Archive for the ‘Cpanel and WHM’ Category

How a Web Server Works

Friday, September 22nd, 2006

You have probably come to this site to find a company that provides Web servers or Web hosting services. But do you actually know how these hosting machines work? It’s a good idea to know a little bit about the product or service you are searching for before you begin your quest.

First, it’s important to note that this is a two-sided story. Web servers are responsible for storing and exchanging information with other machines. Because of this, at least two participants are required for each exchange of information: a client, which requests the information, and a server, which stores it. Each side also requires a piece of software to negotiate the exchange of data; in the case of the client, a browser like Netscape or Internet Explorer is used.

On the server side, however, things are not as simple. There is a myriad of software options available, but they all have a similar task: to negotiate data transfers between clients and servers via HyperText Transfer Protocol, the communications protocol of the Web. What type of server software you are able to run depends on the Operating System chosen for the server. For example, Microsoft Internet Information Server is a popular choice for Windows NT, while many Unix fans choose Apache Web server.

A simple exchange between the client machine and Web server goes like this:

1. The client’s browser dissects the URL in to a number of separate parts, including address, path name and protocol.

2. A Domain Name Server (DNS) translates the domain name the user has entered in to its IP address, a numeric combination that represents the site’s true address on the Internet (a domain name is merely a “front” to make site addresses easier to remember).

3. The browser now determines which protocol (the language client machines use to communicate with servers) should be used. Examples of protocols include FTP, or File Transfer Protocol, and HTTP, HyperText Transfer Protocol.

4. The server sends a GET request to the Web server to retrieve the address it has been given. For example, when a user types http://www.example.com/1.jpg, the browser sends a GET 1.jpg command to example.com and waits for a response. The server now responds to the browser’s requests. It verifies that the given address exists, finds the necessary files, runs the appropriate scripts, exchanges cookies if necessary, and returns the results back to the browser. If it cannot locate the file, the server sends an error message to the client.

5. The browser translates the data it has been given in to HTML and displays the results to the user.

This process is repeated until the client browser leaves the site.

Aside from its functions listed above, the Web server also has an additional number of responsibilities. Whereas a Web browser simply translates and displays data it is fed, a Web server is responsible for distinguishing between various error and data types. A Web server must, for example, designate the proper code for any sort of internal error and send that back to the browser immediately after it occurs. It also has to distinguish between various elements on a Web page (such as .GIFs, JPEGS and audio files) so that the browser knows which files are saved in which format. Depending on the site’s function, a Web server may also have numerous additional tasks to handle, including logging statistics, handling security and encryption, serving images for other sites (for banners, pictures, etc), generating dynamic content, or managing e-commerce functions.

Now that you’ve had a behind-the-scenes tour of a Web server, you can appreciate all the work that goes in to delivering a single page of content to your computer screen. Use this knowledge to your advantage, and keep it in mind when shopping around for your next host.

Hosting domain with external mail server

Friday, September 22nd, 2006

If a client is trying to send e-mail to a domain that has it’s MX record hosted at a external mail server any mail will get stuck internally and will not be sent out. Here is how to fix that issue:

Use WHM to edit DNS and change the MX entries and then login to your server as root and do the following

pico /etc/localdomains

remove the domain name

pico /etc/remotedomains

E-mail Alert on Root SSH Login

Friday, September 22nd, 2006

Want to be notified instantly when someone logs into your server as root? No problem, check out this nice tutorial on email notification for root logins. Keeping track of who logs into your server and when is very important, especially when you’re dealing with the super user account. We recommend that you use an email address not hosted on the server your sending the alert from.

So lets get started……

How to Move a mysqldatabase

Friday, September 22nd, 2006

Thinking about moving your mysql database? Not sure where to start? It’s easier than you think.

If you have cPanel it’s even easier, if not we will show you how to do it without cPanel, see below. Firstly if you do have cPanel you can move a mysql database by logging into your cPanel account.

