PHP Showing Source Code Instead Rendering Page Fix

Sometimes happen that we didn’t configured apache and httpd.conf properly or we didn’t change permissions and PHP doesn’t render pages and instead show in browser plain text of source code.

In most cases that happens because of :

  1. PHP is not properly installed or service is not started
  2. .php extension isn’t added in httpd.conf configuration file
  3. PHP must have execute permissions to execute our script or file [permissions 755]

Making sure PHP is installed

Make sure PHP service is installed and started.

Login to VPS via SSH using Putty and login with root and your password.

To install PHP use command on CentOS use:

yum install httpd

or try

apt-get install apache2

if you are using Debian or Ubuntu Linux operating system.

It might you ask do you want to download it, just type “y” and press enter.

Then start that service and to do that write this line if you are using CentOS:

yum httpd start

or for Debian write:

/etc/init.d/apache2 start

Add PHP extension in httpd.conf

Navigate to /etc/httpd/conf/httpd.conf

You can do that using SSH or if you are using Webmin under Servers click Apache Webserver > Global Configuration > Edit Config Files

and find this line of code:

DirectoryIndex index.html

And change it to:

DirectoryIndex index.php

Allow execute permissions

You have to allow PHP to execute script. To do that, using FTP navigate to folder where is your index.php located, usually in public_html or if you are using Webmin location is : /var/www/html

Right click on index.php and set 755 permission or simply mark boxes (if you are using FTP manager) with Execute attribute.

Don’t forget to restart apache using control panel or using command:

yum restart httpd

Leave a comment