Ubuntu virtual hosts

How to setup virtual hosts on Ubuntu 14.04

After install and setup LAMP you need do this simple steps:

1. Let’s create new folder for project.

sudo mkdir -p /var/www/example.com/public_html

2. Change owner.

sudo chown -R $USER:$USER /var/www/example.com/public_html

3. Change mod.

sudo chmod -R 755 /var/www

4. Copy apache config for new site.

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.com.conf

5. Edit new site config.

sudo nano /etc/apache2/sites-available/example.com.conf

6. Must be somth like this:

ServerAdmin lehaqs@gmail.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

7. Create vhost for new site.

sudo a2ensite example.com.conf

8. Restart local server.

sudo service apache2 restart

9. Add new site to hosts.

sudo nano /etc/hosts

10. Must be somth like this: example.com

That’s all :)

Published by Aleksey Motovilov

Just do it!