Create a vhost in Ubuntu GNU/Linux

Are you reading the Zend Framework quickstart tutorial and you are blocked at “Create a virtual host“?

It’s really simple, here I explain how to do it in Ubuntu GNU/Linux (versione 10.04 LTS).


First you have to choose the hostname for you virtual host. It’s the first part of the URL you use to access the vhost. For example you can choose myapp.mycomputer. You have to add this row to /etc/hosts :       myapp.mycomputer

In this way you say “myapp.mycomputer domain is mapped to, the local host”.

Add a virtual host

Now you create the vhost directory where files for your application goes

$ sudo mkdir /var/www/myapp

And now create the file where you define the vhost (The one with … in the tutorial), create the file /etc/apache2/sites-available/myapp.mycomputer with this content :

<VirtualHost *:80>
    ServerName myapp.mycomputer
    DocumentRoot /var/www/myapp
    SetEnv APPLICATION_ENV "development"

    <Directory /var/www/myapp>
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all

In particular note the lines with ServerName, DocumentRoot and <Directory …> (In case of a Zend Framework application DocumentRoot and <Directory …> should point to the public directory of it).

Enable the vhost and enjoy it!

Now you have to do the last few little things:

Enable the vhost

$ sudo ln -s /etc/apache2/sites-available/myapp.mycomputer /etc/apache2/sites-enabled/myapp.mycomputer

UPDATE (2010/09/04) : The right way to enable it is use the e2ensite command that will create that link for you:

$ sudo a2ensite myapp.mycomputer

Restart Apache

$ sudo /etc/init.d/apache2 restart

Enjoy it!

Open your favourite browser and go to http://myapp.mycomputer/


This knowledge comes from the OSys R&D department :P.

{lang: 'it'}

Puoi seguire le risposte a questo articolo tramite il feed RSS 2.0.
Puoi anche lasciare un commento, o creare un trackback dal tuo sito.

2 Risposte a “Create a vhost in Ubuntu GNU/Linux”

Lascia un commento

XHTML: Puoi usare questi tag: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>