windows apache配置多版本php
软件准备
php安装
解压php-7.3.0-Win32-VC15-x86.zip
到 c 盘的根目录
替换 php.ini
到安装目录,点击此处下载
注意:之前的 php5 如果 php.ini
不在安装目录里面,找到 php.ini
移回到 php5 的安装目录
apache-fcgid扩展安装
解压 modules-2.4-win32-VC11.zip
,将 mod_fcgid-2.3.9/mod_fcgid/mod_fcgid.so
文件复制到 apache 的 modules
目录里
httpd.conf配置
- 注释掉以下类似配置
#LoadModule php5_module "c:\php5\php5apache2_4.dll"
#PHPIniDir "C:/php5/"
- 新增配置
#加载fcgid扩展模块(额外说明,fcgid根据实际apache版本对应,apache2版本测试2.3.6正常)
LoadModule fcgid_module modules/mod_fcgid.so
#添加映射
AddHandler fcgid-script .fcgi .php
# 设置PHP_FCGI_MAX_REQUESTS大于或等于FcgidMaxRequestsPerProcess,防止php-cgi进程在处理完所有请求前退出
FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 1000
#php-cgi每个进程的最大请求数
FcgidMaxRequestsPerProcess 1000
#php-cgi最大的进程数
FcgidMaxProcesses 3
#最大执行时间
FcgidIOTimeout 120
FcgidIdleTimeout 120
#限制最大请求字节 (单位b)
FcgidMaxRequestLen 2097152
AddType application/x-httpd-php .php
#------这里是默认虚拟主机配置
#php.ini的存放目录
FcgidInitialEnv PHPRC "C:/php5/"
#php-cgi的路径
FcgidWrapper "C:/php5/php-cgi.exe" .php
- 修改添加执行权限(如若不然,可能会提示HTTP错误,禁止访问403)
ExecCGI
为附加值
<Directory />
Options FollowSymLinks ExecCGI
AllowOverride none
Require all denied
Header set Access-Control-Allow-Origin *
</Directory>
<Directory "c:/Apache24/cgi-bin">
AllowOverride None
Options FollowSymLinks ExecCGI
Require all granted
</Directory>
<Directory "d:/phpweb">
Header set Access-Control-Allow-Origin *
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options FollowSymLinks ExecCGI
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride All
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
- 虚拟主机文件配置 (每个虚拟主机独立的配置段中只需要更改其配置版本路径即可)
<VirtualHost *:80>
ServerAdmin master@scrumcn.com
DocumentRoot D:\phpweb\leangooApi
ServerName dev.api.com
FcgidInitialEnv PHPRC "C:/php-7.3.0-Win32-VC15-x86/"
FcgidWrapper "C:/php-7.3.0-Win32-VC15-x86/php-cgi.exe" .php
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* – [F]
</VirtualHost>
- 重启 apache
解决 no input file specified 问题
使用cgi的管理方式,目前的配置会出现该问题。
解决方法:打开项目的.htaccess
文件,在RewriteRule
后面的 index.php
后面添加一个 ?
注意:不要提交到svn
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ /index.php?/$1 [L]
解决 php-cgi under Apache does not pass HTTP Basic user/pass to PHP by default 问题
使用 Basic Auth header
的方式来认证,很多参数没有了。
解决方法:leangooApi
项目的.htaccess
文件在上面的基础上加上一句RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ /index.php?/$1 [L]
注意事项:
- CI2的项目需要修改
config.php
的uri_protocol
$config['uri_protocol'] = 'REQUEST_URI';