How to Upgrade Latest PHP 8.1 from PHP 8.0

Recently PHP released the latest stable version PHP 8.1.0 (PHP 8.1). In this tutorial, we are going to show you the steps to upgrade the latest version of PHP from the older version PHP 8.0. PHP is a very popular language and over the internet, almost 40+% is WordPress websites, based on PHP language.

WordPress recommends upgrading to the latest version for security reasons. However, this version doesn’t have any major changes, and if you don’t upgrade to PHP 8.1 then it is okay.

Manual Installation/Upgradation PHP 8.1 on Linux Server

This method will be for Dedicated servers and Desktops that are based on Linux operating system (Ubuntu or Debian-based distros). You can use the same commands for all Linux distros, which are based on Debian or Ubuntu in a few steps.

Must Read: How to Upgrade PHP 8.0 from PHP 7.4 [cPanel or VPS Server] 

Step – 1. Update You System

Use the following command to update your system dependencies and repositories, so you can install the latest stable version of PHP.

sudo apt update

Step – 2. Add Latest PHP 8.1 Package Dependency

After updating system dependencies using the command mentioned above, and now you must run the following commands to update your server with the latest PHP dependency.

You must know which Linux distro you are using as a server. Nowadays most the dedicated or VPS server provide Ubuntu or Debian-based server so, check your system and use the following command accordingly.

For Ubuntu 21.04, 20.04, 18.04:

sudo add-apt-repository ppa:ondrej/php
sudo apt update

For Debian 11, 10, 9:

sudo apt install -y gnupg2 ca-certificates apt-transport-https software-properties-common
wget -qO - https://packages.sury.org/php/apt.gpg | sudo apt-key add –
echo "deb https://packages.sury.org/php/ buster main" | sudo tee /etc/apt/sources.list.d/php.list
sudo apt update

Step – 3. Install PHP 8.1

After updating the latest PHP dependencies and repositories, use the following command to install PHP 8.1 to the server.

sudo apt install php8.1
sudo apt install php8.1-common php8.1-cli
php 8.1 update on linux server

After using the following command you will see a prompt like this, and you have to type “Y” and then hit enter on the keyboard to install the PHP.

Step – 4. Check Installed Version of PHP

After the completion of the installation of the latest PHP 8.1, you can check whether it was successfully installed or not.

Use the following command to check:

sudo php -v
Check php 8.1 Version

Install Latest PHP 8.1 Modules/Extensions

Modules are very important for doing works with PHP, and different kinds of works will be handled by different-different PHP modules. In WordPress, you will need various PHP modules like php-mysql, php-imagick, needs for connecting with the MySQL database and handling the images on site respectively.

For installing the latest version of PHP modules or extensions using the following commands:

sudo apt install php8.1-{imagick,bz2,curl,intl,mysql,readline,xml}

How to Switch from Older PHP to Latest PHP 8.1

Possibly you are upgrading PHP on your server, and that means your server has a web server. Mostly in this case Apache web server will be installed, so we have to disable the older version of PHP then need to enable the latest PHP 8.1.

For that you have to follow these commands:

Disbale the Old PHP

In case, your system has installed PHP 7.4 or lower version and you want to upgrade to the latest version, then replace php8.0 to your current version of PHP.

sudo a2dismod php8.0

Enable the Latest PHP

Now use the following command to enable the latest version of PHP using the following command:

sudo a2enmod php8.1
Note:- If you are installing PHP in your newly deplyoed system, then you don't need to switch between the PHP versions.

Restart the Apache Web server

Now, use the following command to restart or reload the Apache webserver so everything works fines without any conflicts.

sudo systemctl restart apache2.service

Conclusion

If you are a PHP developer, then this latest update would be interesting for you, check out the latest features on PHP’s official website.

If you are a WordPress website owner, then no need to upgrade, you can wait for the major update, and if you are still using an outdated version then I suggest you upgrade.


Please Support

If you like our content, please consider buying us a coffee.
Thank you for your support!

Pronay Sarkar

Hello!
I am Pronay Sarkar, I love to write about tech and stuff. I am a college graduate from the University of Delhi.

2 thoughts on “How to Upgrade Latest PHP 8.1 from PHP 8.0”

  1. Hi, Pronay,
    Thanks for the article, I was looking for the tutorial and found your article, it’s great. If you include the tutorial about cPanel, it would be more grateful.

    Reply

Leave a Comment