Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

I have installed PHP, MySQL, Apache on CentOS 6, now I have restarted the Apache and mysql, to test PHP I have created a index.php on /var/www/html/test/ now once I go to localhost/test/index.php then it shows only PHP source code like this: enter image description here

From Gnouc comment, I understand that it is due to SELinux security layer.
To work with HTML directory i did this in my terminal, but still i have the same result:

[root@localhost www]# chcon -v --type=httpd_sys_content_t html
changing security context of `html`

Any idea?

share|improve this question
Is SELinux enable? – cuonglm May 15 '14 at 5:29
if it is enable should i disable it? and if so does it effects on the security? – rakibtg May 15 '14 at 5:51
If SELinux is enable, you should check if it allow cgi script to execute and make sure ownership of php file, and allow it executable. – cuonglm May 15 '14 at 5:53
Thankyou, i am currently reeading documentation from here wiki.centos.org/HowTos/SELinux – rakibtg May 15 '14 at 5:57
up vote 7 down vote accepted

If your SELinux config is ok, it seems that this error occured because server configuration.

If you have installed php, then make sure that it is loaded by apache and apache is associated with php handler.

LoadModule php5_module        modules/libphp5.so
AddType application/x-httpd-php .php

And you should check your .htaccess. It may have some configurations that overrided apache's config.

share|improve this answer
Don't mind, i'm really new to linux, i run those commands but it shows error: bash: LoadModule: command not found bash: LoadModule: command not found Thanks – rakibtg May 15 '14 at 7:14
@rakibtg: No, you should check that those lines is in your apache config and are not commented. – cuonglm May 15 '14 at 7:16
@rakibtg: Do you have any php.conf file in /etc/httpd/conf.d? – cuonglm May 15 '14 at 7:44
Oh, You should install mod_php. – cuonglm May 15 '14 at 7:59
Maybe yum --enablerepo=centosplus install mod_php – cuonglm May 15 '14 at 8:09
yum install mod_php -y
systemctl restart httpd.service
share|improve this answer
Please note that on a CentOS 6 machine, systemctl restart httpd.service will return a "command not found." service httpd restart would be the correct means of restarting the httpd service. – Gravy Oct 15 '15 at 16:45
worked for me, thanks – Prakash Apr 13 at 11:30
Thanks worked, can I specify the php version? – Jack Nicholson Jul 16 at 15:12

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.