Add Web Site To Local Dev Server

There is 2 parts to setup a web site in local dev server

1. Add Web Site to Apache
2. Add Web Site to /etc/hosts file.


Add Web Site To Apache

When we develop a web site, we need to add it to local web server. We also want to see the live web site also.

For example, we are developing web site

Code:
http://ImageHostNow.com
We add a web site

Code:
http://ImageHostNow.dev
To local Apache web server. So we can access developement version of the site and live site same time

To Add web site ImageHostNow.dev to local Apache web server, edit

Code:
subl ~/conf/vhosts.conf
Add following to end of the file and save and quit editor.


Code:
<VirtualHost 127.0.0.1:80>
    ServerName imagehostnow.dev
    SetEnv APP_ENV "dev"
    DocumentRoot /home/YOUR_USER_NAME_HERE/www/imagehostnow.com/public
    CustomLog ${APACHE_LOG_DIR}/imagehostnow.dev.log combined
    <Directory "/home/YOUR_USER_NAME_HERE/www/imagehostnow.com/public">
        Options All
        AllowOverride All
        Require all granted
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>
In the above, VirtualHost entry, you need to change YOUR_USER_NAME_HERE with your actual username.

Now you will need to create the folder for your web site

Code:
mkdir ~/www/imagehostnow.com
mkdir ~/www/imagehostnow.com/public
Now restart Web Server

Code:
sudo service apache2 restart
Now Apache is ready to serve your web site. If you go to

Code:
http://ImageHostNow.dev
You get web site not found error. This is because, when you go to a web site, first web site IP address is found using DNS server. In out case, ImageHostNow.dev, there is no such real site, so public DNS servers don't know about this site. So we have to point the web site to local Apache IP address (127.0.0.1)

Setting Local DNS

Edit /etc/hosts file.

Code:
subl /etc/hosts
Now add following

Code:
127.0.0.1 imagehostnow.dev
Save and exit editor. Now you will be able to see web site

Code:
http://ImageHostNow.dev
Since our document root directory

Code:
/home/YOUR_USER_NAME_HERE/www/imagehostnow.com/public
Is empty, no web page will be displayed. So go to that folder, create a file index.php (or index.html). Now the site will display the content.