Saturday, September 22, 2012

Adding VHost to apache2 (Ubuntu 12.04)

Following steps is not include installation of apache2.

1. Create vhost dir.
sudo mkdir /etc/var/www/example.com/public_html


2. I use for development, so I map the localhost IP to example.com, if you using internet IP, go to next step.

sudo nano /etc/hosts

#add line
127.0.0.1 example.com


3. Grant permissions to 'www/example.com/public_html'

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

sudo chmod 755 -R /var/www/example.com


4. Creating Vhost file.

cd /etc/apache2/sites-available
cat default > example.com
nano example.com


#add line after ' ServerAdmin webmaster@localhost'
ServerName    example.com
DocumentRoot   /var/www/example.com/public_html

#correct the <Directory> tag with correct attribute.
 <Directory /var/www/example.com/public_html/>


5. Enable the site.

a2ensite example.com
services apache reload


6. Test the site by browser the example.com.