How to setup an apache VirtualHost in Ubuntu

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.
jobin@JobNix:~$ sudo gedit /etc/apache2/conf.d/example.conf
It will open a file in gedit, copy the below lines to the file.

ServerAdmin username@localhost
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
jobin@JobNix:~$ 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
jobin@JobNix:~$ 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
jobin@JobNix:~$ cd /home/username
jobin@JobNix:~$ sudo mysql
mysql> . yourdb.sql
@@@@ it will import your db from the dbdump file @@@
mysql> grant all on yourdb.* to yourdbusername@’localhost’ identified by ‘yourdbpasswd’;
mysql> flush privileges;
mysql> quit
###############################
###### for new databases #########
jobin@JobNix:~$ sudo mysql
mysql> create database exampledb;
mysql> grant all on exampledb.* to exampleuser@’localhost’ identified by ‘examplepasswd’;
mysql> flush privileges;
mysql> quit
#############################
now load the application in browser. http://example.com
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
Scroll to Top