简体   繁体   English

获取Apache的空白PHP页面

[英]Getting blank PHP page over Apache

In a newly setup digitalOcean cloud server (CentOS), I have installed php and Apache. 在新设置的digitalOcean云服务器(CentOS)中,我安装了php和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. 但是如果我尝试访问任何php页面,浏览器会显示空白页面(白页)。

Here is what I have done so far to troubleshoot: 以下是我到目前为止所做的排除故障的方法:

  1. Created a page with following content: <?php phpinfo(); ?> 创建了一个包含以下内容的页面: <?php phpinfo(); ?> <?php phpinfo(); ?> . <?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. 为了确保,apache指向正确的目录,在那里放置了一个静态.html页面,并且在浏览器中看到它很好,所以apache正在工作,目录是正确的。
  3. In /etc/php.ini , changed display_errors directive to On . /etc/php.ini ,将display_errors指令更改为On Still blank page 还是空白页面
  4. In Apache config file ( /etc/httpd/conf/httpd.conf ) found this line Include conf.d/*.conf . 在Apache配置文件( /etc/httpd/conf/httpd.conf )中发现此行Include conf.d/*.conf Inside conf.d directory, there is a php.conf file containing the line: LoadModule php5_module modules/libphp5.so . conf.d目录下,有一个包含以下行的php.conf文件: LoadModule php5_module modules/libphp5.so Ensured that this .so file actually exists in this place. 确保此.so文件实际存在于此处。
  5. In the same file I have these two lines as well: AddHandler php5-script .php and AddType text/html .php 在同一个文件中我也有这两行: AddHandler php5-script .phpAddType text/html .php
  6. Executed the php page from CLI, it works fine - so php is working locally. 从CLI执行php页面,它工作正常 - 所以php在本地工作。

Then why is it always shows a blank/white page over the browser? 那为什么它总是在浏览器上显示空白/白页? What else am I missing? 我还缺少什么?

EDIT Based on suggestions from @Nathan, 编辑根据@Nathan的建议,

  1. I checked Apache error log file, could not see any error being reported there. 我检查了Apache错误日志文件,看不到任何报告错误。
  2. My /etc/php.ini says, php error_log is located as syslog . 我的/etc/php.ini说,php error_log位于syslog So I checked /var/log/messages but could not find any PHP error message 所以我检查了/var/log/messages但找不到任何PHP错误消息
  3. Next I put some normal HTML in the php file containing phpinfo() call. 接下来,我将一些普通的HTML放在包含phpinfo()调用的php文件中。 Interestingly I found that even the normal HTML texts are also not coming. 有趣的是,我发现即使是普通的HTML文本也不会出现。 It still produces blank page. 仍然产生空白页面。
  4. Then I checked Apache access log. 然后我检查了Apache access日志。 Surprise! 惊喜! There is no GET request for any of the PHP files I tried to load in the browser. 我试图在浏览器中加载的任何PHP文件都没有GET请求。 But GET request for all the non-php files are there with 200 return code. GET请求所有非PHP文件都有200返回代码。

Apache is not even logging any access request for PHP files. Apache甚至没有记录任何PHP文件的访问请求。 Any idea why would that happen? 知道为什么会这样吗?

check out your phpinfo() script. 看看你的phpinfo()脚本。

<?php
phpinfo();
?>

missing the "php" behind the first "?" 错过了第一个“?”背后的“php” will give a blank page 会给出一个空白页面

I think your php installation with apache is faulty. 我认为你的apache安装错误。 Thats why you can not see any php page in your webserver. 这就是为什么你在网络服务器上看不到任何php页面的原因。 Clean remove all the existing apps, like httpd,php,php-fpm,php-cli etc. and try to clean isntall in this order 清除删除所有现有的应用程序,如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: 重启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”之后进行搜索并确保将其设置为“off”然后保存文件。

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

Are you navigating to the php file directly? 您是否直接导航到php文件? Or are you just going to the directory root? 或者你只是去目录根目录?

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

I have the same issue... The problem is in the iptables. 我有同样的问题......问题在于iptables。 ( It seems like it ) 看起来像

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. [ edit ]重新启动iptables服务对我有用。

Try: 尝试:

service iptables restart

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. 如果您不向公众授予读取权限,Apache会生成一个空白页面而不显示任何错误。

Since everything looks at its default state, have you checked this part just for confirmation 由于所有内容都处于默认状态,因此您只需检查此部分以进行确认

cat /etc/php.ini | grep log_errors

If log_errors is disabled then enable it and check this below log after restarting httpd. 如果禁用了log_errors,则启用它并在重新启动httpd后检查以下日志。 /var/log/httpd/error_log

-- Also check this part from php configuration. - 还要从php配置中检查这部分。
cat /etc/php.ini | grep error_reporting

This value should be enabled by default so that display_errors will work. 默认情况下应启用此值,以便display_errors可用。
error_reporting = E_ALL

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. 在仔细检查了php.ini或我的apache conf文件并且仍然没有收到任何输出之后,我后来发现我正在使用@嵌套在构造函数中来抑制包含/包含类的错误。 There was a syntax error in the included file, which stopped all output altogether when errors were thrown. 包含文件中存在语法错误,在抛出错误时会完全停止所有输出。

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. 如果您首先将所有输出存储到vars中,并且首先包含各种脚本,那么您将不得不看到这些错误。 If you suppress file handler errors, you'll get a blank screen if you have a syntax error in the file. 如果您禁止文件处理程序错误,如果文件中存在语法错误,则会出现空白屏幕。

Search your files for all instances of @ in your php code. 在您的PHP代码中搜索文件中的所有@实例。 Then turn @include "/path_to/script.php"; 然后转@include "/path_to/script.php"; to include "/path_to/script.php"; include "/path_to/script.php"; or anything @$foo into $foo as 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. @$foo$foo因为这样的var可能会引用一个依赖项,导致脚本以httpd错误日志或http响应中没有显示任何内容而结束。

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. 我使用的FPM用户没有必要的权限来执行web根目录中的index.php文件。

To avoid these issues in the future, I have created an automated bash script that will automatically create and configure webservers in DigitalOcean boxes. 为了避免将来出现这些问题,我创建了一个自动bash脚本,可以在DigitalOcean框中自动创建和配置Web服务器。 Please take a look here https://github.com/akash-mitra/fairy 请看这里https://github.com/akash-mitra/fairy

This script will automatically, 这个脚本会自动,

  • Installs Nginx 安装Nginx
  • Create virtual server block for nginx 为nginx创建虚拟服务器块
  • Installs PHP, PHP APC, PHP Curl etc. 安装PHP,PHP APC,PHP Curl等。
  • Supports PHP Fast Process Manager (php-fpm) 支持PHP快速流程管理器(php-fpm)
  • Installs Memcached 安装Memcached
  • Installs Database (MariaDB / MySQL) 安装数据库(MariaDB / MySQL)
  • Optionally Installs PHP Composer and Laravel (可选)安装PHP Composer和Laravel
  • Configures and Strengthens SSH 配置和加强S​​SH
  • Activates Firewall 激活防火墙
  • Optionally enables SWAP space in DO server and fixes a locale issue (可选)在DO服务器中启用SWAP空间并修复区域设置问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM