Apache2 - Configure multiple websites (virtual hosts)

1. Login to your Ubuntu Server, navigate to and list »sites-available« directory

cd /etc/apache2/sites-available 

2. You should see the files:


3. Disable the default site configuration

sudo a2dissite 000-default.conf 

4. Create a copy of the default configuration file and open it for edit

sudo cp 000-default.conf yourdomain-com.conf 
sudo nano yourdomain-com.conf 

5. Enter the configuration (you can delete the comments) in this manner

<VirtualHost *:80>
ServerName yourdomain.com
ServerAdmin info@yourdomain.com

DocumentRoot /var/www/yourdomain.com

ErrorLog ${APACHE_LOG_DIR}/yourdomain.com-error.log
CustomLog ${APACHE_LOG_DIR}/yourdomain.com-access.log combined

6. Save and exit the file edit mode

7. Enable the yourdomain.com site configuration

sudo a2ensite yourdomain-com.conf 

8. Be sure to create appropriate directory and set permissions

cd /var/www/
sudo mkdir yourdomain.com
sudo chown username:username yourdomain.com -R

(use your own Ubuntu Server username)

9. Reload Apache2 server

sudo service apache2 reload

Apache2 enable / disable sites & modules

Enable site (virtual host)

sudo a2ensite [filename.conf]

Disable site

sudo a2dissite [filename.conf]

Enable an apache2 module

sudo a2enmod [module_name]

Disable an apache2 module

sudo a2dismod [module_name]

Force reload the server

sudo /etc/init.d/apache2 force-reload


sudo service apache2 reload