1

I'm upgrading my application to new PHP version.

For that I created two virtualhosts one server PHP 5.3 application and another with PHP 5.6.

My virtualhosts are like,

<VirtualHost *:80>
  ServerName php53app.com 
  DocumentRoot /var/www/php_53/public 
  <Directory />
   Options FollowSymLinks
   AllowOverride All
   AddHandler php-cgi .php
   Action php-cgi /cgi-bin-php/php-cgi-5.3.0
  </Directory>
  ErrorLog /var/log/apache2/error.log
  LogLevel warn
  CustomLog /var/log/apache2/access.log combined
</VirtualHost>

and

<VirtualHost *:80>
  ServerName php56app.com 
  DocumentRoot /var/www/php_56/public 
  <Directory />
   Options FollowSymLinks
   AllowOverride All
   AddHandler php-cgi .php
   Action php-cgi /cgi-bin-php/php-cgi-5.6.0
  </Directory>
  ErrorLog /var/log/apache2/error.log
  LogLevel warn
  CustomLog /var/log/apache2/access.log combined
</VirtualHost>

I'm planning migrate each url by url.

For example :

When I'm migrating /login to new app, it should show php53app.com/login instead of php56app.com/login.

So my need is to serve all URLs in same domain name whether it is new or old. Is there any possible way by using apache's mod rewrite or something?

Nisam
  • 113
  • 6
  • Why don't you just add the Servername of the one as an Alias under the second? – Lexib0y Oct 21 '15 at 09:58
  • @Lexib0y My two servers are running under two different PHP versions. Different applications. How can I user serveralias to them? bacause I'm having two different document root – Nisam Oct 21 '15 at 10:24
  • Oops, you are right, my mistake. – Lexib0y Oct 21 '15 at 19:50

1 Answers1

1

Rewriting is not really the way to go. You should use proxying the request.

From mod_proxy documentation:

In addition, reverse proxies can be used simply to bring several servers into the same URL space.

Your setup will look like this:

<VirtualHost *:80>
    ServerName php53app.com 
    DocumentRoot /var/www/php_53/public

    # General proxy config ... do not skip
    <Proxy *>
        AddDefaultCharset off
        Order deny,allow
        Allow from all
    </Proxy>

    # now proxy the migrated part
    <Location /login>
        ProxyPass           http://php56app.com/login
        ProxyPassReverse    http://php56app.com/login
    </Location>

    <Directory />
        Options FollowSymLinks
        AllowOverride All
        AddHandler php-cgi .php
        Action php-cgi /cgi-bin-php/php-cgi-5.3.0
    </Directory>
    ErrorLog /var/log/apache2/error.log
    LogLevel warn
    CustomLog /var/log/apache2/access.log combined
</VirtualHost>

Of course proxying can be achieved with rewrite but this way it is a bit more explicit and allows for finer control of options.

zeridon
  • 760
  • 3
  • 6