How to upgrade PHP to 8.1 in Ubuntu
How to upgrade PHP to 8.1 in Ubuntu?
Prerequisites
Any installed PHP version with apache and nginx web server.
Enter the following commands on the terminal to upgrade PHP:
1 . To install the latest PHP 8.1, you need to install PHP 8 binary packages that are available in the Ondrej Sury PPA repository.
[email protected]:~# apt-get install php8.1
3. Now install PHP 8.1 with all necessary modules with the command below.
4. Restart Apache2
5. Disable the current version PHP modules whichever you are running and enable the modules for 8.1 version
6. Restart the Apache2 service.
To upgrade PHP to 8/8.1 with nginx web server
1. Update and upgrade your system packages.
[email protected]:~# apt-get update -y
[email protected]:~# apt-get upgrade -y
2. Allow apt to use the system repository
[email protected]:~# apt install ca-certificates apt-transport-https
[email protected]:~# apt install software-properties-common
[email protected]:~# add-apt-repository ppa:ondrej/php
Press ENTER when prompted while adding the repository.
[email protected]:~# apt install php8.1 php8.1-fpm
[email protected]:~# systemctl status php8.1-fpm
5. For Nginx to process PHP files, configure your Nginx server block by updating/adding the server section:
[email protected]:~# nano /etc/nginx/sites-available/example
server {
listen 80;
server_name 192.168.0.105;
root /var/www/html;
index info.php;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
}
}
6. Restart the Nginx service.
[email protected]:~# systemctl restart nginx
7. Install the php8.1 needed packages.
[email protected]:~# apt install php8.1-cli php8.1-xml php8.1-gd php8.1-curl php8.1-mysql php8.1-ldap php8.1-zip
To check installed version of PHP and set the needed PHP version
[email protected]:~# update-alternatives --config php
Testing PHP