0

At the moment I have running PHP 8.0 with Mautic and Moodle on a VPS with Ubuntu Server 22.04.

I want to install Suite CRM what needs php8.1 and another app who needs php8.2.

  1. How to install php8.1 and php8.2. I want to keep my default php8.0 and the applications will initially continue to run under 8.0?

  2. How can I set the PHP version for every site/app?

  3. About cron jobs: At the moment the cron job in Mautic is e.g. * * * php /var/www/html/mautic/bin/console mautic:campaigns:trigger How do i set an cron job that it use a special php version? (Mautic and Moodle needs cron jobs)

Here ist my config for mo.stefan-franz.de:

<VirtualHost *:80>
ServerAdmin info@stefan-franz.de
DocumentRoot /var/www/html/moodle/
ServerName  mo.stefan-franz.de

<Directory /var/www/html/moodle/> Options +FollowSymlinks AllowOverride All Require all granted </Directory>

<FilesMatch .php$> SetHandler "proxy:unix:/run/php/php8.1-fpm.sock|fcgi://localhost/" </FilesMatch>

ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined

RewriteEngine on RewriteCond %{SERVER_NAME} =mo.stefan-franz.de RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent] </VirtualHost>

My SSL configuration_

    root@mautic01:/etc/apache2/sites-available# ls -alh
total 44K
    drwxr-xr-x 2 root root 4.0K Nov 14 12:19 .
    drwxr-xr-x 8 root root 4.0K Nov  7 08:31 ..
    -rw-r--r-- 1 root root 1.3K Apr  8  2023 000-default.conf
    -rw-r--r-- 1 root root 4.5K Apr  8  2023 default-ssl.conf
    -rw-r--r-- 1 root root  647 Sep 30 12:40 ma.stefan-franz.de-le-ssl.conf
    -rw-r--r-- 1 root root  532 Nov 14 12:19 ma.stefan-franz.de.conf
    -rw-r--r-- 1 root root  626 Oct  8 19:56 mo.stefan-franz.de-le-ssl.conf
    -rw-r--r-- 1 root root  466 Oct  8 19:56 mo.stefan-franz.de.conf
    -rw-r--r-- 1 root root  636 Nov  7 08:31 shop.stefan-franz.de-le-ssl.conf
    -rw-r--r-- 1 root root  474 Nov  7 08:31 shop.stefan-franz.de.conf

And here is the SSL config for moodle:

<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin info@stefan-franz.de
DocumentRoot /var/www/html/moodle/
ServerName  mo.stefan-franz.de

<Directory /var/www/html/moodle/> Options +FollowSymlinks AllowOverride All Require all granted </Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined

SSLCertificateFile /etc/letsencrypt/live/mo.stefan-franz.de/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/mo.stefan-franz.de/privkey.pem Include /etc/letsencrypt/options-ssl-apache.conf Header always set Strict-Transport-Security "max-age=31536000"

1 Answers1

3

If you want to use different PHP versions on your sites, you have to use PHP FPM(FastCGI Process Manager).

1. Installing php8.1 and php8.2

Some of the PHP versions you want are not in the official repos, so you can use ppa:ondrej/php repository:

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt upgrade

Install PHP FPM and required extensions:

sudo apt install php8.0-fpm
sudo apt install php8.1-fpm
sudo apt install php8.2-fpm

sudo a2enmod proxy_fcgi sudo service apache2 restart

You also have to install the required PHP extensions by the sites/apps you want to run. For example if your PHP8.2 site need MySQL you will have to install that too:

sudo apt install php8.2-mysql

2. Set the PHP version for every site

Edit your Apache2 vhost configs for each site in /etc/apache2/sites-available/. Between <VirtualHost> and </VirtualHost>, add the following code (replace 8.1 with the version you want for each site):

<FilesMatch \.php$>
    SetHandler "proxy:unix:/var/run/php/php8.1-fpm.sock|fcgi://localhost/"
</FilesMatch>

You have to add these line to your -le-ssl.conf files too. For example /etc/apache2/sites-available/mo.stefan-franz.de-le-ssl.conf should look like this:

<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin info@stefan-franz.de
DocumentRoot /var/www/html/moodle/
ServerName  mo.stefan-franz.de

<Directory /var/www/html/moodle/> Options +FollowSymlinks AllowOverride All Require all granted </Directory>

<FilesMatch .php$> SetHandler "proxy:unix:/run/php/php8.1-fpm.sock|fcgi://localhost/" </FilesMatch>

ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined

SSLCertificateFile /etc/letsencrypt/live/mo.stefan-franz.de/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/mo.stefan-franz.de/privkey.pem Include /etc/letsencrypt/options-ssl-apache.conf Header always set Strict-Transport-Security "max-age=31536000" </VirtualHost> </IfModule>

3. Use a specific PHP version for the cron

The php command in your cron is using the CLI version of PHP. You have to install the version specific php-cli package. You can use update-alternatives to configure which version php will use. For example if you want to use PHP 8.2 for php, do this:

sudo apt install php8.2-cli

sudo update-alternatives --set php /usr/bin/php8.2

Alternatively, you can use the command php8.2 instead of php in your cron.

