Assuming you already have installed LAMP on your Ubuntu machine, here are the steps in creating multiple virtual hosts.
If Apache mod_rewrite module is not yet enabled, you can do so by typing the following command in the terminal:
$ sudo a2enmod rewrite
Following the step below, in your terminal:
$ mkdir /var/www/brymayor.com.local
Add your site to the hosts file:
$ sudo nano /etc/hosts
Edit the file by adding the local domain you want to use, in this case, brymayor.com.local:
127.0.0.1 localhost 127.0.0.1 brymayor.com.local # The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback
Configure Apache
Navigate to /etc/apache2/sites-available/:
$ cd /etc/apache2/sites-available/ $ sudo cp default brymayor.com.local $ sudo nano brymayor.com.local
<VirtualHost *:80> ServerAdmin webmaster@brymayor.com.local ServerAlias brymayor.com.local DocumentRoot /var/www/brymayor.com.local <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/brymayor.com.local/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory>
Please also note this line to allow .htaccess on your local site:
AllowOverride All
Enable the sites in Apache and restart Apache
$ sudo a2ensite brymayor.com.local $ sudo /etc/init.d/apache2 reload
or
$ sudo service apache2 reload
or
$ sudo /etc/init.d/apache2 restart
You can now navigate your browser to http://brymayor.com.local/
If you need to remove any site on your local machine, the easiest way is to reverse through the steps.
1. Disable it using the a2dissite command:
$ sudo a2dissite brymayor.com.local
2. Delete brymayor.com.local file from /etc/apache2/sites-available folder;
3. Remove brymayor.com.local from /etc/hosts;
4. Restart apache:
$ sudo /etc/init.d/apache2 reload
or
sudo /etc/init.d/apache2 restart
or
$ sudo service apache2 reload
Always think twice before hitting the Enter key…
The post How to Create Multiple Virtual Hosts in Ubuntu appeared first on BryMayor.com.