Setup Virtual Hosts using Apache2 on Ubuntu 12.04
When I started programming website on a localhost, I often ran into issues setting up SEF URLs. So, I started using virtual hosts by creating fake domain names and then make them connect to the local apache server via the hosts file.
For example, if I work on webdesignblog.asia on my localhost, I am accessing webdesignblog.dev, which is a fake domain linked to my localhost via the virtual hosts (enabled sites) and hosts modifications.
Here are the steps needed to setup your own virtual host:
Create a configuration file for the virtual host / domain:
# sudo nano /etc/apache2/sites-available/webdesignblog.dev
Modify the text block below and then paste it in the file
# It will make any customisation easier to understand in the weeks to come
# domain: webdesignblog.dev
# public: /home/wdb/public_html/
<VirtualHost *:80>
# Admin email, Server Name (domain name) and any aliases
ServerAdmin [email protected]
ServerName webdesignblog.dev
ServerAlias www.webdesignblog.dev
# Index file and Document Root (where the public files are located)
DirectoryIndex index.html
DocumentRoot /home/wdb/public_html/
# Custom log file locations
LogLevel warn
ErrorLog /home/demo/public_html/domain1.com/log/error.log
CustomLog /home/demo/public_html/domain1.com/log/access.log combined
</VirtualHost>
# sudo a2ensite webdesignblog.dev
# sudo service apache2 reload
3213
A nice and clear guide. Helped me get mine working. Thanks for posting this!