在 documentroot(cgi-bin 文件夹)之外运行 PHP 文件 [英] Running PHP file outside of documentroot (cgi-bin folder)

查看:20
本文介绍了在 documentroot(cgi-bin 文件夹)之外运行 PHP 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与一位同事合作,在 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 Web 服务器正确处理 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 戴夫员工

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 代码.

UPDATE Tried 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 冲突的 IIRC 的读取权限 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(cgi-bin 文件夹)之外运行 PHP 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