Setup Apache Virtual Host on Ubuntu Server

In this post I will show you through setting up website using virtual hosts on Ubuntu server.

Before we begin, you need to have Apache installed in order to work through these steps.

1. sudo apt-get update
2. sudo mkdir -p /var/www/coolexample.local/public_html
3. sudo chown -R orange:orange /var/www/coolexample.local/public_html
4. sudo chmod -R 755 /var/www/coolexample.local/public_html
5. sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/coolexample.local.conf
6. sudo vim /etc/apache2/sites-available/coolexample.local.conf
DocumentRoot /var/www/coolexample.local/public_html
ServerName www.coolexample.local
ServerAlias coolexample.local
:wq
7. sudo a2ensite coolexample.local.conf
8. sudo service apache2 restart
9. sudo vim /etc/hosts
127.0.0.1 coolexample.local
:wq

Note: For index.php url issue add below lines in /etc/apache2/sites-available/coolexample.local.conf just after DocumentRoot
<Directory /var/www/>
AllowOverride All
</Directory>

Leave a Reply