How to upgrade PHP to 8.1 in Ubuntu
How to upgrade PHP to 8.1 in Ubuntu?
Overview: This article provides the step to upgrade the PHP version.
Prerequisites: Any installed PHP version with apache and nginx web server.
Enter the following commands on the terminal to upgrade PHP version:
Step 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.
Step 3: Now install PHP 8.1 with all necessary modules with the command below:
To upgrade PHP to 8/8.1 with nginx web server
Step 1: Update and upgrade your system packages.
root@gateway:~# apt-get update -y
root@gateway:~# apt-get upgrade -yStep 2: Allow apt to use the system repository.
root@gateway:~# apt install ca-certificates apt-transport-https
root@gateway:~# apt install software-properties-common
Step 3: You need to install PHP 8 binary packages that are available in the Ondrej Sury PPA repository.
root@gateway:~# add-apt-repository ppa:ondrej/php
Press ENTER when prompted while adding the repository.
Step 4: Install PHP 8/ 8.1 with nginx.
root@gateway:~# apt install php8.1 php8.1-fpm
root@gateway:~# systemctl status php8.1-fpm
Step 5: For Nginx to process PHP files, configure your Nginx server block by updating/adding the server section:
root@gateway:~# 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;
}
}
Step 6: Restart the Nginx service.
Step 7: Install the php8.1 needed packages.
To check installed version of PHP and set the needed PHP version.
root@gateway:~# update-alternatives --config php
To confirm the PHP version:
root@gateway:~# php -v
root@gateway:~# nano /var/www/html/info.php
<?php
phpinfo();
?>
Related Articles: