问题描述
我正在与一位同事合作,在XAMPP中的MAC上设置本地环境,在Windows上,我的虚拟主机看起来像下面的虚拟主机.
I am working with a colleague to set up their local environment on a MAC in XAMPP, on windows my vhost looks like the one below.
当我访问 http://domain.local/cgi-bin/handler之类的URL时. php 网络服务器正确处理了PHP,但是在他的服务器上,我们收到500服务器错误和此消息...
When I access a URL like http://domain.local/cgi-bin/handler.php the web server processes the PHP correctly but on his we get a 500 server error and this message...
The server encountered an internal error and was unable to complete your request.
Error message:
Premature end of script headers:
我们尝试将cgi-bin文件夹的名称更改为其他名称,因为我注意到httpd.conf中还有另一个别名,但这没有任何作用...所以在我看来,该问题与权限相关.
We tried changing the name of the cgi-bin folder to something else as I noticed there was another alias in httpd.conf but this had no effect...so it seems to me like the issue is permissions related.
我们认为可以通过访问 http://domain.local/cgi-bin来设置别名/filenothere.php (不存在)会按预期抛出404,任何.html/.pl文件均无法执行.
We believe the alias is setup ok as accessing http://domain.local/cgi-bin/filenothere.php which doesn't exist throws a 404 as expected, any .html/.pl files fail to execute.
cgi-bin文件夹中的权限是...
The permissions that exist on the cgi-bin folder are...
rwxrwxrwx dave员工
rwxrwxrwx dave staff
,由用户和组所有....
and is owned by the user and group....
戴夫员工
虚拟主机
<VirtualHost *:80>
ServerAdmin webmaster@example.com
ServerName www.domain.local
ServerAlias domain.local
ServerAlias api.domain.local
# Indexes + Directory Root.
DirectoryIndex index.php
DocumentRoot E:/home/www/www.domain.co.uk/htdocs/
# CGI Directory
ScriptAlias /cgi-bin/ E:/home/www/www.domain.co.uk/cgi-bin/
<Location /cgi-bin>
Options +ExecCGI
</Location>
# Logfiles
ErrorLog E:/home/www/www.domain.co.uk/logs/error.log
CustomLog E:/home/www/www.domain.co.uk/logs/access.log combined
</VirtualHost>
您知道什么原因导致该PHP文件无法执行吗?
Any idea what is causing this PHP file to not be executed?
更新尝试在PHP文件的开头添加标头以表明内容是PHP,现在仅输出PHP代码.
UPDATETried adding a header to say that the content is PHP to the start of the PHP file and this now simply outputs the PHP code.
好像可以使用别名中指定的任何路径访问,但是服务器不知道如何执行内容,这适用于HTML和PHP
It's as if any path specified in as an Alias is accessible but the server doesn't know how to execute the content, this is for HTML as well as PHP
推荐答案
我认为您的cgi-bin需要一个部分.
I think you need a section for your cgi-bin.
您的服务器可以向您显示脚本源的事实意味着该服务器至少具有对/file/system/path/to/cgi-bin和IIRC的读取权限,这些权限与ScriptAlias冲突b/c ScriptAlias期望/file/system出于安全原因,/path/to/cgi-bin不可访问.我认为您的解决方案应遵循以下原则:
The fact that your server can show you the script sources means the server has at least read permissions on /file/system/path/to/cgi-bin and IIRC that clashes with ScriptAlias b/c ScriptAlias expects /file/system/path/to/cgi-bin to be unaccessible for security reasons. I think your solution should look something along the lines of:
<Directory /file/system/path/to/cgi-bin>
Options ExecCGI
SetHandler cgi-script
</Directory
这篇关于在documentroot之外运行PHP文件(cgi-bin文件夹)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!