LAMP Virtual Hosts

In the last post I tell you how you can install LAMP in Ubuntu 11.10. Now I tell you how to configure virtual hosts, in this way you can create a lot of independent sites (also in different domains).

Decide where you want to store the folder that will contain the sities files. In my case, I have a very large ‘/home’ partition, I decided to put this folder in the path: ‘/home/www’.

Create the folders and set premissions:

sudo mkdir /home/www /home/www/log
sudo chmod ugo+rw /home/www /home/www/log

Now, create a new available virtual host:

sudo gedit /etc/apache2/sites-available/example

Edit this file by pasting the following code:

<VirtualHost *:80>
	ServerName example.localhost
	ServerAlias www.example.localhost
	DocumentRoot /home/www/example
	ErrorLog /home/www/log/error.log
	CustomLog /home/www/log/access.log combined

	<Directory /home/www/example>
		Options Indexes FollowSymLinks MultiViews
		AllowOverride All
		Order allow,deny
		allow from all

Save the file and type the following commands:

mkdir /home/www/example
echo "<?php echo("index page"); ?>" > /home/www/example/index.php
sudo a2ensite example
sudo service apache2 reload

Now, you can configure your DNS to resolve the URL ‘http://example.localhost’, but is simpler to configure the ‘/etc/hosts’ in this way:

sudo gedit /etc/hosts
add the following lines: example.localhost

save the file and try to open de URL: ‘http://example.localhost’
You can see the site errors and warnings opening the file: ‘/home/www/log/error.log’

10 responses to “LAMP Virtual Hosts

  1. Benete

    wanted to thank you for this great read!! i am definitely enjoying every little bit of it i have you bookmarked to check out new stuff you post.

    1. Vidya

      Pretty great post. I simply stmubled upon your blog and wanted to say that I’ve really enjoyed surfing around your blog posts. In any case I will be subscribing for your rss feed and I am hoping you write again soon!

  2. OPEN VZ

    Thank you very much for that great article

    1. Thiwie

      Wonderful paintings! That is the type of ioinrmatfon that should be shared around the net. Disgrace on Google for now not positioning this publish upper! Come on over and talk over with my site . Thank you =)

  3. женские сумки

    Very enjoyed this! Well done!

  4. Darcivana

    nice post, thanks.

    1. Abdulrahman

      You really make it apaper really easy with your presentation however I in finding this topic to be actually one thing that I feel I would by no means understand. It kind of feels too complicated and extremely vast for me. I am looking forward to your subsequent publish, I will try to get the dangle of it!

  5. Claire

    thanks for the post, it helped me a lot.

    1. Kirsten

      Hi there, I am using Ubuntu 11.04. And it simply will not decett my Tata Photon + device no matter what I do. I have tried your suggestion, in addition to several others that are posted online, but nothing helps. Any ideas on how to fix this? Thank you,Ben

  6. Shaboo

    Thanks for some other fantastic arictle. The place else could anyone get that type of information in such a perfect manner of writing? I have a presentation subsequent week, and I am on the search for such information.

Comments are closed.