Author: Ricky Bryce (Montgomery County, Illinois)
| Click here to learn why Christ came to this Earth for us! | Get 10% off VPSLink! Enter REFERRAL code MJDCDJ |
Apache (WebServer)
By default, Apache should work as-is. In fact, if you open your web browser right now, and type your domain name into the address bar, you should get a test page. Let's try this to make sure the Apache server is up and running. Since the CentOS package was already set up in a LAMP configuration, you should not have any trouble bringing up the test page. If you were to create an index page in the /var/www/html directory, your page would display instead of the test page.
We are wanting the ability, however for our server to host multiple web pages with multiple users, so we are going to have to configure virtual hosting in the Apache configuration file. Other features such as directory protection can be configured as well, but this lesson is just going to show how to get the server running for multiple websites.
How many different web pages can Apache host? This depends on how large the page is, and the amount of dynamic content. A VPS with 10 Gigs of drive space and 128Megs of RAM (with 256M Swap) using the XEN hypervisor would probably be sufficient to host 25 personal web pages or more depending on how much traffic those pages get, how much drive space they use, and how much dynamic content they have.
Let's configure the server!
First let's log in to your server using a standard username.
Now, let's type su to become the root user. (press enter after each command)
Next, we need to enter the Apache configuration file. To do this, type cd /etc/httpd/conf then type vi httpd.conf (CD changes to the proper directory, and vi is your text editor, so you are editing the httpd.conf file.)

Hold CTRL + F until you reach the bottom (end) of the file. (Control and F at the same time)
Using your arrow keys, move your cursor up until you reach a line stating “#NameVirtualHost *:80” (This is about 20 lines above the bottom of the file)

Tap “i” for insert mode, then press the del key on your keyboard to delete the # sign. The # sign makes a line of code inactive, so by deleting the # sign, we are activating the VirtualHost feature of Apache.
Now press the esc key on your keyboard to go back into command mode, and cursor down about 13 lines to #<VirtualHost *:80>
Count the number of lines from #<VirtualHost *:80> to #</VirtualHost> There should be around 7. This is the number of lines we are going to yank and paste in the next few steps.
Be sure you pressed esc in in the above step, so you are in command mode, then type 7yy This will yank 7 lines of code. If you counted a different number of lines from #<VirtualHost *:80> to #</VirtualHost>, then use that number instead of 7.
Now we are going to past our code we yanked at the bottom of the file. Cursor down (with your arrow keys) to the bottom of the file.
Tap “i” for insert mode.
Cursor to the right as far as you can go, then press enter a couple times.
Press esc to get back to command mode
Now hit “p” to paste the lines that you yanked earlier. Yanking the 7 lines and pasting them, we just duplicated the original 7 lines. This way, we will always still have the original 7 lines of code (which are currently inactive) while we modify a copy of those 7 lines.
Now you are starting to get familiar with the vi editor. Just hit “i” to insert text, and esc will return you to command mode where you can save your work, yank and paste, and many other commands that are available in vi. We are going to modify our copy of the code we just pasted. Using the example below, try to modify these 7 lines as shown, adjusting them for your own needs. Notice I am adding an extra line called ServerAlias. You may want to do the same as well.

Now, we need to save our work. To do this press esc on your keyboard, then :wq (colon followed by w, for write and q, for quit.
Note: If you are going to point other domain names to this server to host web pages, you would want to add the new user to your Linux system using the adduser and passwd commands as shown earlier in this document. Then you would simply yank these 8 lines, and adjust them to reflect the domain name, and directory location for the new user. The first virtual host is the default, so if a person enters the IP address of your server into the address bar of the web browser, the first virtual host should be the one displayed. Apache uses host headers to determine what directory to serve. This means it goes by the host name entered into the address bar of the web browser.
Now we need to create a directory for the user to store their page in. As you can see from the configuration file in this example, the location of the web page for brycefamily.com needs to be in /home/ricky/public_html. The reason each user needs their own public_html directory is because we are later going to configure the FTP server for that user, and each user will only have access to their own directory. We will create the folder, and web page in the next few steps.
We already added some users in a previous lesson, so let's make sure each user we added has their own folder in the /home/directory. Type cd /home to change to the home directory.
Now type ls (list)

Looks like we are good to go here. When the user “ricky” was added, a folder was automatically created in the home directory. We do need to make the folder “ricky” available for apache to access. To do this, type chmod 711 ricky (substitute the username you are using instead of “ricky”) To fully understand the chmod command, you can do a simple google search, but we are simply entering a binary code for 3 different types of users, and giving them read, write or execute permissions. For example, the first number is 7 which is 111 in binary, so you are giving the user himself read, write, and execute permissions. The second number is the group permissions 1, which is 001 in binary, so everyone in the group the user is in only has execute permissions. The last number again is 001, so others will only have execute permissions.
Now we need to go into his home directory, and add the public_html folder that apache is looking for. Type cd ricky to enter the user's directory. (again use your own username instead of “ricky”.
Now type mkdir public_html to make the directory the user will store his web page in.
Type ls -al (optional step) Notice the folder public_html is owned by root, and is set up for the root group. That's because we created the folder as root. We need to set this folder up so ricky owns this folder, and it's in ricky's group.

Type chown ricky public_html
Type chgrp ricky public_html
Now, type ls -al You will see that “ricky” or your own user and group now owns the folder.

It looks like the permissions might be OK, but you can type chmod 755 public_html to be sure.
Now let's become the user “ricky” so we don't have that problem. This way any file we create will be owned by “ricky”.
Type su ricky You will notice the # sign on your cursor became a $ indicating that you are no longer the privileged user.
![]()
Let's enter the public_html directory. Type cd public_html
Now we are ready to create the first web page, and save it.... By default, apache looks for a file named index.html, or index.php to serve. We'll just create a simple index.html file. The vi editor can do this for us. Just type vi index.html
Tap “i” for insert mode, and create your page as shown:

Hit esc on your keyboard, then type :wq to write the file and quit.
Now type exit to get back to the root user.
Because we changed the httpd.conf file, we need to restart apache.
Type /etc/init.d/httpd restart
Note: In this example, the host file was not set up properly, so apache displayed a warning that the domain name could not be determined reliably. If your host file is set up properly, apache should start and stop with out this warning. We configured the host file in the section “Setting the Host Name”.

I made a change to the host file, and now it is properly configured. This time, when I restart apache, I do not receive the warning.

Open your web browser, and try to load your page by typing your domain name in the address bar.

Congratulations! Your web server is running!