( Virtual Hosts ) Multiple websites on Apache2


Say, for instance, we're setting up a test environment on our Apache2 server. We've created the test.conf file in /etc/apache2/sites-available with the contents:
Alias /test "/var/www/test/"
<Directory /var/www/test/>
Options +FollowSymlinks
AllowOverride All
<IfModule mod_dav.c>
Dav off
</IfModule>
SetEnv HOME /var/www/test
SetEnv HTTP_HOME /var/www/test
</Directory>
Say you want, for whatever reason, test1—you could create a second sites-available .conf file for a second test1 instance. Name that file test1.conf with the following contents:
Alias /test1 "/var/www/test1/"
<Directory /var/www/test1/>
Options +FollowSymlinks
AllowOverride All
<IfModule mod_dav.c>
Dav off
</IfModule>
SetEnv HOME /var/www/test1
SetEnv HTTP_HOME /var/www/test1
</Directory>
In order to enable those configuration files, you create the .conf file in sites-available and then use a simple command.
all we have to do is issue the command:
sudo a2ensite test.conf
sudo a2ensite test1.conf
The above command will copy the /etc/apache2/sites-available/test*.conf files to/etc/apache2/sites-enabled and make Apache2 aware of the new host. Restart Apache2 with the command:
sudo apachectl reload
Your test,test1 sites is now available to use.

Comments

Popular Posts