How to run multiple PHP versions with Apache on XAMPP

To run multiple verions of PHP simultaneously this guide is going to use Apache Macros for configuration templates along with assigning a subdomain for each PHP version.

C:\xampp\conf\extra\httpd-xampp.conf:

#
# XAMPP settings
#

<IfModule env_module>
    SetEnv MYSQL_HOME "\\xampp\\mysql\\bin"
    SetEnv OPENSSL_CONF "C:/xampp/apache/bin/openssl.cnf"
    SetEnv TMP "\\xampp\\tmp"
</IfModule>

#
# PHP Setup
#

# PHP 7.4
ScriptAlias /php74 "C:/xampp/php74"
Action application/x-httpd-php74-cgi /php74/php-cgi.exe
<Directory "C:/xampp/php74">
    AllowOverride None
    Options None
    Require all denied
    <Files "php-cgi.exe">
        Require all granted
    </Files>
</Directory>

# PHP 8.0
ScriptAlias /php80 "C:/xampp/php80"
Action application/x-httpd-php80-cgi /php80/php-cgi.exe
<Directory "C:/xampp/php80">
    AllowOverride None
    Options None
    Require all denied
    <Files "php-cgi.exe">
        Require all granted
    </Files>
</Directory>

# PHP 8.1
ScriptAlias /php81 "C:/xampp/php81"
Action application/x-httpd-php81-cgi /php81/php-cgi.exe
<Directory "C:/xampp/php81">
    AllowOverride None
    Options None
    Require all denied
    <Files "php-cgi.exe">
        Require all granted
    </Files>
</Directory>

# PHP 8.2
ScriptAlias /php82 "C:/xampp/php82"
Action application/x-httpd-php82-cgi /php82/php-cgi.exe
<Directory "C:/xampp/php82">
    AllowOverride None
    Options None
    Require all denied
    <Files "php-cgi.exe">
        Require all granted
    </Files>
</Directory>

# Default PHP Handler
Action application/x-httpd-php-cgi /php81/php-cgi.exe
<FilesMatch "\.php$">
    SetHandler application/x-httpd-php-cgi
</FilesMatch>

...

C:\xampp\conf\httpd.conf:

# Include Virtualhosts
Include "conf/vhosts/*.conf"

C:\xampp\conf\vhosts\litecart.local.conf:

# Define the main domain
<VirtualHost *:80>
    ServerName litecart.local
    DocumentRoot "D:\Clients\TiM International\LiteCart\repository (dev)\public_html"
    <Directory "D:\Clients\TiM International\LiteCart\repository (dev)\public_html">
        Options Indexes FollowSymLinks Includes ExecCGI
        DirectoryIndex index.php index.html
        AllowOverride All

        <IfModule mod_authz_core.c>
            <RequireAny>
                Require ip 127.0.0.1
                Require ip ::1
            </RequireAny>
        </IfModule>

    </Directory>
</VirtualHost>

# Load the macro module for repetitive directives
LoadModule macro_module modules/mod_macro.so

#Define the macro
<Macro VHostPHP $version>
    <VirtualHost *:80>
        ServerName php$version.litecart.local
        DocumentRoot "X:\Projects\LiteCart\public_html"
        <Directory "X:\Projects\LiteCart\public_html">
            Options Indexes FollowSymLinks Includes ExecCGI
            DirectoryIndex index.php index.html
            AllowOverride All

            <IfModule mod_authz_core.c>
                <RequireAny>
                    Require ip 127.0.0.1
                    Require ip ::1
                </RequireAny>
            </IfModule>
        </Directory>

        <FilesMatch "\.php$">
            SetHandler application/x-httpd-php$version-cgi
        </FilesMatch>
    </VirtualHost>
</Macro>

# Run the macro for each PHP version
Use VHostPHP 74
Use VHostPHP 80
Use VHostPHP 81
Use VHostPHP 82

UndefMacro VHostPHP

Alternatively, if you don't want to use Macros and rather define each and every subdomain:

C:\xampp\conf\vhosts\litecart.local.conf:

<VirtualHost *:80>
    ServerName litecart.local
    DocumentRoot "X:\Projects\LiteCart\public_html"

    <Directory "X:\Projects\LiteCart\public_html">
        Options Indexes FollowSymLinks Includes ExecCGI
        DirectoryIndex index.php index.html
        AllowOverride All

        <IfModule mod_authz_core.c>
            <RequireAny>
                Require ip 127.0.0.1
                Require ip ::1
            </RequireAny>
        </IfModule>
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName php74.litecart.local
    DocumentRoot "X:\Projects\LiteCart\public_html"

    <Directory "X:\Projects\LiteCart\public_html">
        Options Indexes FollowSymLinks Includes ExecCGI
        DirectoryIndex index.php index.html
        AllowOverride All

        <IfModule mod_authz_core.c>
            <RequireAny>
                Require ip 127.0.0.1
                Require ip ::1
            </RequireAny>
        </IfModule>

        <FilesMatch "\.php$">
            SetHandler application/x-httpd-php74-cgi
        </FilesMatch>

    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName php80.litecart.local
    DocumentRoot "X:\Projects\LiteCart\public_html"

    <Directory "X:\Projects\LiteCart\public_html">
        Options Indexes FollowSymLinks Includes ExecCGI
        DirectoryIndex index.php index.html
        AllowOverride All

        <IfModule mod_authz_core.c>
            <RequireAny>
                Require ip 127.0.0.1
                Require ip ::1
            </RequireAny>
        </IfModule>

        <FilesMatch "\.php$">
            SetHandler application/x-httpd-php80-cgi
        </FilesMatch>

    </Directory>
</VirtualHost>

C:\Windows\System32\drivers\etc\hosts:

127.0.0.1  litecart.local
127.0.0.1  php74.litecart.local
127.0.0.1  php80.litecart.local
127.0.0.1  php81.litecart.local
127.0.0.1  php82.litecart.local

Revíziók

Nemrég szerkesztett cikkek
Ez a weboldal nem használ cookie-kat és nem használ harmadik féltől származó nyomkövetési technológiát. Úgy gondoljuk, hogy jobban tudjuk csinálni, mint mások, és tényleg gondolunk az Ön magánéletére.