Now click on the backup button. You should now see a page contains the backup information.

On the third option down it should have

Download a MySQL Database Backup

Just select the database you want to transfer, by clicking on it, a download should now start with your database, please note this may take awhile to start downloading depending on the size of your database.

Once the download is complete, thats you, you have downloaded your database backup.

Now to go about restoring it all you have to do is login to cPanel, click the backup button. Now in the second menu on the right, click browse, select the .gz backup you downloaded earlier and hit upload. This will automatically restore your database.

Thats really how easy it is, to move a mySQL database with cPanel.

Please note if you have a large database I would recommend you use the steps below.

Dont have cPanel?

Dont panic, it is not as easy as it is with cPanel but it’s fairly easy. There are lots of ways to do this but we are going to use ssh so you will need to have ssh access to the server.

If you have ssh, firstly login to the server.

For this we are doing to use the mysqldump command. I suggest you read the man pages for this command by typing `man mysqldump` in ssh. Now for this all we have to do is type
mysqldump -u [username] -B [database] –password > dump.sql

Obviously replace [username] + [database] with your username and database name. Again this is only if you are moving one database, you are best to read the man pages for all the switches. IE if you want to move ALL databases associated with the user you would type

mysqldump -u [username] -A –password > dump.sql

Once this is done, again this may take awhile depending on the size of your database. You should now have a file called dump.sql in the current directory. You will have to transfer this to the server you would like to restore the database on. This can be done with ftp,wget and so on.

For our example we are going to use ftp, now say the server you want to move it too is 127.0.0.1 we would type ftp 127.0.0.1, you will be prompted for the username, after you input the username, you will be prompted with the password, after you have inputted it you should see a screen where you can execute ftp commands. You should see somthing similar to this when logging in.

# ftp 127.0.0.1
Name (127.0.0.1:[currentusername]): example
331 User example OK. Password required
Password:
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>

Obviously this will be different from ftp server to ftp server, but the general layout and functionality should be roughly the same.

Now that you have logged into ftp, you should put the dump.sql file on the remote server by typing

put dump.sql

this may take awhile again depending on the size of your database and on the speed of the connection. Please note, if you are using cPanel (and are using this part anyway, for large databases) you may not be able to upload the database if it is 2+ GB, you will have to split it into different parts.

This can be done by using the split command, before continuing please read the man pages on split by typing `man split`

The split command when using the -b switch DOES support using m for MB instead of just using bytes. I would recommend splitting the files into 1GB portions. This can be done by typing

split -b 1024m dump.sql

You should now see different parts, you will have to use the put command with ftp for each one.

Skip the steps above if your database transferred fine. Now that the database is transferred just exit the ftp client by typing quit.

Now it’s time to work on the remote server. First login to the remote server via ssh. There are lots of ways to restore this database. We are going to use mysqldump and by using the myql command, you only need to use one of these.

1) Using mysqldump
This is fairly easy, you just do the exact same as you did to back it up except instead of > dump.sql you use < dump.sql

So you would type
mysqldump -u [username] -B [database] --password > dump.sql

Thats it, it may take time to restore depending on the size of your database.

2) Using the mysql command
Since we have not used this to restore the database, you may not know how to use this but it’s even easier to restore a database with.
Firstly you will have to login to the database, again read the man pages on mysql before continuing by typing `man mysql` in ssh.
You would login by typing
mysql -u [username] -D [database] –password

Once logged in all you type is

source dump.sql

This will now restore your database.

Thats it you have successfully transferred a database.

Random stuff

1) If you receive problems restoring the database, ie mysql errors. This could be because of when you output the database it does NOT quote everything properly. You can fix this issue by adding -Q to the mysqldump command.

2) If you receive memory problems, you can stop mysqldump writing to memory by adding the -q switch to the mysqldump command.

3) If you just want to output the mysql tables, without data all you would do is add the -d switch to the mysqldump command.