Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is my phptest.php file:

  echo "Hello";

But when I try 'http://serveraddress/phptest.php'on my browser,it does not work properly and shows the whole php file on my browser.

I am using CentOS 5 and PHP version is 5.2.5. When a type 'php phptest.php' on the terminal, it works properly.

Please help

share|improve this question
What web server are you using, Apache? Ensure the PHP module for your web server is enabled. – xeon Jul 8 '11 at 19:41
up vote 2 down vote accepted

From a console run:

php -v

That should return the version of PHP if you have it installed. If you do have it installed, did you setup your web server properly to recognize PHP files? For example, you would need to add the following to your apache config file:

AddType application/x-httpd-php .php
share|improve this answer
I added AddType application/x-httpd-php .php But now when I try to run from the browser, it asks me to download the file. I am using Firefox 4.0 – Poojan Jul 8 '11 at 20:08
What was the result from running 'php -v' on the command line? – Brendan Jul 8 '11 at 20:18
php -v gave PHP 5.2.5 (cli) (built: Nov 19 2008 15:18:12) Copyright (c) 1997-2007 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies – Poojan Jul 8 '11 at 20:28
If PHP is installed on your system, merely adding the second line of code to your Apache configuration file solves the situation. Thanks David for this tip. In CentOS 7, it was located under /etc/httpd/conf/ with the name httpd.conf. In that file, add that line of code inside the IfModule mime_module brackets. – Can Sürmeli Jul 11 '15 at 1:40

On redhat systems the apache configuration is by default held in one file /etc/httpd/conf/httpd.conf. All modules are loaded from this file, and can be disabled by commenting out the appropiate LoadModule statement.

LoadModule authz_default_module modules/
LoadModule ldap_module modules/
LoadModule authnz_ldap_module modules/
LoadModule include_module modules/
LoadModule log_config_module modules/
LoadModule logio_module modules/
LoadModule env_module modules/
LoadModule mime_module modules/
LoadModule dav_module modules/

Check if your module isn't commented, restart apache.

share|improve this answer
On a CentOS 5 box? – womble Jul 8 '11 at 22:56
I need to read more, edited the answer – Lucas Kauffman Jul 8 '11 at 23:22
You would have been better off leaving your Debian answer (after making it explicit it was Debian-specific) and then adding a second, CentOS-specific answer. – womble Jul 8 '11 at 23:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.