PHP on centos 6 not working

26,417

Solution 1

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.

Solution 2

yum install mod_php -y
systemctl restart httpd.service
Share:
26,417

Related videos on Youtube

MikeH
Author by

MikeH

Updated on September 18, 2022

Comments

  • MikeH
    MikeH over 1 year

    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?

    • Admin
      Admin almost 10 years
      Is SELinux enable?
    • Admin
      Admin almost 10 years
      if it is enable should i disable it? and if so does it effects on the security?
    • Admin
      Admin almost 10 years
      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.
    • Admin
      Admin almost 10 years
      Thankyou, i am currently reeading documentation from here wiki.centos.org/HowTos/SELinux
  • MikeH
    MikeH almost 10 years
    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
  • cuonglm
    cuonglm almost 10 years
    @rakibtg: No, you should check that those lines is in your apache config and are not commented.
  • MikeH
    MikeH almost 10 years
    Ops! i think i have nothing like LoadModule php... in my httpd.conf file , any idea?
  • cuonglm
    cuonglm almost 10 years
    @rakibtg: Do you have any php.conf file in /etc/httpd/conf.d?
  • MikeH
    MikeH almost 10 years
    I think no there isn't any file like php.conf ! i.stack.imgur.com/Lv7v1.png What i should do now? Thanks for your time :)
  • cuonglm
    cuonglm almost 10 years
    Oh, You should install mod_php.
  • MikeH
    MikeH almost 10 years
    How i can install mod_php, because i have already installed apache?
  • cuonglm
    cuonglm almost 10 years
    Maybe yum --enablerepo=centosplus install mod_php
  • Gravy
    Gravy over 8 years
    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.
  • Jack
    Jack almost 8 years
    Thanks worked, can I specify the php version?
  • GTS Joe
    GTS Joe over 7 years
    This worked for me after I restarted Apache. Thanks! =)