PHP not working with Apache on Centos 7

73,069

Solution 1

It seems your php module for apache is not working. It's may be not properly installed or configured.

To see all available modules, you can run:

apachectl -M

You can enable the module by adding the following line either in httpd.conf or your vhost config file:

LoadModule php5_module        modules/libphp5.so

Solution 2

Every time I have this problem, it is because I did something like:

# yum install httpd php-mysql
# yum install php-fpm
# systemctl start httpd

Finally I remember that this is not a dependency and get it working:

# yum install php
# apachectl -M | grep -i php
 php5_module (shared)

# systemctl enable httpd
# systemctl restart httpd

At this point I can use php in httpd without external repos or mod_php package listed in "rpm -qa"

Share:
73,069

Related videos on Youtube

llanato
Author by

llanato

Been working with PHP/SQL for over 10 years now and feel it's time to give back to the community as if it wasn't for stackoverflow and other sites I would have never gotten to grips with a lot of syntax all those years ago as well as Java, Python & MongoDB to name but a few. SOreadytohelp

Updated on September 18, 2022

Comments

  • llanato
    llanato almost 2 years

    I'm on centos 7 and have the httpd service (2.4.6) installed from yum no problems and I had to install PHP from a different repo remi to get php 5.6 installed.

    PHP works on the command line and the httpd service is running but all php is not being executed, there are no errors in any logs, and the below php.conf exists.

    AddHandler php5-script .php
    AddType text/html .php
    
    <IfModule  mod_php5.c>
        <FilesMatch \.php$>
            SetHandler application/x-httpd-php
        </FilesMatch>
    </IfModule>
    

    I've been at this hours now going around in circles and just can't seem to see where the disconnect between apache and php is, any help greatly appreciated.

    • Froggiz
      Froggiz over 8 years
      What happend when you try to display a php page, php source is displayed ?
    • llanato
      llanato over 8 years
      @Froggiz, PHP code is displayed plain-text.
    • Diamond
      Diamond over 8 years
      @llanato, create test.php with the following code <?php phpinfo(); ?> and put it in your Apache document root or anywahere that you can execute from a browser. Then see what happens when you go to page hostname_or_ip/test.php. This is a test to see if php is working with apache.
    • llanato
      llanato over 8 years
      @bangal, as I already said, php isn't working with apache at all, it's only working on the command line and all php code is displayed as plain-text.
    • Diamond
      Diamond over 8 years
      @llanato, what does your /var/log/httpd/error_log says when you try to execute a php page?
    • llanato
      llanato over 8 years
      @bangal, there are no errors in any logs and no errors on screen
    • Diamond
      Diamond over 8 years
      @llanato, can you make sure the php module for apache is installed and loaded? Try adding LoadModule php5_module modules/libphp5.so just before SetHandler... line.
  • Michael Hampton
    Michael Hampton almost 4 years
    Why do you say without mod_php package? You installed mod_php and you are using it!