通过 Apache 获取空白 PHP 页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21083506/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting blank PHP page over Apache
提问by hashbrown
In a newly setup digitalOcean cloud server (CentOS), I have installed php and Apache. The webserver is running fine:
在新设置的digitalOcean 云服务器(CentOS)中,我安装了 php 和 Apache。网络服务器运行良好:
[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.
但是如果我尝试访问任何 php 页面,浏览器会显示空白页面(白页)。
Here is what I have done so far to troubleshoot:
以下是我到目前为止所做的故障排除:
- Created a page with following content:
<?php phpinfo(); ?>. It displays a blank page when viewed from browser. - Just to ensure, apache is pointing to the correct directory, placed a static
.htmlpage there, and saw it comes out fine in browser, so apache is working and directory is correct. - In
/etc/php.ini, changeddisplay_errorsdirective toOn. Still blank page - In Apache config file (
/etc/httpd/conf/httpd.conf) found this lineInclude conf.d/*.conf. Insideconf.ddirectory, there is aphp.conffile containing the line:LoadModule php5_module modules/libphp5.so. Ensured that this .so file actually exists in this place. - In the same file I have these two lines as well:
AddHandler php5-script .phpandAddType text/html .php - Executed the php page from CLI, it works fine - so php is working locally.
- 创建了一个包含以下内容的页面:
<?php phpinfo(); ?>. 从浏览器查看时,它显示一个空白页面。 - 只是为了确保,apache 指向正确的目录,在
.html那里放置了一个静态页面,并且在浏览器中看到它运行良好,所以 apache 正在工作并且目录是正确的。 - 在 中
/etc/php.ini,将display_errors指令更改为On. 还是空白页 - 在 Apache 配置文件 (
/etc/httpd/conf/httpd.conf) 中找到了这一行Include conf.d/*.conf。在conf.d目录中,有一个php.conf包含以下行的文件:LoadModule php5_module modules/libphp5.so. 确保这个 .so 文件确实存在于这个地方。 - 在同一个文件中,我也有这两行:
AddHandler php5-script .php和AddType text/html .php - 从 CLI 执行 php 页面,它工作正常 - 所以 php 正在本地工作。
Then why is it always shows a blank/white page over the browser? What else am I missing?
那么为什么它总是在浏览器上显示一个空白/白页?我还缺少什么?
EDITBased on suggestions from @Nathan,
编辑根据@Nathan 的建议,
- I checked Apache error log file, could not see any error being reported there.
- My
/etc/php.inisays, php error_log is located assyslog. So I checked/var/log/messagesbut could not find any PHP error message - Next I put some normal
HTMLin the php file containingphpinfo()call. Interestingly I found that even the normal HTML texts are also not coming. It stillproduces blank page. - Then I checked Apache
accesslog. Surprise! There is noGETrequest for any of the PHP files I tried to load in the browser. But GETrequest for all the non-phpfiles are there with 200 return code.
- 我检查了 Apache 错误日志文件,没有看到那里报告了任何错误。
- 我
/etc/php.ini说,php error_log 位于syslog. 所以我检查/var/log/messages但找不到任何 PHP 错误消息 - 接下来我
HTML在包含phpinfo()调用的 php 文件中放了一些法线。有趣的是,我发现即使是普通的 HTML 文本也没有出现。它仍然产生空白页。 - 然后我检查了Apache
access日志。惊喜!没有GET请求我尝试在浏览器中加载的任何 PHP 文件。但是对所有非 php文件的GET请求都带有 200 返回码。
Apache is noteven logging any access request for PHP files. Any idea why would that happen?
Apache甚至没有记录对 PHP 文件的任何访问请求。知道为什么会这样吗?
采纳答案by hashbrown
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.phpfile in the web root.
我使用的 FPM 用户没有index.php在 Web 根目录中执行文件的必要权限。
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
为了避免将来出现这些问题,我创建了一个自动 bash 脚本,该脚本将在 DigitalOcean 框中自动创建和配置网络服务器。请看这里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
- 安装 Nginx
- 为 nginx 创建虚拟服务器块
- 安装 PHP、PHP APC、PHP Curl 等。
- 支持 PHP 快速进程管理器 (php-fpm)
- 安装 Memcached
- 安装数据库 (MariaDB / MySQL)
- 可选择安装 PHP Composer 和 Laravel
- 配置和加强 SSH
- 激活防火墙
- 可选择在 DO 服务器中启用 SWAP 空间并修复区域设置问题
回答by linuxmint17
check out your phpinfo() script.
检查您的 phpinfo() 脚本。
<?php
phpinfo();
?>
missing the "php" behind the first "?" will give a blank page
缺少第一个“?”后面的“php” 会给一个空白页
回答by DeSmOnd
I think your php installation with apache is faulty. Thats why you can not see any php page in your webserver. Clean remove all the existing apps, like httpd,php,php-fpm,php-cli etc. and try to clean isntall in this order
我认为您使用 apache 安装的 php 有问题。这就是为什么您在您的网络服务器中看不到任何 php 页面的原因。Clean 删除所有现有的应用程序,如 httpd、php、php-fpm、php-cli 等,并尝试按此顺序清理 isntall
yum install httpd -y
yum install php php-common php-cli php-gd php-curl php-fpm -y
then make sure you restart yout httpd server.
然后确保你重新启动你的 httpd 服务器。
service httpd restart
Install mod_fastcgi:
安装 mod_fastcgi:
yum install mod_fastcgi
Start the service:
启动服务:
service php-fpm start
Restart Apache:
重启阿帕奇:
service httpd restart
5. Configuration of Apache with PHP-FPM
5.使用PHP-FPM配置Apache
Open the fastcgi.conf file:
打开 fastcgi.conf 文件:
nano /etc/httpd/conf.d/fastcgi.conf
Add this to the end of the file:
将此添加到文件末尾:
<IfModule mod_fastcgi.c>
DirectoryIndex index.html index.shtml index.cgi index.php
AddHandler php5-fcgi .php
Action php5-fcgi /php5-fcgi
Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -host 127.0.0.1:9000 -pass-header Authorization
</IfModule>
After that search after "FastCgiWrapper" and make sure it's set to "off" then save the file.
在“FastCgiWrapper”之后搜索并确保将其设置为“关闭”,然后保存文件。
The /usr/lib/cgi-bin/ directory must exist, so we create it:
/usr/lib/cgi-bin/ 目录必须存在,所以我们创建它:
mkdir /usr/lib/cgi-bin/
If mod_php is installed and enabled, we need to disable it so open the configuration at /etc/httpd/conf.d/php.conf:
如果安装并启用了 mod_php,我们需要禁用它,因此在 /etc/httpd/conf.d/php.conf 打开配置:
nano /etc/httpd/conf.d/php.conf
Comment out the AddHandler and AddType lines so it looks like here:
注释掉 AddHandler 和 AddType 行,使其看起来像这里:
#
# PHP is an HTML-embedded scripting language which attempts to make it
# easy for developers to write dynamically generated webpages.
#
<IfModule prefork.c>
LoadModule php5_module modules/libphp5.so
</IfModule>
<IfModule worker.c>
LoadModule php5_module modules/libphp5-zts.so
</IfModule>
#
# Cause the PHP interpreter to handle files with a .php extension.
#
#AddHandler php5-script .php
#AddType text/html .php
#
# Add index.php to the list of files that will be served as directory
# indexes.
#
DirectoryIndex index.php
#
# Uncomment the following line to allow PHP to pretty-print .phps
# files as PHP source code:
#
#AddType application/x-httpd-php-source .phps
Save the file and restart Apache:
保存文件并重启Apache:
service httpd restart
回答by wwwanaya
I have the same issue... The problem is in the iptables. (It seems like it)
我有同样的问题...问题出在 iptables 中。(好像是这样)
Try with:
尝试:
service iptables stop
## check if it stop...
service iptables status
Then try to reload the page again.
然后尝试再次重新加载页面。
If you had other solution please share.
如果您有其他解决方案,请分享。
[edit] Restarting the iptables service is working for me.
[编辑] 重新启动 iptables 服务对我有用。
Try:
尝试:
service iptables restart
回答by Aidan
Are you navigating to the php file directly? Or are you just going to the directory root?
你是直接导航到php文件吗?或者你只是去目录根?
If the later, Apache might not be recognizing .php as the directory index.
如果是后者,Apache 可能不会将 .php 识别为目录索引。
To test, try create a .htaccess file in your web root containing the following line:
要进行测试,请尝试在您的 Web 根目录中创建一个包含以下行的 .htaccess 文件:
DirectoryIndex index.php
回答by Saemmel
First of all you should check the permissions of your file. If you don't grant read-permission to public, Apache produces a blank page without showing any errors.
首先,您应该检查文件的权限。如果您不向 public 授予读取权限,Apache 会生成一个空白页面而不会显示任何错误。
回答by Paul Latour
Sorry to repost an old thread...this is important.
很抱歉重新发布一个旧线程......这很重要。
I also was having these problems where no html response was outputting
我也遇到了这些问题,没有输出 html 响应
After double-checking php.ini or my apache conf files and was still receiving no output, I later found out that I was suppressing the error of an include / require of a class, with @, which was nested within a constructor function. There was a syntax error in the included file, which stopped all output altogether when errors were thrown.
在仔细检查 php.ini 或我的 apache conf 文件并且仍然没有收到任何输出后,我后来发现我正在抑制类的包含/要求的错误, with @,它嵌套在构造函数中。包含的文件中存在语法错误,在抛出错误时会完全停止所有输出。
So, check your handlers first. If you are storing all your output into vars first and you are including various scripts first that fail you'll have to see those errors. If you suppress file handler errors, you'll get a blank screen if you have a syntax error in the file.
因此,请先检查您的处理程序。如果您首先将所有输出存储到 vars 中,并且首先包含各种失败的脚本,您将不得不看到这些错误。如果您抑制文件处理程序错误,并且文件中有语法错误,您将看到一个空白屏幕。
Search your files for all instances of @in your php code. Then turn @include "/path_to/script.php";to include "/path_to/script.php";or anything @$foointo $fooas such var might reference a dependency that is causing your script to end with nothing showing in the httpd error log or in the http response.
在文件中搜索@php 代码中的所有实例。然后打开@include "/path_to/script.php";到include "/path_to/script.php";什么的@$foo到$foo这样的VAR可能引用导致你的脚本有没有在httpd的错误日志或HTTP响应显示结束的依赖。
回答by Allie
Since everything looks at its default state, have you checked this part just for confirmation
既然一切都看它的默认状态,你是否检查过这部分只是为了确认
cat /etc/php.ini | grep log_errors
cat /etc/php.ini | grep log_errors
If log_errors is disabled then enable it and check this below log after restarting httpd.
/var/log/httpd/error_log
如果 log_errors 被禁用,则启用它并在重新启动 httpd 后检查以下日志。
/var/log/httpd/error_log
--
Also check this part from php configuration. cat /etc/php.ini | grep error_reporting
-- 也从php配置检查这部分。 cat /etc/php.ini | grep error_reporting
This value should be enabled by default so that display_errors will work. error_reporting = E_ALL
默认情况下应启用此值,以便 display_errors 起作用。 error_reporting = E_ALL

