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?

  • 1
    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 9 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.

  • 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
  • 2
    @rakibtg: No, you should check that those lines is in your apache config and are not commented. – cuonglm May 15 '14 at 7:16
  • 1
    @rakibtg: Do you have any php.conf file in /etc/httpd/conf.d? – cuonglm May 15 '14 at 7:44
  • 1
    Oh, You should install mod_php. – cuonglm May 15 '14 at 7:59
  • 2
    Maybe yum --enablerepo=centosplus install mod_php – cuonglm May 15 '14 at 8:09
yum install mod_php -y
systemctl restart httpd.service
  • 1
    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 '16 at 11:30
  • Thanks worked, can I specify the php version? – Jack Nicholson Jul 16 '16 at 15:12

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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