How to configure multiple versions of PHP with Nginx and Apache

王林
Release: 2023-05-23 11:10:06
forward
1049 people have browsed it

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;
Copy after login

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;
        }
}
Copy after login

  • 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
Copy after login

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
Copy after login
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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template