How to setup an apache VirtualHost in Ubuntu

08. November 2010 SysAdmin 0

Setting up example.com virtual host in local system

#########################################################
Requirements:apache2, php, mysql, mysql-server.
Install these softwares using Ubuntu software center.
#########################################################
Put the application in /var/www/example. so that example folder contain index.php.
[email protected]:~$ sudo gedit /etc/apache2/conf.d/example.conf
It will open a file in gedit, copy the below lines to the file.

ServerAdmin [email protected]
DocumentRoot /var/www/example
ServerName example.com
ErrorLog /var/log/apache2/error_example.log

Options FollowSymlinks
AllowOverride All
RewriteEngine on

—– save — and close the editor—–
now run
[email protected]:~$ sudo gedit /etc/hosts
It will open a file in gedit, give the following entries in last line
127.0.0.1 example.com
—– save — and close the editor—–
now run
[email protected]:~$ sudo /etc/init.d/apache2 restart
If the Apache restarts succesfully, you can view your site, with the following address http://example.com
If the Application requires New mysql database, then follow these steps.
##### for existing database ####
asuming that your database dump is at /home/username/yourdb.sql
[email protected]:~$ cd /home/username
[email protected]:~$ sudo mysql
mysql> . yourdb.sql
@@@@ it will import your db from the dbdump file @@@
mysql> grant all on yourdb.* to [email protected]’localhost’ identified by ‘yourdbpasswd’;
mysql> flush privileges;
mysql> quit
###############################
###### for new databases #########
[email protected]:~$ sudo mysql
mysql> create database exampledb;
mysql> grant all on exampledb.* to [email protected]’localhost’ identified by ‘examplepasswd’;
mysql> flush privileges;
mysql> quit
#############################
now load the application in browser. http://example.com

Leave a Reply

Your email address will not be published.