Dec 17 2007

How to set up a virtual host on Apache2 in Ubuntu Gutsy Gibbon (7.10)

Welcome back!

Earlier, I showed you “How to install a lamp stack on Ubuntu Gutsy Gibbon (7.10).” This will get you started with the default website. However, for day to day development work, I find it easier to work on sites (Wordpress, Ruby, etc.) in my Home directory so I don’t have to sudo every time I edit a file.

For this you will need to set up a virtual host in Apache2. Think of it as a separate web site that runs in your Home directory. I followed the write-up at the Community Ubuntu Documentation. In order to set this up, follow the summary below.

-Create a new directory for your new site like the below by typing the following in the Terminal
mkdir /home/yourusername/public_html/

-Copy the default site to use as a starting template by typing the following command in the Terminal:
sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/yournewsite

-Edit the configuration file by typing the following command in the Terminal:
gksudo gedit /etc/apache2/sites-available/yournewsite

-Look for the following in the configuration file:
DocumentRoot

-Point “DocumentRoot” to a new location by deleting the current location path and entering a new one such as:
/home/yourusername/public_html/

-Look for the following in the configuration file:
<directory /var/www/>

-Replace the above line with:
<directory /home/yourusername/public_html/>

-Save and close the configuration file.

-Deactivate the old site and activate the new site with a2ensite and a2dissite by typing the following in the Terminal:
sudo a2dissite default && sudo a2ensite mysite

-Restart Apache2 by typing the following in the Terminal:
sudo /etc/init.d/apache2 restart

-Test the new site by typing the following into the Terminal:
echo '<b>Searchmarked.com is the coolest site on the web!</b>' > /home/yourusername/public_html/index.html

That’s it! You should be able to display the test site in the browser by navigating to http://localhost or http://127.0.0.1 Happy Web Hosting!

Technorati Tags: , ,

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

TAGS:

LEAVE A COMMENT

Subscribe Form

Subscribe to Blog

Sponsors

Recent Readers

JOIN MY COMMUNITY!
                  Computers Blogs - Blog Top Sites