If you decided to run more than one website on your Apache web server you would need to configure a VirtualHost based on the name or IP address. Here is some notes on how to achieve it. Here we assume that you have httpd package already installed on your system.

Step 1:

Create a directory to contain your new website:

# mkdir /var/www/example.net
# echo Hello Web > /var/www/example.net/index.html
# chmod -R 755 /var/www/example.net
# chown -R apache.apache /var/www/example.net

Step 2:

Add virtual host configuration to the bottom of /etc/httpd/conf/httpd.conf :

<VirtualHost *:80>
DocumentRoot /var/www/example.net
ServerName www.example.net
# Other Apache config directives, logs etc.

Step 3:

Confirm the VirtualHost sytax before restarting httpd service:

# httpd -S

Step 4:

Restart apache :

# /etc/init.d/httpd restart

Step 5:

If your example domain is already pointing to your server you should be ready to go. Make sure that your domain resolves an IP address of your server. For testing it is also handy to modify /etc/hosts file. For example if this is done just locally add :

# echo www.example.net example.net >> /etc/hosts

Or if your web server’s IP is do to access it from your local client:

# echo www.example.net example.net >> /etc/hosts

For anything else you need Domain name record somewhere.

Step 6:

Navigate to your new VirtualHost website.

FIND LATEST LINUX JOBS on LinuxCareers.com
Submit your RESUME, create a JOB ALERT.
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
Get extra help by visiting our LINUX FORUM or simply use comments below.