Mod_PHP Not Installed on CentOS 7 with Remi’s PHP 5.4 – Solution

centos7httpdmod-phpPHP

I have a fresh installation on CentOS 7 with httpd and following remi's wizard I installed php 5.4 as single version (I know it's old, but part of my requirements !!).
My problem is that httpd cannot run php scripts (simple like phpinfo) just as described in this question: PHP not working with Apache on Centos 7
Apart from that problem, things that I find very very strange are:

  • there is no php module in httpd:

httpd -M | grep php shows nothing!! There should be php5_module, or not ??

  • there is no php.conf file in httpd:
[user@pc ~]]$ ls -l /etc/httpd/conf.d/
total 16
-rw-r--r--. 1 root root 2926 Apr  2 16:13 autoindex.conf
-rw-r--r--. 1 root root  366 Apr  2 16:14 README
-rw-r--r--. 1 root root 1252 Nov 27 17:58 userdir.conf
-rw-r--r--. 1 root root  824 Nov 27 17:58 welcome.conf
  • but the same time, php is installed as described (remi-wizard):
[user@pc ~]$ php --version
PHP 5.4.45 (cli) (built: Oct 22 2019 13:26:02)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
  • php packages are there (only those I installed obviously) :
[user@pc ~]$ rpm -qa 'php*' | sort
php-cli-5.4.45-18.el7.remi.x86_64
php-common-5.4.45-18.el7.remi.x86_64

Similar question I found here and the provided solution is installation of mod_php. Sounds right… but here comes my other question:
when attempting yum install mod_php the system prompts me for php installation (though I have it installed) !!

sudo yum install mod_php
...
--> Running transaction check
---> Package php.x86_64 0:5.4.45-18.el7.remi will be installed
--> Finished Dependency Resolution

(it's the same with)

sudo yum install php
...
--> Running transaction check
---> Package php.x86_64 0:5.4.45-18.el7.remi will be installed
--> Finished Dependency Resolution

Am I doing something wrong here or missing something ??

Best Answer

You have php-cli and php-common packages installed. That means you've installed only cli version. Cli (console) version is the one you run with php command from shell. Those packages don't provide apache module that's why you don't see it.

While sudo yum install php (or outdated mod_php, which is now an alias only) offers you to install php package, which does includes shared apache module & config.

So your assumption "(though I have it installed) " is not quite correct. Just do sudo yum install php and accept all packages it wants to install and you'll be fine.