To make changes to the settings in php.ini, you have several different files:

  • Sites running PHP FPM 8.2:

    Edit: /etc/php/8.2/fpm/php.ini

    After changes to this file, you should restart the FPM service:

    sudo service php8.2-fpm restart
    
  • Sites running PHP FPM 8.1:

    Edit: /etc/php/8.1/fpm/php.ini

    After changes to this file, you should restart the FPM service:

    sudo service php8.1-fpm restart
    
  • Sites running PHP FPM 8.0:

    Edit: /etc/php/8.0/fpm/php.ini

    After changes to this file, you should restart the FPM service:

    sudo service php8.0-fpm restart
    
  • Default for sites without SetHandler in their vhost config:

    Edit: /etc/php/8.1/apache2/php.ini

    After changes to this file, you should restart the Apache2 service:

    sudo service apache2 restart
    
  • When using the command php from the cron (replace 8.2 with the version you set in update-alternatives):

    Edit: /etc/php/8.2/cli/php.ini

sotirov
  • 3,169
  • 3rd attempt - But Moodle didn't recognise php8.1 I made it step by step as you described. – Stefan Franz Nov 14 '23 at 16:59
  • What do you mean by don't recognize? How are you testing it? – sotirov Nov 14 '23 at 17:00
  • I made an info php: https://mo.stefan-franz.de/info.php With that code: And in Moodle i can check with php version Moodle works – Stefan Franz Nov 14 '23 at 17:04
  • @StefanFranz can you edit you question and share the vhost config for mo.stefan-franz.de – sotirov Nov 14 '23 at 17:05
  • Now am back on the PC for fast response and very much thanks for your support. – Stefan Franz Nov 14 '23 at 17:54
  • @StefanFranz I see you have HTTPS running on the server. Do you have a different config for the SSL? Have you added the SetHandler directive there too? – sotirov Nov 14 '23 at 20:42
  • Yes i use https of course: https://mo.stefan-franz.de/ I don't know what you mean with a "SetHandler" I was able to install Mautic and Moodle with some tutorials and both running stable. But unfortunately i'm a beginner and so i need (if you want help me) a easy to use step by step tutorial for dummies.

    I installed php8.1 this with the modules i need: sudo apt install php8.1 libapache2-mod-php8.1 php8.1-common php8.1-gmp php8.1-curl php8.1-intl php8.1-mbstring php8.1-xmlrpc php8.1-mysql php8.1-bcmath php8.1-gd php8.1-xml php8.1-cli php8.1-fpm php8.1-zip php8.1-imap php8.1-soap

    – Stefan Franz Nov 15 '23 at 05:01
  • You have done well. This is the right way to install the PHP extensions. The problem I am seen is that mo.stefan-franz.de still uses the mod_php, not the php8.1-fpm. By SetHandler I mean this lines: <FilesMatch \.php$> SetHandler "proxy:unix:/run/php/php8.1-fpm.sock|fcgi://localhost/" </FilesMatch>. Add these to the ssl config too and restart the Apache with sudo service apache2 restart – sotirov Nov 15 '23 at 07:18
  • What do you mean with ssl config? And how do i have exactly adjust that? – Stefan Franz Nov 15 '23 at 07:42
  • Can you edit your question and add details about your SSL configuration and the result of: ls -alh /etc/apache2/sites-available/ ? – sotirov Nov 15 '23 at 07:58
  • @StefanFranz I updated my answer with details how to edit /etc/apache2/sites-available/mo.stefan-franz.de-le-ssl.conf. After the edits, don't forget to restart the Apache sudo service apache2 restart – sotirov Nov 15 '23 at 09:59
  • 1
    Thank you very much for your great support. For the special php settings for moodle php8.1 this is the right config file?: /etc/php/8.1/fpm/php.ini – Stefan Franz Nov 15 '23 at 11:58
  • @StefanFranz yes – sotirov Nov 15 '23 at 12:53
  • Success :-))) - It works! About cronjob - to be sure: In moodle i had to add a cronjob: crontab -u www-data -e Before it was: PHP8.0
            • /usr/bin/php /var/www/html/moodle/admin/cli/cron.php >/dev/null

    I changed it to:

            • /usr/bin/php8.1 /var/www/html/moodle/admin/cli/cron.php >/dev/null

    Is that right?

    – Stefan Franz Nov 15 '23 at 15:57
  • Question to Mautic: I added a info.php, but i can't access. What is the reason? https://ma.stefan-franz.de/info.php – Stefan Franz Nov 15 '23 at 16:02
  • @StefanFranz Something is blocking the file. It's hard to tell without more details. For a start you can check /var/log/apache2/error.log. But this is another questions, so it will be best if you open a new questions. Please, check https://askubuntu.com/tour for more details about how AskUbuntu works. – sotirov Nov 15 '23 at 17:12
  • Have a problem: Moodle doesn't find the images. The moodle working directory is: /var/www/html/moodledata - could it be, that with php changing also the path to this directory i have anywhere to change? (i went back to php8.0 because moodle have to run - first i need to find the error) – Stefan Franz Nov 15 '23 at 20:28
  • In the config.php i found: $CFG->wwwroot = 'https://mo.stefan-franz.de'; $CFG->dataroot = '/var/www/html/moodledata'; Maybe i have to adjust here someting? – Stefan Franz Nov 15 '23 at 20:40
  • To Moodle: if i set the php8.1 as default php without the proxy_fcgi it works normal. So i wait now until Mautic is also able with 8.1 and after that, i change my server to 8.1 for all. – Stefan Franz Nov 16 '23 at 09:38