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 </Directory> </VirtualHost>
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/hostsadd the following lines:
127.0.0.1 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’
8 responses to “Install LAMP on Ubuntu”