Adding a "virtualhost" domain to Apache

Expertise level: Easy

To add a VirtualHost entry, follow this procedure:

  • Login to your server as root in an ssh session.
  • Make a copy of the current httpd.conf file (the path of the file may be different).
cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak
  • Open the file /etc/httpd/conf/httpd.conf using your favourite text editor.
  • Navigate to the end of the file and add the VirtualHost entry in the following format:
DocumentRoot /home/user/public_html
ScriptAlias /cgi-bin /home/user/public_html/cgi-bin
<IfModule mod_suphp.c>
suPHP_UserGroup user user

Make sure you have entered the correct IP address using one of your server's IPs.

DocumentRoot directory is the web files directory.

  • Save the file and exit.
  • Restart Apache using this command:
/etc/init.d/httpd restart

Verify if the document root directory "/home/user/public_html" is accessible through the browser when accessing (The domain must resolve on the IP address you have entered into the VirtualHost).


Article is closed for comments.
Powered by Zendesk