Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting blank PHP page over Apache

Tags:

php

apache

centos

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?

like image 312
hashbrown Avatar asked Jan 13 '14 03:01

hashbrown


People also ask

Why is my PHP page showing blank?

Missing Code The most common reason for a blank page is that the script is missing a character. If you left out a ' or } or ; somewhere, your PHP won't work. You don't get an error; you just get a blank screen.

Does PHP require Apache?

No, it does not need to be Apache; you can also use other HTTP servers such as for example Nginx or Node.


3 Answers

check out your phpinfo() script.

<?php
phpinfo();
?>

missing the "php" behind the first "?" will give a blank page

like image 95
linuxmint17 Avatar answered Oct 12 '22 18:10

linuxmint17


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

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.

service httpd restart

Install 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

Open the fastcgi.conf file:

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.

The /usr/lib/cgi-bin/ directory must exist, so we create it:

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:

nano /etc/httpd/conf.d/php.conf

Comment out the AddHandler and AddType lines so it looks like here:

#
# 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:

service httpd restart
like image 37
DeSmOnd Avatar answered Oct 12 '22 19:10

DeSmOnd


Are you navigating to the php file directly? Or are you just going to the directory root?

If the later, Apache might not be recognizing .php as the directory index.

To test, try create a .htaccess file in your web root containing the following line:

DirectoryIndex index.php
like image 2
Aidan Avatar answered Oct 12 '22 18:10

Aidan