How to add a Apache VirtualHost on Ubuntu
With this tutorial I assume that you know what Apache web server is and that you have PHP and Apache installed on your machine. Also ensure that you are able to serve web pages.
NOTE: This has been tested on Ubuntu 9.04
- Open your Terminal Window or the command line.
- Navigate to the /etc/apache2/sites-available directory with this command:
- Create a new file in this directory called sitename.conf or anything you would like to call your new VirtualHost.
Use the following command: sudo gedit sitename.conf
- Add the following code in the sitename.conf file
ServerAdmin yourn[email protected]
allow from all
- Save file and exit.
- Open the /etc/hosts file with command: sudo gedit /etc/hosts
- Add the following code to it
127.0.0.1 localhost sitename
- Save file and exit
- Enable your new VirtualHost
Use this command: sudo a2ensite sitename.conf
- Creates a symbolic link to /etc/apache2/sites-enabled
- In the /etc/apache2/apache2.conf file it includes the /etc/apache2/sites-enabled directory to include the virtual host configurations, so all VirtualHosts will be included everytime Apache starts.
- Restart Apache with command: sudo /etc/init.d/apache2 restart or sudo service apache2 restart
- Now your new VirtualHost should be enabled!