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 [email protected]
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 [email protected]
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"
3
  • Do you still need help?
    – sotirov
    Nov 14, 2023 at 15:15
  • I had to rebuild my server. Mautic wanted also run with php8.1 obviously i made the config right. Don't know why. I start now again. Nov 14, 2023 at 16:24
  • I update my answer with details about how to edit php.ini.
    – sotirov
    Nov 14, 2023 at 16:59

1 Answer 1

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 [email protected]
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

19
  • 3rd attempt - But Moodle didn't recognise php8.1 I made it step by step as you described. Nov 14, 2023 at 16:59
  • What do you mean by don't recognize? How are you testing it?
    – sotirov
    Nov 14, 2023 at 17:00
  • I made an info php: mo.stefan-franz.de/info.php With that code: <?php phpinfo(); ?> And in Moodle i can check with php version Moodle works Nov 14, 2023 at 17:04
  • @StefanFranz can you edit you question and share the vhost config for mo.stefan-franz.de
    – sotirov
    Nov 14, 2023 at 17:05
  • 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 Nov 15, 2023 at 11:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .