Setting up an Apache Virtual Host on Ubuntu Server Linux

   Hi CloudBalkanians,

   Here are some quick tips on setting up Virtual Hosts under Ubuntu Server.

   On the Ubuntu Server you will find the Apache Virtual Hosts in two folders:

   /etc/apache2/sites-available/

   and

   /etc/apache2/sites-enabled/

    

   The first one all set up virtual hosts configuration files, where the second one contains only the active virtual hosts.

   To setup a new one, create a ‘.conf’ file in the /etc/apache2/sites-available/ folder and open it with a text editor.

   You grab the following short example as a base for you virtual hosts:

   

        ServerName example.com        ServerAdmin admin@example.com        DocumentRoot /var/www/example                        Options Indexes FollowSymLinks                AllowOverride All                Require all granted                # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,        # error, crit, alert, emerg.        #LogLevel info ssl:warn        ErrorLog ${APACHE_LOG_DIR}/example-error.log        CustomLog ${APACHE_LOG_DIR}/example-access.log combined

   It’s pretty minimalistic, but yet quite enough for a lot of web applications.

    

   Here are some short explanations of what you can modify in the example.

   The ‘ServerName’ directive defines the domain to be captured by the VirtualHost.

   The ‘DocumentRoot’ specifies the web root folder for the VirtualHost.

   The ‘Directory’ section sets directory specific settings. In this case it defines a few important settings for the ‘DocumentRoot’ folder.

   The ‘Options Indexes FollowSymLinks’ setting enables directory listing – ‘Indexes’ and the usage of symlinks.

   The ‘AllowOverride All’ defines the settings overrides allowed when using ‘.htaccess’ files.

   The ‘Require all granted’ option just enable unrestricted access to the directory.

    

   Once you’re ready with the file there’s only one more step to get your new virtual host working. You must enable it by creating a symlink in the ‘sites-enabled’ folder.

   You can also use the following commands:

   

sudo a2ensite examplesudo service apache2 reload

   A quick reload of the Apache2 service and you should be ready.

    

   Bring your ideas on solid ground with CloudBalkan.