Setting Up Linux Web Server | Affordable Web Hosting Plans | Cheap Domain Name Registration

How to Set Up Linux Apache Server

Page 19: Set Up Your First Virtual Host (Part 2)

Now, we need to add the Virtual Account Information to the Apache Configuration File (httpd.conf). The httpd.conf file can be found in /etc/http/conf directory and can be opened and edited by any text editor.

The httpd.conf file is a very long file. The file is grouped into three sections:

  • Section 1: Global Enviroment
  • Section 2: Main Server Configuration
  • Section 3: Virtual Hosts

If you are not very familiar with the file at this moment, don't change everything in Section 1 and Section 2. The default setting should be okay. What we need to do is to add a few lines in Section 3.

The following is only a very simple example in order that you can run your first virtual hosting. Please follow:

  1. Open httpd.conf with a text editor.
  2. Find the text " ### Section 3: Virtual Hosts"
  3. There are some examples show you how to add Virtual Host
  4. Find the following two lines:

    # NameVirtualHost
    # NameVirtualHost
  5. We will add the first Virtual Host behind these two lines
  6. Add the following line:
  7. To add the first Virtual Host, add the following lines:
    DocumentRoot /var/www/html/yourdomain/public_html
  8. If you have other Virtual Host (e.g. that need to add later, simply add the following lines after the first Virtual Host:
    DocumentRoot /var/www/html/otherdomain/public_html
  9. You must RESTART your computer or Apache Server for the new records in effect.
  10. Restart your Apache Server
  11. Open a browser in any computer connected with the Internet and browse.
  12. The homepage should be displayed. If not, please check the setting again.

The above is a very simple example, you can add more directive between the <VirtualHost>. You may refer to Apache documentation for more details.

This is the end of this Setting Up Linux Apache Web Server tutorial series.

set up linux web server