问题出现的背景
背景:
因为不同项目使用了多个版本的php,重装系统后,因为phpstudy切换php版本更便捷,
所以php集成环境从xampp改到了phpstudy。
系统信息:
操作系统:Windows 10,
安装的php版本:php 7.1,php 7.3,php 8.0,php 8.2
项目信息:
php版本:php 8.0
web端:vue3 + vite5
MySQL :msyql 5.7.44
问题描述
在一个web项目中,可能是apache配置中开启了cgi之类的功能,php无法获取到web发送的http请求头中的“Authorization”字段,
导致web请求业务无法通过检验。
解决方式
找到apache的httpd.conf配置目录,如D:\phpstudy_pro\Extensions\Apache2.4.39\conf\httpd.conf,
添加“SetEnvIf Authorization “(.*)” HTTP_AUTHORIZATION=$1”,如下图所示,然后重启apache即可。
<IfModule dir_module>
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
DirectoryIndex index.php index.html
</IfModule>
其他
phpstudy工具配置多个网站以及同端口配置多个alias。
网站配置文件路径,并不是在apache默认的httpd.conf里面,而是在vhost文件夹内,
如:D:\phpstudy_pro\Extensions\Apache2.4.39\conf\vhosts,
别名配置
<VirtualHost _default_:8230>
DocumentRoot "D:/phpstudy_pro/WWW/erp/public/"
FcgidInitialEnv PHPRC "D:/phpstudy_pro/Extensions/php/php8.0.2nts"
AddHandler fcgid-script .php
FcgidWrapper "D:/phpstudy_pro/Extensions/php/php8.0.2nts/php-cgi.exe" .php
ErrorLog "D:/phpstudy_pro/Extensions/Apache2.4.39/logs/localhost_error.log"
CustomLog "D:/phpstudy_pro/Extensions/Apache2.4.39/logs/localhost_acess.log" common
# 禁止直接访问根路径 /
<LocationMatch "^/$">
Require all denied
</LocationMatch>
#别名
alias /erp "D:/phpstudy_pro/WWW/erp/public/"
<Directory "D:/phpstudy_pro/WWW/erp/public/">
Options FollowSymLinks ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
DirectoryIndex index.php index.html error/index.html
</Directory>
# 按上述样式添加多个别名
ErrorDocument 400 /error/400.html
ErrorDocument 403 /error/403.html
ErrorDocument 404 /error/404.html
ErrorDocument 500 /error/500.html
ErrorDocument 501 /error/501.html
ErrorDocument 502 /error/502.html
ErrorDocument 503 /error/503.html
ErrorDocument 504 /error/504.html
ErrorDocument 505 /error/505.html
ErrorDocument 506 /error/506.html
ErrorDocument 507 /error/507.html
ErrorDocument 510 /error/510.html
</VirtualHost>