upgrade php7.4 to 8.2 ubuntu
its better install php 8.0 and remove 7.4 or change to socket from tcp.
as of now php8.2
List php 7.4 extensions
dpkg -l | grep php7.4
Install php 8
in ubuntu 20/04 LTS default php installation is php 8
add repo
sudo add–apt–repository ppa:ondrej/php
or
sudo LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php
and update
sudo apt-get update && sudo apt-get install php8.0-fpm
or
sudo apt-get update && sudo apt-get install php8.2-fpm
sudo apt install php8.0-common php8.0-mysql php8.0-xml php8.0-xmlrpc php8.0-curl php8.0-gd php8.0-imagick php8.0-cli php8.0-dev php8.0-imap php8.0-mbstring php8.0-opcache php8.0-soap php8.0-zip php8.0-intl -y
php -v
PHP 8.0.27 (cli) (built: Jan 6 2023 15:27:43) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.27, Copyright (c) Zend Technologies
with Zend OPcache v8.0.27, Copyright (c), by Zend Technologies
root@ubuntu-s-2vcpu-4gb-intel-blr1-01:/etc/php# php -v
PHP 8.2.1 (cli) (built: Jan 6 2023 15:18:18) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.1, Copyright (c) Zend Technologies
with Zend OPcache v8.2.1, Copyright (c), by Zend Technologies
root@ubuntu-s-2vcpu-4gb-intel-blr1-01:~#
Configuring php 8.o for nginx
- Delete the default PHP 8.0 worker pool configuration.
$ sudo rm /etc/php/8.0/fpm/pool.d/*
- Copy the configuration from PHP-FPM 7.4 to PHP-FPM 8.0.
$ sudo cp -rL /etc/php/7.4/fpm/pool.d/* /etc/php/8.0/fpm/pool.d/
Configuring php 8.2 for nginx
Delete the default PHP 8.2 worker pool configuration.
$ sudo rm /etc/php/8.2/fpm/pool.d/*
Copy the configuration from PHP-FPM 7.4 to PHP-FPM 8.2.
$ sudo cp -rL /etc/php/7.4/fpm/pool.d/* /etc/php/8.2/fpm/pool.d/
Configuring listening socket or Port for php 8.2 fpm
/etc/php/8.2/fpm/pool.d/www.conf
my case If the old socket is 127.0.0.1:9000: same with nginx config file
Update php ini values in php 8 folder
/etc/php/7.4/fpm/php.ini, then copy those settings to the main PHP 8.0 configuration file /etc/php/8.0/fpm/php.ini.
Php ini values
max_execution_time
memory_limit
post_max_size
upload_max_filesize
date.timezone
memory_limit = 256M
max_execution_time my case 300s or 5 minutes
upload_max_filesize 65MB
Verify new php 8.2 confugration
sudo php-fpm8.2 -t
root@ubuntu-s-2vcpu-4gb-intel-blr1-01:~# sudo php-fpm8.2 -t
[12-Jan-2023 09:41:57] NOTICE: configuration file /etc/php/8.2/fpm/php-fpm.conf test is successful
reload php 8.2 apply changes
sudo systemctl reload php8.2-fpm.service
do not enable on start up if we keep them.
sudo systemctl disable –now php7.4-fpm.service
sudo systemctl disable –now php8.0-fpm.service
check which fpm manager running
ps aux | grep php
root@ubuntu-s-2vcpu-4gb-intel-blr1-01:~# ps aux | grep php
root 6531 0.0 0.3 239560 13368 ? Ss 2022 3:22 php-fpm: master process (/etc/php/7.4/fpm/php-fpm.conf)
finally start the php 8.2 service
sudo systemctl stop php7.4-fpm.service && sudo systemctl start php8.2-fpm.service
root@ubuntu-s-2vcpu-4gb-intel-blr1-01:~# ps aux | grep php root 831891 0.6 0.6 216160 25332 ? Ss 09:53 0:00 php-fpm: master process (/etc/php/8.2/fpm/php-fpm.conf)
Uninstall/Remove PHP 7.x and Extensions
or keep it as backup change tcp port listening socket
/var/run/php/php7.4-fpm.sock or
127.0.0.1:9001
To uninstall PHP 7.x and all of its extensions, run the command below.
Monitor errors in the nginx log
tail -f /var/log/nginx/error.log
Note: WordPress plugins & themes need to update their php scripts according to php8.1 (check new features & fixes) new version prone to bugs.
sudo apt-get purge php7.*
E: The repository 'http://ppa.launchpad.net/certbot/certbot/ubuntu focal Release' does not have a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.