简体   繁体   中英

Apache+PHP - different php versions per VHost

On my local dev maschine (Ubuntu), I have apache2 and different php version to develop different projects, managed over Vhosts.

Is there a way to configure each vhost to use a specific (already installed) PHP version? So for example:

  • example1.local should use PHP 7.4
  • example2.local should use PHP 8.0
  • example3.local should use PHP 8.0
  • example4.local should use PHP 5.6

Currently, I am always running for example sudo a2enmod php{X} & sudo a2dismod php{Y} & sudo service apache2 restart to switch versions, which is really anoying.

I see you are using Apache. So you can use a .htaccess file and add there

AddHandler application/x-httpd-php74 .php

In this way your vhost uses php version 7.4

or with normal apache configuration

<VirtualHost *:80>
    ServerAdmin webmaster@example.com
    ServerName example.com
    ServerAlias www.example.com
    <IfModule mod_fastcgi.c>
        AddHandler php74-fcgi .php
    </IfModule>
</VirtualHost>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM