VHost Konfiguration on Apache2

create directories (i use /var/www/ as base)

root@dev:/var/www# mkdir sandbox
root@dev:/var/www# chmod 0777 sandbox

you can create a separate cgi-bin and log directory for each vhost, but i prefer one cgi-bin directory and one log directory for all vhosts.

root@dev:/var# mkdir cgi-bin
root@dev:/var# mkdir logs
root@dev:/var# chmod 0777 cgi-bin
root@dev:/var# chmod 0777 logs

for a live server chmod 0777 is not best solution for security, but for my sandbox its ok, for live look exactly which user need access to which directory (hint: www-data)

create a file with

nano /etc/apache2/conf.d/virtual.conf

with thsis content

#  multiple virtual hosts!
NameVirtualHost *

create site configs

root@dev:/etc/apache2/sites-available# nano sandbox

with content

<VirtualHost *>
        ServerAdmin admin@localhost
        ServerName  sandbox.intranet
        ServerAlias sandbox.intranet

        # Indexes + Directory Root.
        DirectoryIndex index.php
        DocumentRoot /var/www/sandbox/
        php_value open_basedir "/var/www/sandbox"
        php_value include_path ".:/var/www/sandbox/"

        # CGI Directory
        ScriptAlias /cgi-bin/ /var/cgi-bin/
        <Location /cgi-bin>
                Options +ExecCGI
        # Logfiles
        ErrorLog  /var/logs/sandbox_error.log
        CustomLog /var/logs/sandbox_access.log combined

at the default config following lines are important!

        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all

(the * after virtualhosts stands for the port, change it to a numeric value if desired)

to activate

a2ensite sandbox

to deactivate

a2dissite sandbox

reload or restart apache

/etc/init.d/apache2 restart
/etc/init.d/apache2 reload

now add to the hosts file of calling pc the line

#ip  hostname   sandbox

ip in my case if because of virtualbox image with “host only adapter”

Leave a Reply

Your email address will not be published. Required fields are marked *


Get every new post on this blog delivered to your Inbox.

Join other followers: