Automated PHP upgrade to 8.1 for LibreNMS
I've been putting off updating PHP on my LibreNMS box for a while, but I finally figured I'd take a crack at it. I was on 7.3 and needed to get to 8.1.
I am running Debian 10, and only running LibreNMS on this machine.
If you are on 7.3, this should get you there. If you are on 7.4, just find everywhere it says 7.3, and change it to 7.4.
Also, you will probably need to set the correct timezone in the script. And of course I have not validated this against anything but my own machine. I take no responsibility for it breaking anything! Always take a snapshot/backup first. Also read over the script so you know what its doing
#!/bin/bash
echo "Upgrading system and installing required packages for PHP repository..."
sudo apt update && sudo apt upgrade -y
sudo apt install -y lsb-release ca-certificates apt-transport-https software-properties-common gnupg2
#Add Sury PHP repository
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/sury-php.list
curl -fsSL https://packages.sury.org/php/apt.gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/sury-keyring.gpg
echo "Updating package list..."
sudo apt update
sudo apt upgrade -y
echo "Installing required PHP packages for LibreNMS..."
sudo apt install php8.1-cli php8.1-common php8.1-curl php8.1-fpm php8.1-gd php8.1-mbstring php8.1-mysql php8.1-opcache php8.1-readline php8.1-snmp php8.1-xml php8.1-zip -y
echo "Installing required packages for LibreNMS..."
sudo apt install acl curl fping git graphviz imagemagick mariadb-client mariadb-server mtr-tiny nginx-full nmap rrdtool snmp snmpd whois unzip python3-pymysql python3-dotenv python3-redis python3-setuptools python3-systemd python3-pip -y
echo "Setting timezone to CST for PHP..."
sudo sed -i "s/;date.timezone =/date.timezone = America\/Chicago/" /etc/php/8.1/cli/php.ini
sudo sed -i "s/;date.timezone =/date.timezone = America\/Chicago/" /etc/php/8.1/fpm/php.ini
echo "Copying LibreNMS configuration file..."
sudo cp /etc/php/7.3/fpm/pool.d/librenms.conf /etc/php/8.1/fpm/pool.d/librenms.conf
sudo apt-get purge php7.* -y
echo "Restarting PHP-FPM..."
sudo systemctl restart php8.1-fpm
sudo pip3 install -r /opt/librenms/requirements.txt
echo "Upgrade complete. Please check the LibreNMS web interface for verification."
Now reboot, and you should see PHP is version 8. I had to fix a few minor things under validate config, but now all is working