Wednesday, May 22, 2013

Dynamic VirtualHost in Apache and Ubuntu


Some time you need set dynamic vhost to help you do not restart server when have new site.

Enable  vhost_alias
sudo a2enmod vhost_alias

In /etc/apache2/site-available

Solution 1: For your server many IP.

- With default file

<VirtualHost IP2:80>

ServerName servername@name.com

//DocumentRoot /var/www (comment it)

            ……. (go to bottom of section)

            UseCanoicalName Off

            VirtualDocumentRoot /home/web/sites/mysite.com/site/%0

</VirtualHost>


- With mysite150.com

<VirtualHost *:80>

            ServerName mysite150.com

            ServerAlias www.mysite150.com

            DocumentRoot /home/web/sites/mysite.com/system/mysite150.com/public

            SetEnv APPLICATION_ENV “production”

            <Directory /home/web/sites/mysite.com/system/mysite150.com/public/>

                        DirectoryIndex index.php

                        AllowOverride All

                        Order allow, deny

                        Allow from all

            </Directory>

</VirtualHost>

- With mana.mysqit15.com

<VirtualHost *:80>

            ServerName mana.mysqit15.com

            ServerAlias www. mana .mysqit15.com

            DocumentRoot /home/web/sites/mysite.com/system/mana.mysqit15.com/public

            SetEnv APPLICATION_ENV “production”

            <Directory /home/web/sites/mysite.com/system/mana.mysqit15.com/public/>

                        DirectoryIndex index.php

                        AllowOverride All

                        Order allow, deny

                        Allow from all

            </Directory>

</VirtualHost>

Solution 2: For your server 1 IP.

The same solution 1 but so you have 1 IP should you can set *:80 for all VirtualHost

cd /home/web/sites/mysite.com/site/

ln –s cd /home/web/sites/mysite.com//system/mysite.com/ /home/web/sitesmysite.com//site/mysite.com



Good luck to you

No comments:

Post a Comment