I am migrating my app from PHP 5.6 to php 8.0 by having a front controller redirecting to my legacy app or my new app depending on the uri.

I tried with alias and it works but I need to keep the exact same host for both and no alias.

Eg: https://foo.bar.com/my_php80_routes https://foo.bar.com/my_php56_routes

Here is my unsatisfaying try with alias

<VirtualHost *:80>
    ServerName foo.bar.com

    DocumentRoot /var/www/html/foobar/public
    # Unwanted prefix
    Alias /legacy /var/www/html/foobar/legacy/web

    <Directory /var/www/html/foobar/public>
        AllowOverride none
        Require all granted

        SetEnv APP_ENV "dev"

        # Handled by php8.0 : ok
        <FilesMatch \.php$>
            SetHandler "proxy:unix:/var/run/php/php8.0-fpm.sock|fcgi://localhost/"

        FallbackResource /index.php
        DirectoryIndex index.php

    <Directory /var/www/html/foobar/legacy/web>
        AllowOverride none
        Require all granted

        # Handled by libapache2-mod-php5.6 : ok
        FallbackResource /app_dev.php
        DirectoryIndex app_dev.php

    ErrorLog /var/log/apache2/foobar.log
    CustomLog /var/log/apache2/foobar.log combined

I searched for another method, maybe based on a custom HTTP Header like "FOOBARAPP_LEGACY: 1" but I didn't find a way to map HTTP HEADER to a filesystem location with Apache.

Is there any other solution ?


I will try to explain myself better.

What I am trying to achieve is having 2 applications each running on a different PHP version, one being the "Main App" (the new app on PHP8.0) and redirecting to the "Second App" if route is not found by "Main App". All of this being completly transparent to the end user. (same domain, no prefix)

If https://foo.bar.com/posts is not yet migrated : Main App doesn't find the route and redirects to Second App that will serves the content.

When this endpoit is migrated to "Main App" : Main App find the route and serves the content.

So I'm asking a solution that doesn't involve a /prefix or a new subdomain.

1 Answer 1


So, you're trying to funnel a particular virtualhost, through a pipe, that goes to a proxy module to access the host on loopback??? But only for PHP files? That sounds unnecessarily complicated.

Why not run a second virtual host, on a secondary port, and use mod_proxy to handle the entire virtual host. (ie. generally "the way" to do an upgrade, and still have it Internet-facing).

Or, you know, you can literally do a virtualhost for each, as you migrate. And then drop-in simple redirects between virtualhosts, when the "alternate" URL appears on the "wrong" host.

When you're dealing with this sort of migration, pick the simplest form of "this versus that" and roll that way.

Or, if I completely missed the "ask" in your question... are you having success running multiple versions of PHP under the same instance? Please clarify, as frankly... it's not something I'd ever recommend because, you know... PHP. ;-)

  • Atm I only tried multiple php version on my local dev debian environment (no virtualisation) and it seems to be running fine even in the same virtual host. (modapache for 5.6 and fpm for 7.4 and 8.0). As I am a developper and not ops I don't see yet how your suggestion will work with same domain and phpsessid cookie but I will try, thanks.
    – deuterium
    Commented Sep 9, 2021 at 8:30
  • Honestly, the best thing for developers is to use multiple Docker containers, with different PHP versions and configurations, between them. Running multiple versions of the same middleware on the same Apache host is just "asking" for confusion, in my mind (and that's NOT something you want to accidently inject in to a production pipeline, of course). You might achieve the same sort of thing, using VirtualBox and Vagrant to stand-up and tear down VMs on your own machine. But, overall, my feeling is that you should at-first try to keep them discrete, just to avoid potential problems.
    – RVT
    Commented Oct 8, 2021 at 7:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .