Setup a Virtualhost in Debian

June 14th, 2011 by Regaz

This example is made expressly to work on a local environment and
for to work on a Server Host you need to change IP settings consequently…

1) Insert the Hostname you want to Add in /etc/hosts
Ex:

sudo pico /etc/hosts

So to work on a local domain you add on line 127.0.0.1 something like:

127.0.0.1  localhost drupal

2) Next you need to create a Referring file in /etc/apache2/sites-available

sudo touch /etc/apache2/sites-available/drupal
sudo pico /etc/apache2/sites-available/drupal

To set a Name-Based Virtual Host on port 80 you insert in this blank file something like:


ServerName drupal
DirectoryIndex index.html index.htm index.php
DocumentRoot /var/www/drupal
 

Make Virtual Host’s Directory:

sudo mkdir /var/www/drupal

Don’t put at beginning “NameVirtualHost *:80″ if it’s already defined in /etc/apache2/ports.conf because your Virtual Host don’t will work :)
Just to check look output of:

cat /etc/apache2/ports.conf

if contains this statement or not

Then you need also to add a reference for the new Hostname in /etc/apache2/httpd.conf

sudo pico /etc/apache2/httpd.conf

And insert:

ServerName drupal

Latest, to keep your localhost working like before you need to edit:

sudo pico /etc/apache2/sites-enabled/default

And Insert a line with:

ServerName localhost

3) After you need to activate the new configuration

sudo a2ensite drupal

4) Latest Reload Apache

/etc/init.d/apache2 reload

To check it’s effectively working:

su -c "'Welcome to Drupal!' > /var/www/drupal/index.html"

Test opening the address: http://drupal/index.html
You should be Greeted with a href=”Welcome to Drupal!” :)

Good Luck!

(Visited 1 times, 1 visits today)
Share on Tumblr

Tags: ,