No php module loaded in Apache

Issues related to applications and software problems and general support
Post Reply
user58
Posts: 14
Joined: 2022/01/27 22:16:39

No php module loaded in Apache

Post by user58 » 2022/01/27 23:30:25

Hello everyone, this is my very first post here, thanks for this forum :)

My problem seems very similar to other ones around PHP installation one can find on the www but I tried dozens of solutions, none worked at the end.

A few days ago, I installed CentOS 8 (for the first time) on a Xeon server... I never encountered problems with CentOS 6 but now I'm stuck with this CentOS 8. The short version is : PHP is installed, enabled, works but does not read .php files as php (does it as html)

Here is what I did, step by step :

Installed Apache : sudo dnf install httpd
Installed Firewalld : sudo dnf install firewalld
sudo systemctl enable firewalld
sudo systemctl start firewalld
Checked Firewalld : sudo firewall-cmd --state
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --zone=public --add-port=80/tcp --permanent
sudo firewall-cmd --add-port=10000/tcp --zone=public --permanent
sudo firewall-cmd --zone=public --add-port=443/tcp --permanent
sudo firewall-cmd --reload

Installed Apache mod_ssl : sudo dnf install httpd mod_ssl

Started web server : sudo systemctl start httpd
sudo systemctl status httpd
Installed MySql : sudo dnf install mysql-server
sudo systemctl start mysqld.service
sudo systemctl status mysqld

sudo systemctl enable mysqld
sudo systemctl enable httpd
sudo mysql_secure_installation

Installed wget : sudo yum search wget
sudo yum install wget

Installed Webmin :
wget http://prdownloads.sourceforge.net/weba ... noarch.rpm
sudo dnf install perl perl-Net-SSLeay openssl perl-Encode-Detect
sudo rpm -Uvh webmin-1.984-1.noarch.rpm

sudo systemctl enable webmin

At this point, I tried to access Webmin via ipaddress:80 , and it did not work, I did not notice that the previous command gave the (strange) address to use... So I did :

sudo iptables -I INPUT 1 -p tcp --dport 10000 -j ACCEPT
sudo service iptables save
sudo /etc/init.d/webmin restart
sudo firewall-cmd --reload

Installed Vim : sudo dnf search vim
sudo dnf install vim-enhanced
alias vi='vim'

Configured Webmin : sudo /etc/webmin/miniserv.conf

At this point, I uninstalled Webmin & reinstalled it, found the right address to use...

I created Virtual Hosts

Then did : yum install epel-release

Installed Snapd : sudo dnf install snapd

sudo systemctl enable snapd.socket --now

Installed Certbot (SSL) : sudo snap install core; sudo snap refresh core
sudo dnf remove certbot
sudo yum remove certbot
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
sudo certbot --apache

Winter is coming : sudo yum module list php (php 7.2, 7.3, 7.4 installed but I did not even try to read a .php file)

I had to try to install PHP 5.6 for an old website

sudo yum install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
sudo yum --enablerepo=remi install php56
sudo yum module list php (php 5.6 does not appear)
sudo yum search php (php 5.6 appears...)
sudo find / -name php.ini

I needed a recent version of PHP as well :

sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm -y
sudo dnf module enable php:remi-7.4

Php did not start... sudo systemctl restart httpd.service does not help...

Installed PHP 8.1 :

sudo yum --enablerepo=remi install php81

Tried with dnf :

sudo dnf install -y https://dl.fedoraproject.org/pub/epel/e ... noarch.rpm

sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm

sudo dnf module list php
sudo dnf module enable php:remi-8.0 -y

sudo yum install php-cli
php -v (php now works in command line but does not read .php files)

Tried to edit /etc/httpd/conf.d/php81-php.conf

php -r 'echo "Hello World!n";' (ok)

apachectl -M (no php module there)

yum install php
apachectl -M | grep -i php

Got "Could not reliably determine the server's fully qualified domain name, using nsxxxxxx.ip-xx-xx-xx.eu. Set the 'ServerName' directive globally to suppress this message" , so I changed ServerName in httpd.conf, uncommented the line. No more error message

I tried to uninstall php : yum remove php , yum install php ... now there is /etc/httpd/conf.d/php.conf

