3

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.

llanato
  • 211
  • 2
  • 4
  • 12
  • What happend when you try to display a php page, php source is displayed ? – Froggiz Nov 23 '15 at 20:52
  • @Froggiz, PHP code is displayed plain-text. – llanato Nov 23 '15 at 20:57
  • @llanato, create test.php with the following code `` 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 http://hostname_or_ip/test.php. This is a test to see if php is working with apache. – Diamond Nov 23 '15 at 21:32
  • @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. – llanato Nov 23 '15 at 21:36
  • @llanato, what does your `/var/log/httpd/error_log` says when you try to execute a php page? – Diamond Nov 23 '15 at 21:41
  • @bangal, there are no errors in any logs and no errors on screen – llanato Nov 23 '15 at 21:44
  • @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. – Diamond Nov 23 '15 at 21:47
  • What is the list of RPM installed ? (rpm -qa php\*) as it seems "mod_php" is not installed. – Remi Collet Nov 25 '15 at 08:37

3 Answers3

6

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
Diamond
  • 9,001
  • 3
  • 24
  • 38
5

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"

noname
  • 51
  • 1
  • 1
0

I figured out my problem that mod_php is not default installed after I install PHP and httpd, now it works with this command:

yum install mod_php
systemctl restart httpd