需求
线上使用的是Apache+PHP5.5,但本地需要不同版本的PHP。
一保持和线上环境的PHP版本一致,其次因Yii2 Laravel这些PHP框架需要PHP7.3+的版本。
解决
先配置好Apache,下载的是安装好Apache2.4解压缩、PHP7.3解压缩。
Apache下载地址:
地址:https://home.apache.org/~steffenal/VC15/binaries/httpd-2.4.39-win64-VC15.zip
版本: httpd-2.4.39-win64-VC15.zip
Apache扩展:
地址:https://www.apachelounge.com/download/VC15/modules/mod_fcgid-2.3.9-win64-VC15.zip
版本: mod_fcgid-2.3.9-win64-VC15.zip 将解压缩出来的 mod_fcgid.so
放到apache的module目录
修改Apache配置 httpd.conf末尾加入
LoadModule fcgid_module modules/mod_fcgid.so
AddHandler fcgid-script .fcgi .php
FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 1000
FcgidMaxRequestsPerProcess 1000
FcgidMaxProcesses 15
FcgidIOTimeout 120
FcgidIdleTimeout 120
FcgidInitialEnv PHPRC "d:/php73"
FcgidWrapper "d:/php73/php-cgi.exe" .php
FcgidMaxRequestLen 104857600
这里使用 fcgid-script 模式,所以必须将php指向给这个。
加好了,系统默认使用 PHP73版本。重启 Apache,访问 phpinfo.php。
测试
访问测试 http://localhost/phpinfo.php
发现提示 403 Forbidden you don't have permission to access
,解决办法,修改httpd.conf,在option中加入指令 ExecCGI
,重启 Apache
<Directory />
Options ExecCGI FollowSymLinks
AllowOverride All
Order deny,allow
Allow from all
Satisfy all
</Directory>
不同版本设置
修改新网站httpd-vhost.conf,增加设置
<VirtualHost *:80>
ServerName local.test2.com
DocumentRoot "D:/google_home/test2"
FcgidInitialEnv PHPRC "d:/php56"
FcgidWrapper "d:/php56/php-cgi.exe" .php
FcgidWrapper "d:/php56/php-cgi.exe" .p5hx
ErrorLog "logs/test2-error.log"
CustomLog "logs/test2-access.log" common
</VirtualHost>
将d:/php56 里面的 php.ini-development 改名为 php.ini,再讲php.ini中的这一段去掉注释
extension_dir = "ext"
重启访问这个域名的 http://local.test2.com/phpinfo.php
显示的PHP5.6。因为我将PHP扩展名改为了 *.p5hx
,所以需要再多加一段FcgidWrapper "d:/php56/php-cgi.exe" .p5hx
版本
系统Win7 x64位
Apache: Apache/2.4.39 (Win64) VC15
PHP7.3: MSVC15 (Visual C++ 2017) ,TS
PHP5.6: MSVC11 (Visual C++ 2012),TS
mod_fcgid: mod_fcgid-2.3.9-win64-VC15.zip
关键的几点
LoadModule fcgid_module modules/mod_fcgid.so
AddHandler fcgid-script .fcgi .php
Options ExecCGI FollowSymLinks
Author: coconets@163.com