Setup a virtual host on Ubuntu

Aug 24th, 2013

Basic commands to setup a virtual host on Ubuntu 12.04

This is a small howto to setup a virtual host on Ubuntu 12.04 with an upgraded version of php and apache (see my article about PHP and Apache upgrade on Ubuntu 12-04. Default installation path ( /home/www/tuto.dev ) and host name ( tuto.dev ) will be used in all our tutorials.

sudo gedit /etc/hosts

add

127.0.0.1 tuto.dev
sudo touch /etc/apache2/sites-available/page.conf
sudo gedit /etc/apache2/sites-available/page.conf

Note : setup a host for a Symfony application. Files are in /home/www/tuto.dev but web root is in /home/www/tuto.dev/web.

# /etc/apache2/sites-available/page.conf
<VirtualHost *:80>
    ServerName tuto.dev

    DocumentRoot /home/www/tuto.dev/web

    <Directory /home/www/tuto.dev/web>
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        allow from all
        # New directive needed in Apache 2.4.3:
        Require all granted
    </Directory>

    # logs are outside of root
    # this allows to make automatic build
    # and then allow git repo creation

    ErrorLog /home/logs/tuto.dev-error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.

    LogLevel info

    CustomLog /home/logs/tuto.dev-access.log combined
</VirtualHost>

Enable your virtual hosts

sudo a2ensite page.conf
sudo service apache2 reload

You can then got to http://tuto.dev

If you get the following error :

apache2: Could not reliably determine the server s
fully qualified domain name, using 127.0.1.1 for ServerName
 ... waiting apache2: Could not reliably determine
 the server s fully qualified domain name, using
 127.0.1.1 for ServerName

you can do a

sudo gedit /etc/apache2/httpd.conf

and add

ServerName localhost

A new

sudo service apache2 restart

a the error must be gone.


Comments

comments powered by Disqus