2

Trying to setup an Apache VirtualHosting environment with PHP in a freshly created CentOS node under DigitalOcean cloud server.

The trouble is, although Virtual hosting is working per se, PHP isn't.

Server Setup:

  • Web Server : CentOS 6.5 with Apache/2.2.15
  • PHP Version: 5.3.3 (To be used as an Apache Module)

Steps Taken:

Logging in as the root user,

  • Installing Apache and php : yum -y install httpd php
  • Creating a new virtual host configuration file like below:

File: /etc/httpd/conf.d/vhosts.conf

NameVirtualHost *:80 <VirtualHost *:80> ServerAdmin [email protected] ServerName example.org ServerAlias www.example.org DocumentRoot /srv/www/example.org/public_html/ ErrorLog /srv/www/example.org/logs/error.log CustomLog /srv/www/example.org/logs/access.log combined </VirtualHost> 
  • Creating new directories for the virtual host site

Like below,

mkdir -p /srv/www/example.org/public_html mkdir -p /srv/www/example.org/logs 
  • Placing a .php and .html test files like below:

Files under /srv/www/example.org/public_html/ (DocumentRoot)

echo "<HTML>It work's</HTML>" > /srv/www/example.org/public_html/index.html echo "<?php echo ("It works"); ?>" > /srv/www/example.org/public_html/index.php 

Next, when I point my browser to index.html, it works. But when I point my browser to index.php I get a blank page.

Troubleshooting

(Things that I already did/checked without any luck)

  • Ensured Apache is running and DocumentRoot is accessible
  • All the directories are 755 and files 644
  • Checked Apache access log. The html page requests are there with 200 status code, but no .php page request present in access log
  • No error in Apache or PHP error log, no error in /var/log/messages
  • Tried adding php_admin_flag engine on in vhost config file

Also see below the contents of /etc/httpd/conf.d/php.conf

<IfModule prefork.c> LoadModule php5_module modules/libphp5.so </IfModule> <IfModule worker.c> LoadModule php5_module modules/libphp5-zts.so </IfModule> AddHandler php5-script .php AddType text/html .php DirectoryIndex index.php 
6
  • Could you show us the contents of index.php (rather than the command you used to create it)? Testing this on the command line using curl --include http://www.example.org/index.php might give you a more useful error message. Commented Jan 14, 2014 at 7:32
  • @Ladadadada When I try the above curl command from my local machine, it returns curl: (52) Empty reply from server Commented Jan 14, 2014 at 7:46
  • try to use php -v and give us the result of php -i | grep "configure" Commented Jan 14, 2014 at 10:00
  • What was logged in Apache's error log? Commented Jan 14, 2014 at 15:25
  • @MichaelHampton Apparently Apache error log did not log any error on this. Also access log only shows access request to .html files, but not logging any access request to .php files Commented Jan 15, 2014 at 3:17

1 Answer 1

2

In my experience PHP renders a blank page when it encounters a serious underlying error. It is usually easy to fix, but unfortunately nothing is typically logged in the Apache logs, PHP logs, or syslog making the troubleshooting process difficult.

Find your php.ini configuration file using:

php -i | grep "php.ini" 

This should produce something like this:

Configuration File (php.ini) Path => /etc Loaded Configuration File => /etc/php.ini 

Edit this configuration file (/etc/php.ini in this case) with your favorite text editor and be sure that displaying errors and startup errors is turned on. The entries should look like this:

display_errors = On display_startup_errors = On 

Finally restart Apache so that it reads the new PHP configuration and access your page via curl or a browser. This should produce an error message that will help in the troubleshooting process.

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.