Coexistence of Nginx and multi version PHP

Software download

php integrated with nginx needs to choose Non Thread Safe(nts) installation free version.

NGINX download. In this case, nginx/Windows-1.10.2 is downloaded. Download and unzip.
PHP7.0 download. This example downloads PHP 7.0 (7.0.14) VC14 x64 Non Thread Safe. Download and unzip.
PHP5.2 download. This example downloads php-5.2.17-nts-Win32-VC6-x86.zip. Download and unzip.
RunHiddenConsole, used to start PHP CGI, can close the window and still run in the background. After decompression, copy RunHiddenConsole.exe to the root directory of nginx (where the nginx.exe file is located).

Configure NGINX

Modify the nginx.conf configuration file. Send the request to ports 9000 and 9001 respectively.

server {
    listen       80;
    server_name  www.mydomain.com;

    location / {
        root   D:/php_program;
        index  index.php index.html index.htm;
    }

    location ~ \.php$ {
        root           D:/php_program;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}
server {
    listen       80;
    server_name  www.mydomain1.com;

    location / {
        root   D:/php_program1;
        index  index.php index.html index.htm;
    }

    location ~ \.php$ {
        root           D:/php_program1;
        fastcgi_pass   127.0.0.1:9001;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

Configure PHP

Copy php.ini-recommended or php.ini-development to php.ini

;Set up php Of ext Path, usually absolute path.
extension_dir = "D:/php-5.2.17-nts-Win32-VC6-x86/ext"

;Maximum limit of submitted data
post_max_size = 30M
;Maximum limit for uploading files.
upload_max_filesize = 100M

;Extensions that are usually to be turned on, php7.0 nothing php_mysql.dll,php_pdo.dll´╝îThere is no need to open both.
extension=php_gd2.dll
extension=php_mbstring.dll
extension=php_mysql.dll
extension=php_mysqli.dll
extension=php_pdo.dll
extension=php_pdo_mysql.dll

;php And nginx Integration must be on
cgi.fix_pathinfo=1

Startup script

In the nginx root directory (where the nginx.exe file is located), create a new startup script, start? Nginx.bat. Two versions of php use different ports

@ECHO OFF

ECHO Starting PHP5.2 FastCGI...
RunHiddenConsole.exe C:/infinit-server/php56/php-cgi.exe -b 127.0.0.1:9000
ECHO Starting PHP7.0 FastCGI...
RunHiddenConsole.exe C:/infinit-server/php72/php-cgi.exe -b 127.0.0.1:9001

ECHO Starting Nginx...
start nginx

In the nginx directory, create a new close script stop? Nginx.bat. Two PHP CGI can be shut down with one command.

@ECHO OFF

ECHO Stoping PHP FastCGI...
taskkill /F /IM php-cgi.exe > nul

ECHO Stoping Nginx...
taskkill /F /IM nginx.exe > nul

ECHO Stopping PHP fpm...
taskkill /F /IM php-fpm.exe > nul

Tags: Operation & Maintenance PHP Nginx Windows

Posted on Thu, 26 Mar 2020 11:00:16 -0400 by huszi001