Tuesday, August 20, 2013

Tagged under: , , , ,

How to create Apache virtual hosts in Ubuntu

Virtual host system help you to develop and manage your local websites easily by mapping them to friendly names like mybusiness.dev or myclient.com instead of localhost/mybusiness or localhost/myclient. With these names, your websites will run like real websites on the Internet, but remember, these names only work locally on your computer. Here's how to do it.

Go to the Apache folder named /etc/apache2/sites-available
You'll see a file named default, create a copy of it and name the copy with your website name (Ex: company.dev).

Open this file and change all existing domain names and paths here to the domain name you've just choose and the path to the folder contain your website.

Finally, you have to active this virtual host by running this command in terminal:
sudo a2ensite company.dev

Add this line to the file /etc/hosts to map the name to localhost, not to the Internet:
127.0.0.1 example.dev

Restart Apache and test
service apache2 restart

Notice that in some browser like Chrome, may be you have to type "http://compnay.dev", not just "company.dev". Chrome can misunderstand and think it an address on the Internet.

0 comments:

Post a Comment