Press enter to see results or esc to cancel.

Host Multiple Websites On Localhost For Testing Purposes

I run a LAMP (Linux/Apache/Mysql/Php) setup on my local machine where I do all development and testing before updating production websites. This enables a smooth transition of code changes from test version to production grade with minimum interruption to production websites.

In order to achieve this local machine test environment, I have configured local versions of all of my production websites on this local LAMP setup. So, for example, I am able to type in cubiclenomore.local into my web-browser and access a fully functional locally configured website where I do all of my testing. I do the same for my other locally configured websites.

The following text describes how I achieve this multiple-website localhost configuration running Ubuntu and LAMP.

Firstly, I edit my hosts file to make a cubiclenomore.local entry as follows:

sudo gedit /etc/hosts

Once inside the hosts file I add the following line just below the 127.0.0.1 localhost line:

127.0.0.1	cubiclenomore.local

Once my hosts file is configured, I proceed to configure apache2 as follows. I make a copy of the default configuration file inside /etc/apache2/sites-available and name it cubiclenomore.local:

cp default cubiclenomore.local

I then edit this newly created file and change the configuration to look like the following:

sudo gedit cubiclenomore.local
<VirtualHost *:80>
	ServerAdmin webmaster@localhost
	ServerName cubiclenomore.local
	DocumentRoot /var/www/cubiclenomore
	<Directory />
		Options FollowSymLinks
		AllowOverride None
	</Directory>
	<Directory /var/www/cubiclenomore>
		Options Indexes FollowSymLinks MultiViews
		AllowOverride All
		Order allow,deny
		allow from all
	</Directory>
	ErrorLog ${APACHE_LOG_DIR}/error.log
	LogLevel warn
	CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

In the above, please pay attention to the DocumentRoot and ServerName entries which should point to your local folder containing your website files and local site name respectively.

Once your new vhosts file is created, make sure to save it.

After you have saved the new vhosts file, you need to make a symlink to it from the sites-enabled folder. You can do that as follows:

cd /etc/apache2/sites-enabled
ln -s /etc/apache2/sites-available/cubiclenomore.local

And finally, before you are done, you need to restart your apache2 server as follows:

/etc/init.d/apache2 restart

That’s it, your newly configured locally accessible website is ready to go.

Note: you can create as many vhosts as you wish locally by following the above process.

Comments

Leave a Comment