403 禁止在工作模式下使用 php。仅从浏览器访问 php 文件

发布于 2024-09-29 01:19:23 字数 994 浏览 14 评论 0原文

首先我要说的是,是的,我已经在谷歌和 stackoverflow 中专门搜索过这个问题,我找到了很多答案并尝试了所有答案。在这一点上,我相信我唯一的资源就是自己发布问题,即使场景听起来重复,也请善意地尝试提供帮助。

情况非常基本,在 Ubuntu 桌面 10.04 上,我根据本指南通过 Synaptic 和 Php5 设置 apache 和 它的衍生品在这里。 此时,如果我进入命令行并调用 php 脚本,它就会起作用,例如:

  php test.php

输出我的 hello world 没有任何问题。但是如果我转到 firefox 并指向 test.php 它将显示 403 错误 Forbidden...

我已将 /var/、/var/www/ 和 /var/www/test.php 的所有权更改为我可以的每个变量想想(www-data [apache作为这个用户运行],purefan [我的常规用户],root)没有什么区别,我也多次更改权限777、0777(只是为了安全)、644、755,没有改变。 从 CLI 中,我将 phpinfo 放入一个文件中,并将其添加到此处

如果我没记错的话,问题是在 Apache 调用 php 解释器时发生的,就像我访问 http://localhost/index.php 时一样 它显示 apache 的默认“It Works!”页面,但如果我将 php 内容添加到该文件中,它就会被忽略,但不会显示任何错误(还检查了错误日志和系统日志)。

所以,如果您有任何建议,请告诉我,这不是生死攸关的事情,但我真的很想使用 Worker 而不是 prefork 进行设置。

谢谢您的宝贵时间

First off let me start by saying that yes I have searched for this in google and in stackoverflow specifically, I have found many answers and tried them all. At this point I believe my only resource is posting the question myself, even if the scenario sounds repeated please be so kind as to try to help.

The situation is quite basic, on Ubuntu desktop 10.04 I set up apache via Synaptic and Php5 according to this guide and its spin-off here.
At this point if I go on command line and call a php script it works, for example:

  php test.php

outputs my hello world without any problem. But if I go to firefox and point to test.php it will show the 403 error Forbidden...

I have changed ownership on /var/, /var/www/ and /var/www/test.php to every variable I can think of (www-data [apache runs as this user], purefan [my regular user], root) it makes no difference, I have also changed permissions several times 777, 0777 (just to be safe), 644, 755, no change.
from CLI I got the phpinfo into a file and added it here.

If Im not mistaken the problem is happening when Apache calls the php interpreter, as when I go to http://localhost/index.php it shows apache's default "It Works!" page, but if I add php content to that file it simply gets ignored, no error is shown though (also checked error log and syslog).

So please, if you have any suggestion let me know, this is not a life or dead thing but would really like to set up using worker instead of prefork.

Thank you for your time

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

帅的被狗咬 2024-10-06 01:19:23

我遇到了完全相同的问题..首先我在虚拟机下成功安装了带有worker mpm的apache2和带有fastcgi的php5..但是当我在生产主机上尝试它(使用完全相同的过程)时,它给了我禁止的错误。

经过大量搜索,我终于成功了。在这里您可以找到我为使其正常工作所做的步骤:

这些是我安装的用于通过 mpm-worker 和 mpm-worker 获取 apache2 的软件包。 php5 with fastcgi:

  • apache2
  • apache2-mpm-worker
  • php5-cli
  • php5-cgi
  • php5-common
  • libapache2-mod-fcgid

然后你需要创建一个文件来告诉apache如何使用php文件。我在 /etc/apache2/conf.d 目录下创建了一个名为 php.conf 的文件。内容应该是这样:

<Directory /usr/share>
    AddHandler fcgid-script .php
    FCGIWrapper /usr/lib/cgi-bin/php5 .php
    Options ExecCGI FollowSymlinks Indexes
</Directory>

<Files ~ (\.php)>
    AddHandler fcgid-script .php
    FCGIWrapper /usr/lib/cgi-bin/php5 .php
    Options  ExecCGI
    allow from all
</Files>

仅此而已。显然,请确保文件的用户、组和权限正确(用户和组为 www-data,文件和文件夹为 644 和 755)。

我的失败是没有添加 标签。添加后我终于可以访问该网站了。在 标签下进行 php 配置之前,我在虚拟主机中的 标签下添加了这些行。像这样:

<Directory /var/www/website/>
    AddHandler fcgid-script .php
    FCGIWrapper /usr/lib/cgi-bin/php5 .php
    Options  ExecCGI Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

但这不起作用!在我的虚拟机中,我确实有这一行,并且它工作得很好......所以,也许我的解决方案也适合您。

我希望这会对某人有所帮助:)

编辑:这是拯救我生命的论坛帖子:http://forum.parallels.com/showthread.php?t=85413

I had exactly this same problem.. first I installed apache2 with worker mpm and php5 with fastcgi successfully under a virtual machine.. but when I tried it (using exactly the same process) on my production host, it gave me forbidden errors.

After a lot of search, I finally got it working. Here you can find the steps I've done to get it working:

These are the packages I've installed to get apache2 with mpm-worker & php5 with fastcgi:

  • apache2
  • apache2-mpm-worker
  • php5-cli
  • php5-cgi
  • php5-common
  • libapache2-mod-fcgid

Then you need to create a file to tell apache how to use php files. I've created one under the /etc/apache2/conf.d directory named php.conf. This should be the content:

<Directory /usr/share>
    AddHandler fcgid-script .php
    FCGIWrapper /usr/lib/cgi-bin/php5 .php
    Options ExecCGI FollowSymlinks Indexes
</Directory>

<Files ~ (\.php)>
    AddHandler fcgid-script .php
    FCGIWrapper /usr/lib/cgi-bin/php5 .php
    Options  ExecCGI
    allow from all
</Files>

And that's all. Obviously, ensure that the user, group and permissions for the files are the correct one (www-data for user and group and 644 & 755 for files and folders).

My failure was not to add the <Files></Files> tag. After adding it I finally could access the site. Before having the php configuration under the <Files> tag I was adding those lines in the virtual-host, under the <Directory> tag of my host. Like this:

<Directory /var/www/website/>
    AddHandler fcgid-script .php
    FCGIWrapper /usr/lib/cgi-bin/php5 .php
    Options  ExecCGI Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

But this wasn't working! In my virtual machine I have exactly this lines and it works perfectly... so, maybe my solution works for you too.

I hope this will help somebody :)

Edit: This is the forum thread that saved my life: http://forum.parallels.com/showthread.php?t=85413

我们只是彼此的过ke 2024-10-06 01:19:23

如果你没有在 apache httpd.conf 中启用 ExecCGI,你会得到 PHP only禁止的错误

Options Indexes FollowSymLinks **ExecCGI**

AllowOverride None
Require all granted

YOu get the PHP only forbidden error, if you have not enabled ExecCGI in your apache httpd.conf

Options Indexes FollowSymLinks **ExecCGI**

AllowOverride None
Require all granted

枕梦 2024-10-06 01:19:23

嗯,你安装了 Apache2 PHP 模块吗?

听起来有点像你安装了 php5-cli 但没有安装 apache2 模块。

页面上,您找到了一个简短的示例。也许我可以帮助你。

hmm have you installed the Apache2 PHP module?

It sounds a bit that you have installed php5-cli but not the apache2 module.

On this page you found a short example. Perhaps i could help you.

尴尬癌患者 2024-10-06 01:19:23

这真的让我很困惑。有完全相同的问题。
就这样解决了:
我添加了 .htaccess 文件,其中包含以下内容:

# Follow symbolic links in this directory.
Options +FollowSymLinks

该文件夹下的所有内容突然开始正常工作。

It puzzles me really a lot. Had exactly same problem.
Solved it that way:
I added .htaccess file with following content in it:

# Follow symbolic links in this directory.
Options +FollowSymLinks

And everything under that folder suddenly started to work properly.

假情假意假温柔 2024-10-06 01:19:23

IndexesFollowSymLinks 添加到 Files 标记解决了我的问题:

<Files ~ "\.php
gt;"
  AddHandler fcgid-script .php
  FcgidWrapper "c:/php/php-cgi.exe" .php
  Options ExecCGI Indexes FollowSymLinks
  allow from all
</Files>

Adding Indexes and FollowSymLinks to Files tag solved my problem:

<Files ~ "\.php
gt;"
  AddHandler fcgid-script .php
  FcgidWrapper "c:/php/php-cgi.exe" .php
  Options ExecCGI Indexes FollowSymLinks
  allow from all
</Files>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文