通过 Apache 获取空白 PHP 页面 [英] Getting blank PHP page over Apache

查看:37
本文介绍了通过 Apache 获取空白 PHP 页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在新设置的digitalOcean 云服务器(CentOS)中,我安装了php 和Apache.网络服务器运行良好:

[root@a2m5cent01 httpd]# service httpd statushttpd (pid 11232) 正在运行...[root@a2m5cent01 httpd]# php --version |头-1PHP 5.3.3 (cli)(构建时间:2013 年 12 月 11 日 03:29:57)

但是如果我尝试访问任何 php 页面,浏览器会显示空白页面(白页).

以下是我目前为排除故障所做的工作:

  1. 创建了一个包含以下内容的页面:<?php phpinfo();?>.从浏览器查看时显示空白页面.
  2. 只是为了确保,apache 指向正确的目录,在那里放置了一个静态的 .html 页面,并且看到它在浏览器中运行良好,所以 apache 正在工作并且目录是正确的.立>
  3. /etc/php.ini 中,将display_errors 指令更改为On.还是空白页
  4. 在 Apache 配置文件 (/etc/httpd/conf/httpd.conf) 中找到这一行 Include conf.d/*.conf.在 conf.d 目录中,有一个包含以下行的 php.conf 文件:LoadModule php5_module modules/libphp5.so.确保此 .so 文件确实存在于此位置.
  5. 在同一个文件中,我也有这两行:AddHandler php5-script .phpAddType text/html .php
  6. 从 CLI 执行 php 页面,它运行良好 - 所以 php 可以在本地运行.

那为什么它总是在浏览器上显示一个空白/白页?我还缺少什么?

编辑根据@Nathan 的建议,

  1. 我检查了 Apache 错误日志文件,没有看到任何错误在那里报告.
  2. 我的 /etc/php.ini 说,php error_log 位于 syslog.所以我检查了 /var/log/messages 但找不到任何 PHP 错误消息
  3. 接下来,我将一些普通的 HTML 放入包含 phpinfo() 调用的 php 文件中.有趣的是,我发现即使是普通的 HTML 文本也没有出现.它仍然产生空白页.
  4. 然后我检查了 Apache access 日志.惊喜!我尝试在浏览器中加载的任何 PHP 文件都没有 GET 请求.但是对所有非php文件的GET请求都带有200个返回码.

Apache 甚至记录对 PHP 文件的任何访问请求.知道为什么会发生这种情况吗?

解决方案

已经有一段时间了,但我想回到这个问题来更新问题出在目录权限设置上.

我使用的 FPM 用户没有必要的权限来执行 Web 根目录中的 index.php 文件.

为了避免将来出现这些问题,我创建了一个自动 bash 脚本,该脚本将在 DigitalOcean 框中自动创建和配置网络服务器.请看这里https://github.com/akash-mitra/fairy>

这个脚本会自动,

  • 安装 Nginx
  • 为 nginx 创建虚拟服务器块
  • 安装 PHP、PHP APC、PHP Curl 等
  • 支持 PHP 快速进程管理器 (php-fpm)
  • 安装 Memcached
  • 安装数据库 (MariaDB/MySQL)
  • 可选择安装 PHP Composer 和 Laravel
  • 配置和加强 SSH
  • 激活防火墙
  • 可选择在 DO 服务器中启用 SWAP 空间并修复区域设置问题

In a newly setup digitalOcean cloud server (CentOS), I have installed php and Apache. The webserver is running fine:

[root@a2m5cent01 httpd]# service httpd status
httpd (pid  11232) is running...
[root@a2m5cent01 httpd]# php --version | head -1
PHP 5.3.3 (cli) (built: Dec 11 2013 03:29:57) 

But browser is showing blank pages (white page) if I try to visit any php page.

Here is what I have done so far to troubleshoot:

  1. Created a page with following content: <?php phpinfo(); ?>. It displays a blank page when viewed from browser.
  2. Just to ensure, apache is pointing to the correct directory, placed a static .html page there, and saw it comes out fine in browser, so apache is working and directory is correct.
  3. In /etc/php.ini, changed display_errors directive to On. Still blank page
  4. In Apache config file (/etc/httpd/conf/httpd.conf) found this line Include conf.d/*.conf. Inside conf.d directory, there is a php.conf file containing the line: LoadModule php5_module modules/libphp5.so. Ensured that this .so file actually exists in this place.
  5. In the same file I have these two lines as well: AddHandler php5-script .php and AddType text/html .php
  6. Executed the php page from CLI, it works fine - so php is working locally.

Then why is it always shows a blank/white page over the browser? What else am I missing?

EDIT Based on suggestions from @Nathan,

  1. I checked Apache error log file, could not see any error being reported there.
  2. My /etc/php.ini says, php error_log is located as syslog. So I checked /var/log/messages but could not find any PHP error message
  3. Next I put some normal HTML in the php file containing phpinfo() call. Interestingly I found that even the normal HTML texts are also not coming. It still produces blank page.
  4. Then I checked Apache access log. Surprise! There is no GET request for any of the PHP files I tried to load in the browser. But GET request for all the non-php files are there with 200 return code.

Apache is not even logging any access request for PHP files. Any idea why would that happen?

解决方案

It's been sometime, but I wanted to come back to this question to update that the issue was with the directory permission setup.

The FPM user I was using didn't have necessary permission to execute the index.php file in the web root.

To avoid these issues in the future, I have created an automated bash script that will automatically create and configure webservers in DigitalOcean boxes. Please take a look here https://github.com/akash-mitra/fairy

This script will automatically,

  • Installs Nginx
  • Create virtual server block for nginx
  • Installs PHP, PHP APC, PHP Curl etc.
  • Supports PHP Fast Process Manager (php-fpm)
  • Installs Memcached
  • Installs Database (MariaDB / MySQL)
  • Optionally Installs PHP Composer and Laravel
  • Configures and Strengthens SSH
  • Activates Firewall
  • Optionally enables SWAP space in DO server and fixes a locale issue

这篇关于通过 Apache 获取空白 PHP 页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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