Posted in Main category

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:

127.0.1.1 example.com

That’s all 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s