Roshan Book

My Tech Notebook

Configuring Virtual host


When we develop on Zend framework , to check your progress you need to go to http://localhost/phpProj/zend/dev.zendtest.com/public , time and again to get to the index page. We can conveniently set up a virtual host on our local machine, so that if we type dev.zendtest.com we could get to the above mentioned link.

Below are the steps to configure virtual host

Before this, visit /etc/apache2 and see the folders residing there.

Notice two specific folder

a) sites-available

b) sites-enabled

Sites-available is a folder which contains configuration file for each site, which you want to enable

sites-enabled mainly contains link to sites-available. link present inside sites-enabled folder

Suppose we make a new zend framework enabled website in /var/www/zend/dev.zendtest.com , and our objective is to get to its’s public/index.php when we open dev.zendtest.com

Step 1. Create  a new file inside sites-available folder and paste following code :

<VirtualHost *>
ServerAdmin webmaster@localhost
ServerName dev.zendtest.com
DocumentRoot /var/www/zend/dev.zendtest.com/public
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/zend/dev.zendtest.com/public/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
LogLevel warn
CustomLog /var/log/apache2/access.log combined
</VirtualHost>

Step 2. Save the file

Step 3. Open the terminal (ctrl+alt+t) and run “sudo a2ensite dev.zendtest.com
Step 4. Open etc/hosts file ( ensure it’s hosts and not host file)

Step 5. Paste 127.0.0.1 dev.zendtest.com

Step 6. Restart apache by running “sudo /etc/init.d/apache2 start

That’s it, when you now open http://dev.zendtest.com you will get zend welcome page

Notes :

1. In-case you are not able to save site config inside sites-available, try to save the file as root

2. Clear browser chache, if dev.zendtest.com is not giving results

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: