Possible Problems With Rendering PHP with Apache

Problem scenario
Your PHP code is being displayed in a raw fashion.  It is not being rendered or presented nicely as it should.  You see raw PHP text when you open a web browser and go to the .php page.  What should you do?

Solution
If the PHP page is blank (or completely white), see this posting.

Is your PHP program using Linux Bash commands? If so, see this posting.

If a PHP page is retrievable from a web browser, but shows only text and the actual source code in PHP, Apache is at least somewhat working.  What is the root cause?  One potential root cause is that PHP has not been installed.  If you are running Ubuntu Linux, run this command to remedy two potential root causes:  sudo apt-get -y install php7.0 libapache2-mod-php

Another root cause of this problem may be that Apache web server has not been configured correctly.  Find the httpd.conf file (e.g., if you are not running Ubuntu, because with Ubuntu there will be an apache2.conf file instead).  You may want to consult with this external posting.  Otherwise find the "AddType" section of the httpd.conf file.  Ensure that this line is present:  AddType application/x-httpd-php .php

The second stanza to look for is the LoadModule one.  In the LoadModule section of the httpd.conf file, ensure that a line like this is present (assuming you are using PHP5):
LoadModule php5_module modules/libphp5.so

You may need to replace "modules" above with the absolute path to the libphp5.so file.  The libphp5.so file may not be present after a Drupal installation and configuration.  Proper Drupal* installations use the ./configure script with a flag like this: --with-apxs2=<pathToAPXS>
The value <pathToAPXS> should be the results of this command: which apxs
If the results of this which apxs command are nothing, try one of these commands:
    -If you are using a RedHat derivative OS): # echo "extension=apc.so" > /etc/php.d/apc.ini
    -If you are using a Debian distribution: # echo "extension=apc.so" > /etc/php5/conf.d/apc.ini

The flag would be --with-apxs (with no "2") if the Apache version is older. 

*Drupal is a content management system. To find out how it is pronounced, go here.

Leave a comment

Your email address will not be published. Required fields are marked *