Apache Virtualhost on Ubuntu

Running multiple websites on a single server can be done with Apache Virtualhosting.

1. Change the directory to sites-available

cd /etc/apache2/sites-available/

2. Create a new file called example.conf

vi example.conf

3. Copy and paste this entire code in example.conf

<VirtualHost *:80>
ServerAdmin webmaster@example.com
ServerName  www.example.com
ServerAlias example.com

DocumentRoot /var/www/example.com/htdocs/

# CGI Directory
ScriptAlias /cgi-bin/ /var/www/example.com/cgi-bin/
<Location /cgi-bin>
Options +ExecCGI

# Logfiles
ErrorLog  /var/www/example.com/logs/error.log
CustomLog /var/www/example.com/logs/access.log combined

4. Enable the virtualhost

a2ensite example

5. Restart apache, all done

NOTE : All the directories need to be created manually, apache wont create any directories.

Leave a Reply

Your email address will not be published. Required fields are marked *