Upgrading php7.2 to php7.4 in Ubuntu 18.04LTS

For those of you that need to upgrade their php from 7.2 to 7.4, here is the process that I went through and was able to do so easily on Ubuntu18.04LTS

Add php7.4 libraries

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

Remove php7.2

apt purge libapache2-mod-php7.2 php7.2-cli php7.2-curl php7.2-gd php7.2-json php7.2-mbstring php7.2-mysql php7.2-snmp php7.2-xml php7.2-zip

Install php7.4

apt install composer php7.4 php7.4-cli php7.4-curl php7.4-fpm php7.4-gd php7.4-json php7.4-mbstring php7.4-mysql php7.4-snmp php7.4-xml php7.4-zip

Change Timezone

vi /etc/php/7.4/fpm/php.ini
vi /etc/php/7.4/cli/php.ini

Configure PHP-FPM

cp /etc/php/7.4/fpm/pool.d/www.conf /etc/php/7.4/fpm/pool.d/librenms.conf
vi /etc/php/7.4/fpm/pool.d/librenms.conf
[www] to [librenms]
user = librenms
group = librenms
listen = /run/php-fpm-librenms.sock

update /etc/apache2/sites-available/librenms.conf

mv /etc/apache2/sites-available/librenms.conf /etc/apache2/sites-available/librenms-7.2.conf
vi /etc/apache2/sites-available/librenms.conf

*** use this as template; dont forget to change this per your 7.2 verision ***

<VirtualHost *:80>
  DocumentRoot /opt/librenms/html/
  ServerName  librenms.example.com

  AllowEncodedSlashes NoDecode
  <Directory "/opt/librenms/html/">
    Require all granted
    AllowOverride All
    Options FollowSymLinks MultiViews
  </Directory>

  <IfModule setenvif_module>
    SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1
  </IfModule>

  <FilesMatch ".+\.php$">
    SetHandler "proxy:unix:/run/php-fpm-librenms.sock|fcgi://localhost"
  </FilesMatch>
</VirtualHost>

Restart services

a2enmod proxy_fcgi setenvif rewrite
a2ensite librenms.conf
systemctl restart apache2
systemctl restart php7.4-fpm

This worked like a charm for me. Thanks again to Tony for leading me in the right direction and Hans for helping to develop and validate.

Cheers!

4 Likes

In my thoughts it’s easier to just change the required PHP version in e.g. remi repo, remove PHP 7.2 and install php.

For Centos for example

No further adjustments needed.

worked for me too. Thanks :slight_smile:

1 Like

Hi,

have troubles to add php7.4 libraries for Raspbian/buster:

sudo add-apt-repository ppa:ondrej/php
Traceback (most recent call last):
  File "/usr/bin/add-apt-repository", line 95, in <module>
    sp = SoftwareProperties(options=options)
  File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 109, in __init__
    self.reload_sourceslist()
  File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 599, in reload_sourceslist
    self.distro.get_sources(self.sourceslist)
  File "/usr/lib/python3/dist-packages/aptsources/distro.py", line 93, in get_sources
    (self.id, self.codename))
aptsources.distro.NoDistroTemplateException: Error: could not find a distribution template for Raspbian/buster

sudo add-apt-repository ppa:ondrej/apache2
Traceback (most recent call last):
  File "/usr/bin/add-apt-repository", line 95, in <module>
    sp = SoftwareProperties(options=options)
  File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 109, in __init__
    self.reload_sourceslist()
  File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 599, in reload_sourceslist
    self.distro.get_sources(self.sourceslist)
  File "/usr/lib/python3/dist-packages/aptsources/distro.py", line 93, in get_sources
    (self.id, self.codename))
aptsources.distro.NoDistroTemplateException: Error: could not find a distribution template for Raspbian/buster

