Saturday, October 8, 2011

// // Leave a Comment

Speeding up MySQL Queries for faster performance using MySQL Cache

MySQL Queries Can Really Kill Your Web Server. Yes its true that writing buggy SQL queries can result in a lot of server cpu usage. Many webmasters face this problem and they think that their service provider is not good and blah blah.

Best Example is of wapsites using sea 8.1 Script. Tongue

if you are in one of them or your server is getting overloaded because of MySQL then i will suggest you to look at below method of caching can help in reducing the cpu usage of a script.

ok so below is the way on how to use SQL cache.

Suppose your have a query
SELECT name from users where name='xtra';

so query with cache will be like this:
SELECT SQL_CACHE name from users where name='xtra';


This Will stores the result in cache.
Using This Can reduce Your Memory Requirement and load Your Site Faster Smile


Similarly there are a lot of ways to improve and reduce the server load by optimizing the SQL queries.
Read More
// // Leave a Comment

Cpanel Error from park wrapper: Using nameservers with the following IPs

When i tried add a domain into cpanel addon it shows
Error from park wrapper: Using nameservers with the following IPs: , Sorry, the domain is already pointed to an IP address that does not appear to use DNS servers
associated with this server. Please transfer the domain to this servers nameservers or have your administrator add one of its nameservers to /etc/ip.remotedns and make the proper A entries on that remote nameserver.

It's mean, My domain ex: testing.com is not using the cpanel/whm DNS or nameservers.

This can be solved by :
1. change a nameservers in your domain registrar to pointing it to your CPANEL/WHM DNS servers
2. tweak your WHM to support external nameservers.
Login into your WHM with root access.
Server Configuration > Tweak Settings

Within this page you get a lot of options, the one I had to enable (tick) was:

Allow Creation of Parked/Addon Domains that resolve to other servers (i.e. domain transfers) This can be a major security problem. If you must have it enabled, be sure to not allow users to park common internet domains.

Basically it allows cPanel to Add domains on to external nameservers.
After you have added your add on into your CPANEL.
You need to un tick the allow creation of parked/addon domains that resolve to other servers again.
this will prevent any major security problem.
Read More
// // Leave a Comment

Using Screen for Linux Session Management

What is Screen ?
GNU Screen can be thought of as a text version of graphical window managers, or as a way of putting virtual terminals into any login session. It is a wrapper that allows multiple text programs to run at the same time, and provides features that allow the user to use the programs within a single interface productively.

Persistence

    Similar to VNC, GNU Screen allows the user to start applications from one computer, and then reconnect from a different computer and continue using the same application without having to restart it. This makes migration between locations like work and home simple. Screen provides terminal-agnostic functionality so that users can disconnect and reconnect using different terminal types, allowing applications to continue running without being aware of the change in terminals.

Multiple windows
    Multiple terminal sessions can be created, each of which usually runs a single application. The windows are numbered, and the user can use the keyboard to switch between them. Some GUI terminal emulators provide tabs or otherwise similar functionality to this. Each window has its own scroll-back buffer, so that output is captured even when the window isn't actively displayed, and that history can be saved even when migrating to another computer. Windows can be split-screened. While some text applications have this functionality built in, Screen allows any application to be split-screened alongside any number of other applications.

Session Sharing

    Screen allows multiple computers to connect to the same session at once, allowing collaboration between multiple users. The same computer can also be used to make multiple simultaneous connections, providing alternative functionality to screen-splitting, particularly for computers with multiple monitors.
Why we need Screen ?
Here is an example You are logged into your remote server via SSH and happily plucking along at your keyboard and then it happens. Suddenly, the characters stop moving and then you get the dreaded “Connection Closed” message. You have just lost your session. You were halfway through some task and now you have to start over. Ugh. Well you can prevent this from happening by using screen. The Linux screen tool can not only save you from disconnection disasters, but it also can increase your productivity by using multiple windows within one SSH session.
Installing Screen
Most linux are already have screen installed on the system.
if you can find any screen installed on the system. you can install it from yum, apt-get or other repositories
Example installing screen in centos/RHEL
#yum install screen
Example installing screen in BSD / FREEBSD
#cd /usr/ports/sysutils/screen
#make install clean
Screen usually installed in /usr/bin/screen or /usr/local/bin/screen
Using Screen
Simply type screen in your shell prompt like below
#screen
You will see a screen welcome message like below
you can simply press space to continue

How To Using Screen
We need to press CTRL and then press "A" to send a command to screen.
You can reconfigure these keys to your liking using a .screenrc file, but I just use the defaults
Multiple Windows or Multiple Screen Session
#screen
(now we are in screen 0:bash)
Example in screen 0 we will download kernel
#cd /root

(We can open other session with command below)
Press CTRL and A and c
(Now we are in a screen 1 session and then you can see a new SSH prompt again like below)
#
We can exit the screen 1 session, simply type command below :
#exit
And you will back to a screen 0 session above where the wget kernel still running.
We also can detached a session with command below :
(still in a screen 0 session )
Press CTRL and press A and press d
[detached]
#
You will see a detached, which is mean screen 0 session still running in background and we already quit from screen session. but we don't need to worry about ssh lost connection because we can attach to screen again.
How can we attached to a screen 0 ?
First we need to see a screen session list with command below
#screen -ls
There is a screen on:
        26303.pts-3.sitenow     (Detached)