sudo systemctl enable php-fpm
sudo systemctl start php-fpm

sudo yum module list php
sudo yum module reset php
sudo yum module enable php:remi-8.1
sudo systemctl reload httpd

yum list installed | grep php (I can see php 5.6 & 8.1)

yum -y remove php* (removed all versions)

And again : sudo yum --enablerepo=remi install php81
sudo yum install php-cli
php -v (php 8.1)

Restarted Apache, now I get 503 Service Unavailable when reading .php files... I did not find any working solution on the www.

yum -y remove php*
yum install php (php 8.1, restart Apache, still 503)

sudo dnf module list php (php 8.1 enabled)
sudo dnf module reset php (no more php enabled)
sudo dnf module enable php:7.2 (php 7.2 enabled but php -v gives 8.1)

Reinstalled Apache : sudo dnf remove httpd
sudo dnf install httpd
sudo dnf install httpd mod_ssl
sudo systemctl enable httpd
sudo dnf module reset php
sudo dnf module install php:remi-8.1

Recreated Virtual Hosts, certbot again : sudo certbot --apache

sudo systemctl start httpd
sudo dnf module list php gives :

Last metadata expiration check: 2:04:29 ago on Thu 27 Jan 2022 09:00:13 PM UTC.
CentOS Linux 8 - AppStream
Name Stream Profiles Summary
php 7.2 [d] common [d], devel, minimal PHP scripting language
php 7.3 common [d], devel, minimal PHP scripting language
php 7.4 common [d], devel, minimal PHP scripting language

Remi's Modular repository for Enterprise Linux 8 - x86_64
Name Stream Profiles Summary
php remi-7.2 common [d], devel, minimal PHP scripting language
php remi-7.3 common [d], devel, minimal PHP scripting language
php remi-7.4 common [d], devel, minimal PHP scripting language
php remi-8.0 common [d], devel, minimal PHP scripting language
php remi-8.1 [e] common [d] [ i], devel, minimal PHP scripting language

Hint: [d]efault, [e]nabled, [x]disabled, [ i]nstalled


Now php 8.1 is enabled & installed... but still does not read .php files (readed as html)

apachectl -M (or) apachectl -M | grep -i php (no module php)

sudo journalctl -xe

sudo vi /etc/httpd/conf.modules.d/00-base.conf (via Webmin)
LoadModule rewrite_module modules/mod_rewrite.so (is ok)

sudo dnf install php php-cli php-common

At this point I tried to change the files rights, owner & place (/home/website or /var/www/)

I tried all solutions I found... I am really stuck... What did I miss ? Any idea?

Many thanks in advance... Cheers!

User avatar
TrevorH
Site Admin
Posts: 33215
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: No php module loaded in Apache

Post by TrevorH » 2022/01/28 11:16:03

A few days ago, I installed CentOS 8
Wrong choice, it went EOL at the end of 2021 and there will be no more updates.
sudo iptables -I INPUT 1 -p tcp --dport 10000 -j ACCEPT
You cannot use iptables commands to add rules if you use firewalld. It will remove the rules you add. You need to use firewall-cmd to add the rule you want.

After you install php you must restart httpd (not reload).
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

User avatar
remirepo
Posts: 447
Joined: 2014/09/21 09:07:12
Location: France
Contact:

Re: No php module loaded in Apache

Post by remirepo » 2022/01/28 13:33:42

> No php module loaded in Apache

CentOS 8 (Stream) use php-fpm by default (mod_php is still available, but not recommended, imply to switch back to the old prefork mode)
CentOS 9 Stream use php-fpm by default (mod_php is no more available)

So if php-fpm is installed, and the service started, php scripts should work out of the box (with httpd or nginx)


P.S. if you want proper configuration when using "remi" repository, follow the wizard instructions, but this is usually only needed if you want a version not available (C8S have 7.4 and 8.0, C9S have 8.0), multiple versions, of additional extensions.
Remi's Repository - Forum - Blog

user58
Posts: 14
Joined: 2022/01/27 22:16:39

Re: No php module loaded in Apache

Post by user58 » 2022/01/29 00:20:37

Thanks for your answers...

