How to Upgrade PHP 8.0 to 8.1 in Ubuntu

Websolutionstuff | Nov-03-2023 | Categories : PHP

Hey there! I recently needed to upgrade my PHP version from 8.0 to the latest 8.1 on my Ubuntu server. It's a smart move to keep your server and web applications in top shape with the latest features and improvements.

If you're in the same boat and looking for a straightforward guide, you're in the right place. I'm going to walk you through the entire process step by step.

Updating PHP might sound a bit daunting, but trust me, it's easier than you think. With this guide, I'll make sure you smoothly transition to PHP 8.1, so you can enjoy the benefits of the latest version without any hassle.

Let's get started with upgrading PHP 8.1 on Ubuntu!

Upgrading PHP from version 8.0 to 8.1 in Ubuntu involves several steps, including adding a new repository and installing the updated PHP version. Here's a step-by-step guide to help you with this process:

Step 1: Check Your Current PHP Version

Before upgrading, make sure you're running PHP 8.0. You can check your current PHP version using the command:

php -v

This command will display your PHP version. If it's 8.0, proceed with the upgrade.

 

Step 2: Add PHP 8.1 Repository

To upgrade to PHP 8.1, you need to add the repository for PHP 8.1. You can use the ondrej/php repository, which is a popular source for PHP updates:

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

 

Step 3: Upgrade PHP

Now, you can install PHP 8.1 and the necessary PHP modules. Use the following command:

sudo apt-get install php8.1 php8.1-common php8.1-cli

You can also install additional PHP extensions depending on your project's requirements.

 

Step 4: Remove PHP 8.0 (Optional)

You can remove PHP 8.0 if you no longer need it. Use the following command:

sudo apt-get purge php8.0-common
sudo apt-get autoremove

Removing the old version is optional and depends on your specific use case. Be sure to back up your configuration and project files before doing this.

 

Step 5: Verify PHP 8.1 Installation

After the installation is complete, check the PHP version to make sure you're now running PHP 8.1:

php -v

It should display PHP 8.1.x.

 

Step 6: Update Your Web Server Configuration

If you are using a web server like Apache or Nginx, you'll need to update the configuration to use PHP 8.1. For Apache, you can use the following command to enable the PHP 8.1 module:

For Apache:

sudo a2enmod php8.1

For Nginx, update your site configuration to use PHP 8.1.

 

Step 7: Restart Your Web Server

After updating the web server configuration, restart your web server to apply the changes:

For Apache:

sudo systemctl restart apache2

For Nginx:

sudo systemctl restart nginx

 

Step 8: Test Your PHP Configuration

Create a PHP info file to test if PHP 8.1 is functioning correctly. Use a text editor to create a file named info.php in your web server's root directory (e.g., /var/www/html/) and add the following content.

<?php
phpinfo();
?>

Access this file from your web browser (e.g., http://your-server-ip/info.php) and verify that it shows PHP 8.1 information.

 

Step 9: Cleanup

You can remove the info.php file after testing, and you may also want to remove PHP 8.0-related configuration files if you've chosen to remove the old version.

That's it! You've successfully upgraded PHP from version 8.0 to 8.1 on your Ubuntu server.

 


You might also like:

Recommended Post
Featured Post
How to Upload Image to Storage Folder in Laravel 10
How to Upload Image to Storage...

As I delve into Laravel 10, a true powerhouse in the realm of PHP frameworks, I've found it to be a game-changer for...

Read More

Sep-29-2023

Laravel 11 Livewire Form Validation Example
Laravel 11 Livewire Form Valid...

Hello, laravel web developers! In this article, we'll see how to validate forms in laravel 11 Livewire. In lara...

Read More

Jun-12-2024

How To Get Current Date And Time In Node.js
How To Get Current Date And Ti...

In this example we will see how to get current date and time in Node.js application. In Node.js date and time are handle...

Read More

Sep-01-2021

Laravel 8 Eloquent orWhereHas Condition
Laravel 8 Eloquent orWhereHas...

In this example we will see laravel 8 eloquent orWhereHas() condition. In previous example we will learn about ...

Read More

Oct-15-2021