1 Socket in /var/run/screen/S-root.
Now we  can see a screen 26303.pts-3.sitenow (Detached)
we will attach this 26303.pts-3.sitenow  screen session
#screen -r 26303.pts-3.sitenow
(now we are in screen 0 session again )
How about if i have few screen session and i want to back to previous screen without exit the current screen ?
in screen we can press CTRL and A and p for back to previous session screen or
in screen we can press CTRL and A and n for next session screen
For complete reference.
Please take a look screen User's Manual http://www.gnu.org/software/screen/manual/screen.html
Read More
// // Leave a Comment

How To Using Wget to Download All Files and Directory

This is a short tutorial to download all files and directory.
Example :
i have a files and directory in remote server and want to transfer all files and directory to local client.
here is a simple command to download it using wget instead of ftp.
#wget -r ftp://username:password@domain.com/
From the command above it will download everything in / directory of domain.com into your computer / local client.
Read More
// // Leave a Comment

OpenVZ web interface with WebVZ

What is WebVZ ?

WebVZ is a light web based control panel (~ 300KB) for OpenVZ. It is a free and open source under GPL GNU licence. WebVZ has its own webserver and databases engine which means there is almost no configurations needed.

WebVZ lets you manage the containers from the web browser which makes the life of the system administartors much easier than using the command line tools.

WebVZ Features

1. Create containers.
2. Start, Stop, Restart, and Destroy containers.
3. Migrate containers from Host Node to another Host Node.
4. Create and Manage configuration files.
5. Change the configuration of the containers on the fly.
6. Start, Stop, and Restart OpenVZ service.
7. Execute Commands inside the running containers and display the output on the same page.
8. list the stopped containers, the running containers and/or all of them.
9. Assign a name for each container.
10. User Accesss Module.
11. Add/delete multiple IP Addresses
12. Monitor container's resources (user_beancounter) and highlight the over used resource.
13. Assign root password.
13. Enable/Disable booting of the container.
14. Manage Operating System Templates (delete, download and copy).
15. Recreate a customized OS-Template from an existing container.
16. Copy OS-Template from a machine to another.
17. Backup all containers .
18. Backup all client's containers .
19. Backup a specific container .
20. restore containers .
21. Access Control Level .
22. Client can stop, start and restart his/her container.
23. Client can run commands, observe, and monitor the containers .
24. Ownership of containers .
25. admin and client users .
26. Security enforcement on who access what.
27. and many more.

WebVZ Requirements before installation

WebVZ needs Ruby on Rails & sqlite3-ruby to be installed on the server.

Installing Sqlite3-Ruby

I can't install sqlite3-ruby with gem install sqlite3-ruby
so i just install it from yum repository

#yum install ruby-devel sqlite sqlite-devel ruby-rdoc

Installing WebVZ

#cd /root
#wget http://download.github.com/shuaibzahda-webvz-c6586ca.tar.gz
#tar -zxvf shuaibzahda-webvz-c6586ca.tar.gz
#ruby /root/webvz/script/server -d

Added Ruby WebVZ webserver to rc.local

#vi /etc/rc.local

#### add this line below ####
ruby /root/webvz/script/server -d

Open WebVZ from Web Browser

Click Internet Explorere or Mozilla Firefox
Input your server ip address example http://10.10.10.10
Input username : admin
Input password : admin123

After you install and login to WebVZ. It is advised to create a new user and delete the admin user.
Read More

Tuesday, October 4, 2011

// // Leave a Comment

Captcha image verification

A good way to avoid automatic form submissions when creating a web form is to add some kind of verification. One of the best ways is to use an image verification, called also captcha. What it does is to dynamically create an image with a random string displayed on it. Then visitor is asked to type that string in a text field and once the form is submitted it checks if the string on the image matches the one inputted by the user. Because there is no easy way to read a text from an image (image recognition) this is a good way to protect your web forms from spammers.
For doing this CAPTCHA I would suggest using a session variable where you store the string generated and displayed on that dynamically generated image.
<?php 
session_start(); 
$text = rand(10000,99999); 
$_SESSION["vercode"] = $text; 
$height = 25; 
$width = 65; 
 
$image_p = imagecreate($width, $height); 
$black = imagecolorallocate($image_p, 0, 0, 0); 
$white = imagecolorallocate($image_p, 255, 255, 255); 
$font_size = 14; 
 
imagestring($image_p, $font_size, 5, 5, $text, $white); 
imagejpeg($image_p, null, 80); 
?>
Save this code in a file called captcha.php. What this script does is to generate a random number from 10000 to 99999 and then assign it to $_SESSION['vercode']. Then it generates a 25x65 pixels image with black background and white text using size 14. So if you upload that captcha.php file on your web site and open http://www.site.com/captcha.php you will see an image displaying random integer. You will receive a new random integer every time you refresh that page.
Next we need to create our web form.
<form action="submit.php" method="post"> 
Comment: <textarea name="coment">textarea><br> 
Enter Code <img src="captcha.php"><input type="text" name="vercode" /><br> 
<input type="submit" name="Submit" value="Submit" /> 
form>
Above code will create a form with a single textarea box, randomly generated image using the captcha.php script and a text field where you will have to enter the verification code.
All we have to do now is to make the submit.php script which will check if the verification code you enter matches the one that has been randomly generated.

<?php 
session_start(); 
if ($_POST["vercode"] != $_SESSION["vercode"] OR $_SESSION["vercode"]=='')  { 
     echo  'Incorrect verification code.
'; 
} else { 
     // add form data processing code here 
     echo  'Verification successful.
'; 
}; 
?>
Read More

Sunday, October 2, 2011

// // Leave a Comment

Pascal PHP Class

Name: Pascal
Base name: pascal
Description: Generate the triangle of Pascal with given rows
Version: 1.0
Required PHP version: 3.0
License: Freeware


Read More