6

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?

4
  • 1
    Is SELinux enable?
    – cuonglm
    May 15, 2014 at 5:29
  • if it is enable should i disable it? and if so does it effects on the security?
    – rakibtg
    May 15, 2014 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, 2014 at 5:53
  • Thankyou, i am currently reeading documentation from here wiki.centos.org/HowTos/SELinux
    – rakibtg
    May 15, 2014 at 5:57

2 Answers 2

10

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.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .