Home  >  Article  >  Operation and Maintenance  >  How to configure multiple versions of PHP with Nginx and Apache

How to configure multiple versions of PHP with Nginx and Apache

王林
王林forward
2023-05-23 11:10:061005browse

Sometimes our projects cannot all have the same PHP version, and each project needs to be configured with a different version of PHP. Pagoda and PHPStudy are implemented through the following configuration:

Nginx

Cut conf (not optional)

Add

include vhosts/*.conf;

in nginx.conf so that Nginx will automatically import the current directory ->All *.conf files in the vhosts directory to facilitate each project to manage the Nginx configuration file independently

Configuring multiple versions of PHP

Add # in the conf file ##

server {
        listen        80;
        server_name  localhost;
        root   "D:/WWW";
        location / {
            index index.php index.html;
            include D:/WWW/nginx.htaccess;
            autoindex  on;
        }
        location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9010;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
}

  • fastcgi_pass is the PHP execution IP port

  • fastcgi_index default PHP file

  • fastcgi_split_path_info is regular

  • fastcgi_param is the directory where PHP is located (Nginx will automatically obtain and assign the value to $fastcgi_script_name)

Assume we have two PHP versions, one PHP5 and one PHP7, then you can run them on different ports, and then set the fastcgi_pass parameter to achieve different PHP versions of each project

Apache

cutting conf (not optional)

Add

Include conf/vhosts/*.conf

in httpd.conf so that Apache will automatically import all *.conf files in the Apache installation directory->conf->vhosts directory , to facilitate each project to manage the Apache configuration file independently

Configuring multiple versions of PHP

Just add

FcgidInitialEnv PHPRC "D:/Extensions/php/php8.2.2-nts"
    AddHandler fcgid-script .php
    FcgidWrapper "D:/Extensions/php/php8.2.2-nts/php-cgi.exe" .php

to the conf file to specify the corresponding directory.

The above is the detailed content of How to configure multiple versions of PHP with Nginx and Apache. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete