How to run with multiple PHP versions on Fedora 35 using Apache and PHP-FPM

By | November 23, 2021

I am self hosting my own services on my home server and sometimes issues occur due to incompatible prerequisites and because I try to always use the latest version of everything.

After updating from Fedora 34 to Fedora 35 again I hit one issue I already had: PHP prerequisites.

The issue after update was caused by the fact that Fedora 35 by default updates to PHP 8.0. That is nice that the new PHP features are available, WordPress instance is happy but no so the OwnCloud instance.

Look like OwnCloud latest release at this date 10.8.0 is still compatible with a maximum PHP version of 7.4.

The challenge is how to allow Owncloud to use an older PHP version at the same time with WordPress using the latest and greatest.

It turns out I am not the only one with this issue. After some days of searching through forums and useless Stack Overflow posts I finally found a tutorial in the knowledge base of one of my favorite low cost hosting solution provider: DigitaOcean How To Run Multiple PHP Versions on One Server Using Apache and PHP-FPM on CentOS 8

Starting from the above mentioned tutorial I made my own tutorial that has some extra tips for my case of WordPress and Owncloud running together on the same machine.

Step 1: Installing PHP Versions 7.4 with PHP-FPM

WordPress works just fine with PHP and PHP-FPM version 8.0 that is provided out of the box by Fedora 35 but as wee seen above Owncloud is restricted to a version not higher than 7.4.

We can install this from a separate repo, REMI repo for Fedora 35:

$ sudo dnf install http://rpms.remirepo.net/enterprise/remi-release-35.rpm

Then we can install php 7.4 with all the extra required PHP packages for OwnCloud.

$ sudo dnf install php74.x86_64 php74-php-cli.x86_64 php74-php-common.x86_64 php74-php-fpm.x86_64 php74-php-gd.x86_64 php74-php-gmp.x86_64 php74-php-imap.x86_64 php74-php-intl.x86_64 php74-php-json.x86_64 php74-php-mbstring.x86_64 php74-php-mysqlnd.x86_64 php74-php-pdo.x86_64 php74-php-pecl-apcu.x86_64 php74-php-pecl-imagick-im7.x86_64 php74-php-pecl-json-post.x86_64 php74-php-pecl-jsonpath.x86_64 php74-php-pecl-mcrypt.x86_64 php74-php-pecl-memcache.x86_64 php74-php-pecl-mysql.x86_64 php74-php-pecl-mysql-xdevapi.x86_64 php74-php-pecl-mysqlnd-azure.x86_64 php74-php-pecl-zip.x86_64 php74-php-process.x86_64 php74-php-smbclient.x86_64 php74-php-xml.x86_64 php74-runtime.x86_64

Step 2: Configure the new PHP-FPM

Start the php74-php-fpm service and enable it to start at boot with the following commands:

$ sudo systemctl start php74-php-fpm
$ sudo systemctl enable php74-php-fpm

Note that remi PHP is installed under /var/opt/remi to avoid conflicts with the system default PHP.

Step 3: Configuring Apache for Both Websites

Under /etc/httpd/conf.d php74 is installing an additional php74-php.conf file that configures php. This has to be removed because we do not want to interfere with the default configuration file php.conf.

Inside the php.conf file comment the following block:

#
# Redirect to local php-fpm (no mod_php in default configuration)
#
#<IfModule !mod_php5.c>
#  <IfModule !mod_php7.c>
    # Enable http authorization headers
#    SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1

#    <FilesMatch \.(php|phar)$>
#        SetHandler "proxy:unix:/run/php-fpm/www.sock|fcgi://localhost"
#    </FilesMatch>
#  </IfModule>
#</IfModule>

This eliminates the default PHP-FPM configuration and we will have to add this type of redirect entry in every Virtual Host configuration.

Note that without this redirect a virtual host that uses PHP will no longer work.

In the configuration file of the Virtual Host of the WordPress instance “blog.voina.org.conf” add the following block inside the VirtualHost declaration:

<IfModule !mod_php5.c>
  <IfModule !mod_php7.c>
    # Enable http authorization headers
    SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1

    <FilesMatch \.(php|phar)$>
        SetHandler "proxy:unix:/run/php-fpm/www.sock|fcgi://localhost"
    </FilesMatch>
  </IfModule>
</IfModule>

Note that any php file is redirected to the default php-fpm instance.

In the configuration file of the Virtual Host of the OwnCloud instance “home.voina.org.conf” add the following block inside the VirtualHost declaration:

<IfModule !mod_php5.c>
  <IfModule !mod_php7.c>
    # Enable http authorization headers
    SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1

    <FilesMatch \.(php|phar)$>
        SetHandler "proxy:unix:/var/opt/remi/php74/run/php-fpm/www.sock|fcgi://localhost"
    </FilesMatch>
  </IfModule>
</IfModule>

Note that any php file is redirected to the custom php74 remi php-fpm instance.

After this is done simply restart the httpd server.

$ sudo systemctl restart httpd

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.