First of all, yes I am conscious that CentOS 8 was not a choice so good, but CentOS Stream was not available and I didn't want to experiment other systems I don't know at all... Not possible to upgrade to Stream? Well, let's try anyway.

Ok so of course I restarted httpd so many times without any effect

php-fpm seems installed but no change...

sudo systemctl status php-fpm

● php-fpm.service - The PHP FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor pre>
Active: active (running) since Fri 2022-01-28 22:40:36 UTC; 1h 14min ago
Main PID: 130390 (php-fpm)
Status: "Processes active: 0, idle: 5, Requests: 4, slow: 0, Traffic: 0req/s>
Tasks: 6 (limit: 409610)
Memory: 37.4M
CGroup: /system.slice/php-fpm.service
├─130390 php-fpm: master process (/etc/php-fpm.conf)
├─130393 php-fpm: pool www
├─130394 php-fpm: pool www
├─130395 php-fpm: pool www
├─130396 php-fpm: pool www
└─130397 php-fpm: pool www

... but no, php scripts are not computed, read as html.

I just followed the wizard instructions (as root) then restarted httpd

dnf install php81 (or) dnf --enablerepo=remi-test install php81
php81 --version
php81 --modules
sudo systemctl restart httpd

No change, php scripts are not computed, read as html... really stuck here :/

I also tried to install phpMyAdmin, and for http://myip/phpMyAdmin I get a 403 Forbidden.

User avatar
remirepo
Posts: 447
Joined: 2014/09/21 09:07:12
Location: France
Contact:

Re: No php module loaded in Apache

Post by remirepo » 2022/01/29 10:23:20

> I also tried to install phpMyAdmin, and for http://myip/phpMyAdmin I get a 403 Forbidden.

Using the RPM of phpMyAdmin this is expected for obvious security reasons.
See /etc/httpd/conf.d/phpMyAdmin.conf

Code: Select all

# Allows only localhost by default
#
# But allowing phpMyAdmin to anyone other than localhost should be considered
# dangerous unless properly secured by SSL
...
   Require local
...
Remi's Repository - Forum - Blog

user58
Posts: 14
Joined: 2022/01/27 22:16:39

Re: No php module loaded in Apache

Post by user58 » 2022/01/29 14:21:27

I feel so stupid... I'm so used to PHP short tags that I did not consider to use <?php before and concentrated on seeing this php module listed in Apache ... but it works then (even if I don't see php module)

So I've only to find where to make the change for short tags.

About phpMyAdmin, of course I meant https://myip/phpMyAdmin (still 403 but I'll try some changes soon)

Also, do you think it would be possible to install php 5.6 in parallele of php 8.1 ? How to use both in Apache and choose according to pages? php tags maybe ? Or is it definitely only possible to choose for each VirtualHost ?

Thanks so much...

User avatar
TrevorH
Site Admin
Posts: 33215
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: No php module loaded in Apache

Post by TrevorH » 2022/01/29 14:34:23

The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

User avatar
remirepo
Posts: 447
Joined: 2014/09/21 09:07:12
Location: France
Contact:

Re: No php module loaded in Apache

Post by remirepo » 2022/01/30 05:43:53

> Or is it definitely only possible to choose for each VirtualHost ?

The SetHandler directive (to choose a PHP backend or version) can be set per vhost or directory
See https://httpd.apache.org/docs/2.4/en/mo ... sethandler
Remi's Repository - Forum - Blog

user58
Posts: 14
Joined: 2022/01/27 22:16:39

Re: No php module loaded in Apache

Post by user58 » 2022/02/01 23:43:34

Many thanks. I guess this topic is closed, I'll open a new one about phpMyAdmin (still Forbidden)...

docabilly
Posts: 1
Joined: 2022/04/06 00:54:23

Re: No php module loaded in Apache

Post by docabilly » 2022/04/06 00:56:57

Oh thank you original poster. My experience was almost the same. Pain.

my setup was rocky linux 8 and remi's php 8.1.4

to get apache to process my php files I had to put this in /etc/httpd/conf/httpd.conf

<FilesMatch \.php$>
SetHandler "proxy:unix:/run/php-fpm/www.sock|fcgi://php81scl"
</FilesMatch>

This took days to find/guess

Post Reply