apt install composer php7.4 php7.4-cli php7.4-curl php7.4-fpm php7.4-gd php7.4-json php7.4-mbstring php7.4-mysql php7.4-snmp php7.4-xml php7.4-zip
Packet lists are read... Done
Dependency tree is built.
Status information is read.... Ready
E: Package php7.4 cannot be found.
E: Using the pattern "php7.4" no package could be found.
E: Using the regular expression "php7.4" no package could be found.
E: Package php7.4-cli could not be found
E: No package could be found using the pattern "php7.4-cli".
E: No package could be found using the regular expression "php7.4-cli".
E: Package php7.4-curl could not be found.
E: No package could be found using the pattern "php7.4-curl".
E: No package could be found using the regular expression "php7.4-curl".
E: Package php7.4-fpm could not be found
E: No package could be found using the pattern "php7.4-fpm".
E: No package could be found using the regular expression "php7.4-fpm".
E: Package php7.4-gd could not be found
E: No package could be found using the pattern "php7.4-gd".
E: No package could be found using the regular expression "php7.4-gd".
E: Package php7.4-json could not be found
E: No package could be found using the pattern "php7.4-json".
E: No package could be found using the regular expression "php7.4-json".
E: Package php7.4-mbstring could not be found.
E: No package could be found using the pattern "php7.4-mbstring".
E: No package could be found using the regular expression "php7.4-mbstring".
E: Package php7.4-mysql could not be found
E: No package could be found using the pattern "php7.4-mysql".
E: No package could be found using the regular expression "php7.4-mysql".
E: Package php7.4-snmp could not be found.
E: No package could be found using the pattern "php7.4-snmp".
E: No package could be found using the regular expression "php7.4-snmp".
E: Package php7.4-xml could not be found.
E: No package could be found using the pattern "php7.4-xml".
E: No package could be found using the regular expression "php7.4-xml".
E: Package php7.4-zip could not be found.
E: No package could be found using the pattern "php7.4-zip".
E: Using the regular expression "php7.4-zip" no package could be found.

Here is my running version:

Raspbian GNU/Linux 10 (buster)
4.19.97-v7+
====================================
Component | Version  2.0.6
--------- | -------
LibreNMS  | 1.69-21-gac5920f45
DB Schema | 2020_10_30_093601_add_tos_to_ospf_ports (189)
PHP       | 7.3.19-1~deb10u1
Python    | 3.7.3
MySQL     | 10.3.25-MariaDB-0+deb10u1
RRDTool   | 1.7.1
SNMP      | NET-SNMP 5.7.3
OpenSSL   |
====================================

Can you help with that?

Add the ondrej/php repo for Debian to solve the Error: could not find a distribution template for Raspbian/buster error:

sudo apt install apt-transport-https lsb-release
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg # Download the signing key
sudo sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list' # Add Ondrej's repo to sources list.
sudo apt update

I followed this guide and everything was fine until last command. This part was not clear to me. i just put it as it is but maybe thats wrong

[www] to [librenms]
user = librenms
group = librenms
listen = /run/php-fpm-librenms.sock

This is the error

nov 12 21:25:00 netbox systemd[1]: Starting The PHP 7.4 FastCGI Process Manager...
nov 12 21:25:00 netbox php-fpm7.4[22507]: PHP:  syntax error, unexpected END_OF_LINE, expecting '=' in Unknown on line 3
nov 12 21:25:00 netbox php-fpm7.4[22507]: [12-Nov-2020 21:25:00] ERROR: Unable to include /etc/php/7.4/fpm/pool.d/librenms.conf from /etc/php/7.4/fpm/php-fpm.conf at line 4
nov 12 21:25:00 netbox php-fpm7.4[22507]: [12-Nov-2020 21:25:00] ERROR: failed to load configuration file '/etc/php/7.4/fpm/php-fpm.conf'
nov 12 21:25:00 netbox php-fpm7.4[22507]: [12-Nov-2020 21:25:00] ERROR: FPM initialization failed
nov 12 21:25:00 netbox systemd[1]: php7.4-fpm.service: Main process exited, code=exited, status=78/n/a
nov 12 21:25:00 netbox systemd[1]: php7.4-fpm.service: Failed with result 'exit-code'.
nov 12 21:25:00 netbox systemd[1]: Failed to start The PHP 7.4 FastCGI Process Manager.

I’v got it running after correcting the part i mentioned above. At one point i was able to log on but still hade notice saying that i need to upgrade php. My validate.php suggested to run daily.sh and it’s generating a lot of errors about database e.g. missing columns, extra index
Also error about timezone in php but it is set as mentioned in guide

I’m not sure what is going on but right now it is stuck at cleaning DB. i’ll let it run and see what happens

Hello !
Thanks a lot for your post but unfortunately, my LibreNMS doesn’t work anymore :confused:
When I try to access to my LibreNMS web page I get this :


./validate.php has no output now
I’m using Ubuntu 18.04.
I very often get this error
Undefined index: name at /opt/librenms/vendor/laravel/framework/src/Illuminate/Foundation/PackageManifest.php:122)
From what I’ve seen, it’s related to a bug with laravel/framework - illuminate/foundation (not sure what librenms uses) and composer.
Do do you guys have any clue ? :slight_smile:

Thanks a lot !

I have seen that too during my upgrade to 7.4 php.
After following the guide mentioned above and also running daily.sh afterwards, everything resolved. Dont know what happened. Daily.sh took several hours so i left it running over night.
Hope this helps somehow

Thanks for your answer.
I’m not sure what solved the issue because I’ve tested different fixes but it’s working now. That’s all matters lol
I just need to make my SSL certificate work again. Do you know what to change in the librenms.conf file (apache2) for the <VirtualHost *:443> ?

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)