Soms is het nodig om meerdere versies van PHP actief te hebben op je webserver omdat de ene (nextcloud) applicatie bijvoorbeeld al een nieuwere versie nodig heeft en weer een andere (spotweb) nog alleen werkt met die 'oude' versie.
In dit geval ging het om resp. versies 7.4 en 7.2.
Standaard wordt er door apache de mod_php gebruikt om PHP te activeren. Zo ook bij mij. Om meerdere versies te kunnen gebruiken was PHP-FPM nodig.
Dit is sowieso geen overbodige luxe aangezien dit de moderne en nieuwe manier van het implementeren van PHP is. (In combinatie met NGINX al standaard) Het koppelt PHP los van de webserver (apache) en maakt het makkelijker om performance tweaks te doen aan PHP.
Zorg dat je in iedergeval de laatste versie kan installeren. Via standaard repositories lukt dit niet misschien dus dan eerst een extra repo toevoegen.
root@php-jitsi-docker:~# apt-get install php7.4-fpm
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package php7.4-fpm
E: Couldn't find any package by glob 'php7.4-fpm'
E: Couldn't find any package by regex 'php7.4-fpm'
Zelf gebruik ik de ondrej ppa die veel versies van php bevat waaronder ook de splinternieuwe versies.
Installeren gaat middels het volgende: (het eerste commando is om ervoor te zorgen dat je uberhaupt ppa repo's kan installeren)
apt -y install software-properties-common
add-apt-repository ppa:ondrej/php
apt-get update
Output. Bij regel 26 wordt er gewacht tot je een ENTER geeft om verder te gaan.
root@php-jitsi-docker:~# add-apt-repository ppa:ondrej/php
Co-installable PHP versions: PHP 5.6, PHP 7.x and most requested extensions are included. Only Supported Versions of PHP (http://php.net/supported-versions.php) for Supported Ubuntu Releases (https://wiki.ubuntu.com/Releases) are provided. Don't ask for end-of-life PHP versions or Ubuntu release, they won't be provided.
Debian oldstable and stable packages are provided as well: https://deb.sury.org/#debian-dpa
You can get more information about the packages at https://deb.sury.org
IMPORTANT: The <foo>-backports is now required on older Ubuntu releases.
BUGS&FEATURES: This PPA now has a issue tracker:
https://deb.sury.org/#bug-reporting
CAVEATS:
1. If you are using php-gearman, you need to add ppa:ondrej/pkg-gearman
2. If you are using apache2, you are advised to add ppa:ondrej/apache2
3. If you are using nginx, you are advised to add ppa:ondrej/nginx-mainline
or ppa:ondrej/nginx
PLEASE READ: If you like my work and want to give me a little motivation, please consider donating regularly: https://donate.sury.org/
WARNING: add-apt-repository is broken with non-UTF-8 locales, see
https://github.com/oerdnj/deb.sury.org/issues/56 for workaround:
# LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
More info: https://launchpad.net/~ondrej/+archive/ubuntu/php
Press [ENTER] to continue or Ctrl-c to cancel adding it.
Get:1 http://ppa.launchpad.net/ondrej/php/ubuntu bionic InRelease [20.8 kB]
Get:2 http://mirrors.digitalocean.com/ubuntu bionic InRelease [242 kB]
Hit:3 http://mirrors.digitalocean.com/ubuntu bionic-updates InRelease
Hit:4 https://repos.insights.digitalocean.com/apt/do-agent main InRelease
Hit:5 http://mirrors.digitalocean.com/ubuntu bionic-backports InRelease
Get:6 http://ppa.launchpad.net/ondrej/php/ubuntu bionic/main amd64 Packages [96.5 kB]
Get:7 http://ppa.launchpad.net/ondrej/php/ubuntu bionic/main Translation-en [34.7 kB]
Hit:8 http://security.ubuntu.com/ubuntu bionic-security InRelease
Fetched 394 kB in 0s (833 kB/s)
Reading package lists... Done
Nu dan echt de benodigde versies van php installeren.
apt install php7.2-fpm php7.4-fpm
Vergeet niet om nog additionele modules te installeren als het een nieuwe versie betreft. Dat betekent dus dat als je als 7.2 had en daar alles op had draaien dan heb je waarschijnlijk ook php-mysql minimaal als module om met MySQL te kunnen verbinden.
Zo installeer je voornoemde module dan dus voor php7.4
apt install php7.4-mysql
Dan het omzetten naar de nieuwe methode. In dit geval naar php 7.2 met FPM.
a2dismod php7.2
a2enmod proxy_fcgi setenvif
a2enconf php7.2-fpm
systemctl restart apache2
Wil je gelijk upgraden en dus 7.4 gebruiken als standaard dan kan dat.
a2dismod php7.2
a2enmod proxy_fcgi setenvif
a2enconf php7.4-fpm
systemctl restart apache2
Als er websites zijn die niet goed met die laatste versie werken dan kan je voor een specifieke vhost gewoon 7.2 blijven gebruiken.
Open de configuratie van de betreffende vhost en voeg het volgende stuk in in de configuratie.
<FilesMatch ".+\.ph(ar|p|tml)$">
SetHandler "proxy:unix:/run/php/php7.2-fpm.sock|fcgi://localhost"
</FilesMatch>
Ik heb het na het <directory>
blok gedaan.
<Directory /var/www/spotweb/>
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride FileInfo
Order allow,deny
allow from all
</Directory>
#Tell Apache to use Php7.2 for this site
<FilesMatch ".+\.ph(ar|p|tml)$">
SetHandler "proxy:unix:/run/php/php7.2-fpm.sock|fcgi://localhost"
</FilesMatch>
ErrorLog /var/log/apache2/spotweb/ssl-error.log
php.ini leeft in /etc/php/7.4/fpm i.p.v. in /etc/php/7.4/apache2
Configuratiefile is gewoon de standaard php configuratie dus variabelen als memory_limit / upload_max_filesize zijn hier net zoals voorheen in te stellen.
1 verschil wel is dat je voorheen deze wijzigingen activeerde door apache te herstarten. Dat hoeft / werkt helaas niet meer zo. Dit komt doordat php-fpm als zelfstandig proces draait. Je zal dat proces dus moeten herstarten.
In het geval van versie 7.4 als volgt.
systemctl restart php7.4-fpm
ps aux | grep php
Geeft
root@www:~# ps aux | grep php
root 1791 0.0 0.2 537368 33912 ? Ss 11:16 0:00 php-fpm: master process (/etc/php/7.4/fpm/php-fpm.conf)
www-data 1954 0.5 0.6 872064 104080 ? S 11:26 0:29 php-fpm: pool www
www-data 2013 0.3 0.5 862724 91840 ? S 11:30 0:15 php-fpm: pool www
www-data 2143 0.0 0.4 780632 73216 ? S 11:36 0:01 php-fpm: pool www
root 3220 0.0 0.0 14432 952 pts/0 S+ 12:49 0:00 grep --color=auto php
root 24449 0.0 0.2 532036 33620 ? Ss 10:12 0:00 php-fpm: master process (/etc/php/7.2/fpm/php-fpm.conf)
www-data 25481 0.1 0.4 853784 71364 ? S 10:22 0:09 php-fpm: pool www
www-data 25484 0.0 0.3 773108 59156 ? S 10:22 0:06 php-fpm: pool www
www-data 25492 0.1 0.3 616676 60192 ? S 10:22 0:12 php-fpm: pool www