How to Upgrade PHP 7.4 to 8.0 in Ubuntu

Websolutionstuff | Nov-06-2023 | Categories : PHP

Hey there! I recently faced the need to upgrade my PHP version from 7.4 to the latest 8.0 on my Ubuntu server. It might seem like a daunting task, but don't worry; I'm here to guide you through each step. Keeping your server up-to-date is crucial for security and performance, and I'll show you how to make the transition to PHP 8.0 a breeze.

Let's get started with the upgrade!

Upgrading PHP from version 7.4 to 8 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 7.4. You can check your current PHP version using the command:

php -v

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

 

Step 2: Add PHP 8 Repository

To upgrade to PHP 8, you need to add the repository for PHP 8. 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 and the necessary PHP modules. Use the following command:

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

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

 

Step 4: Verify PHP 8 Installation

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

php -v

It should display PHP 8.x.

 

Step 5: Remove PHP 7.4 (Optional)

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

sudo apt-get purge php7.4-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 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. For Apache, you can use the following command to enable the PHP 8 module:

For Apache:

sudo a2enmod php8.0

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

 

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 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 information.

 

Step 9: Cleanup

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

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

 


You might also like:

Recommended Post
Featured Post
How To Generate Barcode Using Javascript
How To Generate Barcode Using...

In this article, we will see how to generate barcode using javascript. We will use a javascript plugin to generate...

Read More

Nov-01-2022

How To Change Text In Laravel 9 Datatable
How To Change Text In Laravel...

Do you want to learn how to change text in a Laravel 9 Datatable? This blog post is your complete guide to mastering tex...

Read More

Jan-06-2023

How to Build a Blog CMS with React JS?
How to Build a Blog CMS with R...

Are you a blogger who expresses his thoughts with the help of words? If yes, then you might have once thought to create...

Read More

Nov-13-2023

Skype Screen Sharing Not Working Ubuntu In 22.04
Skype Screen Sharing Not Worki...

In this article, we will see skype screen sharing is not working in ubuntu 22.04. When you install skype in ubuntu...

Read More

Feb-15-2023