Last active
August 29, 2015 14:01
-
-
Save gobinathm/1515fc2352494e15dc44 to your computer and use it in GitHub Desktop.
Step By Step Guide to Configure Virtual Host on an Apache in a Ubuntu Machine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Initial Step is to install / Step Apache | |
sudo apt-get install apache2 | |
#below steps are done assuming that your website will be hosted under /var/www | |
#Create a directory that will act as a document root for your site | |
sudo mkdir -p /var/www/example.dev/public_html | |
#Create a directory that will used for Log Storage | |
sudo mkdir -p /var/www/example.dev/log | |
# Document Root & LOG directory should be writable to USERS, not Just for ROOT | |
sudo chown -R $USER:$USER /var/www/example.dev/public_html | |
sudo chown -R $USER:$USER /var/www/example.dev/log | |
# Ensure all user have read access to WWW directory | |
sudo chmod -R 755 /var/www | |
# Create Virtual Host by copying an existing file [Note: Some version of Ubuntu might not have .conf extension. | |
sudo cp /etc/apache2/sites-available/default-000.conf /etc/apache2/sites-available/example.dev.conf | |
# Before enabling newly created virtual host. we need to make few config changes. Use your favorite Text editor, here i'm using vi | |
# 1. Document Root to be update to the one we created above | |
# 2. Change ServerName & ServerAlias to the One you have created above | |
# 3. Change the ServerAdmin Email ID | |
# 4. Change Log path to the one created above | |
sudo vi /etc/apache2/sites-available/example.dev.conf | |
# Final conf file for this example would look like the one in comments | |
# Time to enable new virtual host | |
sudo a2ensite example.dev | |
# As we are using a full qualified domain name "example.dev" its good to make appropriate entry in hosts file. Sample given comment | |
sudo vi /etc/hosts | |
# Reload / Restart your apache (I have given both option, its fine to use any one) | |
sudo service apache2 restart | |
sudo service apache2 reload |
hosts file sample
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
#Virtual Hosts - using local IP address assuming that there is no Public Static IP assigned to the server
127.0.0.1 example.dev
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
example.dev.conf