1 (edited by craigliu 2022-04-05 19:01:06)

Topic: How to set apache to use php81 in RHEL 7 or CentOS 7

Our RHEL 7.9 has remi PHP 7.4 (php-7.4.28-1.el7.remi.x86_64).
Now we have installed remi php 8.1 (php81-php-cli-8.1.4-1.el7.remi.x86_64). Is there a way in RHEL 7 so that I can switch between php-7.4.28-1.el7.remi.x86_64 and php81-8.1-1.el7.remi.x86_64 to use them in apache? We use mod_php, not use php-fpm.

We don't want to use both versions simultaneously. We just want to use only one version in one time, and another version in other time.

Thanks.

Re: How to set apache to use php81 in RHEL 7 or CentOS 7

> We don't want to use both versions simultaneously.

OK.

> php81-php-cli-8.1.4-1.el7.remi.x86_64

So, you don't need the php81-php-* packages designed for parallel installation of multiple versions

Follow the wizard instructions (link on every page of the blog / repo / forum)
and choose "default / single version"


Then you should have php-8.1.4-1.el7.remi.x86_64

Desktop: Fedora 35 + rpmfusion + remi-test + remi-dev
Laptop:  Fedora 36 + rpmfusion + remi (SCL only)
Hosting Server: CentOS 8 Stream with EPEL, rpmfusion, remi

Re: How to set apache to use php81 in RHEL 7 or CentOS 7

Notice: I recommend using "modern" PHP (8.x) on a "modern" distro, so at least EL-8

EL-7 is 8 years old and close to its end of life in 2024.

Desktop: Fedora 35 + rpmfusion + remi-test + remi-dev
Laptop:  Fedora 36 + rpmfusion + remi (SCL only)
Hosting Server: CentOS 8 Stream with EPEL, rpmfusion, remi

Re: How to set apache to use php81 in RHEL 7 or CentOS 7

Thank remi very much.

"Follow the wizard instructions (link on every page of the blog / repo / forum)
and choose "default / single version"
Then you should have php-8.1.4-1.el7.remi.x86_64"

If we install php 8.1 as above, php 8.1 will replace old php 7.4.  But we want to keep both php 7.4 and php 8.1, and can switch between php 7.4 and 8.1.

"EL-7 is 8 years old and close to its end of life in 2024.". You're right, we'll upgrade rhel 1-2 years later.

Re: How to set apache to use php81 in RHEL 7 or CentOS 7

ok, so if you want to have 2 versions installed, you cannot use mod_php (only 1 version can be load)

You have to use php-fpm

I recommend you read
https://developers.redhat.com/blog/2017 … tion-tips/

written for EL-7 and which explain
- how to switch to php-fpm (which is used by default in EL-8 and EL-9)
- how to run multiple version

It describes usage of SCL from official RHSCL repository, but work the same with SCL from my repository.

Desktop: Fedora 35 + rpmfusion + remi-test + remi-dev
Laptop:  Fedora 36 + rpmfusion + remi (SCL only)
Hosting Server: CentOS 8 Stream with EPEL, rpmfusion, remi

Re: How to set apache to use php81 in RHEL 7 or CentOS 7

Remi wrote:

ok, so if you want to have 2 versions installed, you cannot use mod_php (only 1 version can be load)

Thanks. My intention is to install two versions. But run one version only with mod_php. Later run the other version only with mod_php.

Re: How to set apache to use php81 in RHEL 7 or CentOS 7

If you have 2 versions of mod_php (e.g.   php-7.4.28-1.el7.remi.x86_64  and  php81-php-8.1.4-1.el7.remi.x86_64), only the first one will be loaded.

You can choose which one by commenting in/out LoadModule in /etc/httpd/conf.modules.d/*php.conf

BTW, I recommend to use php-fpm (see link in previous answer), which is the modern way to use PHP nowadays. mod_php is the previous century way.

Desktop: Fedora 35 + rpmfusion + remi-test + remi-dev
Laptop:  Fedora 36 + rpmfusion + remi (SCL only)
Hosting Server: CentOS 8 Stream with EPEL, rpmfusion, remi

Re: How to set apache to use php81 in RHEL 7 or CentOS 7

Remi wrote:

If you have 2 versions of mod_php (e.g.   php-7.4.28-1.el7.remi.x86_64  and  php81-php-8.1.4-1.el7.remi.x86_64), only the first one will be loaded.

You can choose which one by commenting in/out LoadModule in /etc/httpd/conf.modules.d/*php.conf

BTW, I recommend to use php-fpm (see link in previous answer), which is the modern way to use PHP nowadays. mod_php is the previous century way.

Thank Remi. You're right that php-fpm is the modern way. But for some reasons, we still need to use mod_php now.
I have tested and in RHEL 7, to go back and forth between php 7.4 and php 81, only thing needs to do is to comment/uncomment corresponding lines with "libphp7.so" or "libphp81.so" for files 15-php.conf and 20-php81-php.conf in /etc/httpd/conf.modules.d. Then restart httpd.service.