How To Downgrade PHP 8 to 7.4 in Ubuntu

Websolutionstuff | Aug-04-2023 | Categories : Other

As a web developer, I understand the significance of embracing the latest technologies to stay ahead in the dynamic world of web development. PHP 8 undoubtedly caught my attention with its impressive performance improvements and cutting-edge features. Excited to explore its potential, I upgraded my Ubuntu machine to PHP 8 to take advantage of its benefits.

However, in this journey, I encountered a few compatibility issues with existing codebases and certain software dependencies.

It became clear that a rollback to a more stable environment, like PHP 7.4, was necessary to ensure a seamless development experience.

If you, too, find yourself facing similar challenges and wish to revert from PHP 8 to PHP 7.4 on your Ubuntu system, fear not! In this article, I will share my step-by-step guide on how I accomplished this version downgrade.

Whether you're a seasoned developer or just starting your coding journey, I hope my instructions will help you navigate this process with ease.

While PHP 8 offers exceptional enhancements, I found PHP 7.4 to be a popular and reliable choice among developers, backed by its mature ecosystem and extensive support for various projects.

Through this article, I aim to provide a comprehensive approach to downgrading PHP versions while minimizing any potential disruptions.

So, if you're ready to explore the process of reverting to PHP 7.4, join me as we dive into the world of version management on your Ubuntu server or local machine.

By the end of this article, I hope you'll gain the confidence to make informed decisions regarding your PHP setup and ensure your web applications continue to run smoothly.

Let's get started how to downgrade php 8 to 7.4 in Ubuntu, how to downgrade PHP version in Ubuntu, how to downgrade PHP version in XAMPP, switch php 8 to 7.4 Ubuntu, and how to change php version in Ubuntu.

Step 1: Check Current PHP Version

Before starting the downgrade, check the current PHP version on your Ubuntu system using the following command.

php -v

This will display the installed PHP version.

 

Step 2: Enable PHP 7 Repository

Next, you’ll need to add the repository for PHP 7 to your system. if you have already installed PHP 7 in your system then ignore this step. So, run the following command.

sudo apt update 
sudo apt install software-properties-common 
sudo add-apt-repository ppa:ondrej/php 
sudo apt update

 

Step 3: Install PHP 7

Once the repository for PHP 7 has been added to your system, you can install it using the following command.

sudo apt install php7.4

 

Step 4: Set PHP 7 as Default

Ubuntu allows us to install and use multiple PHP versions on a single system. You can easily set any version as the default without uninstalling others.

sudo alternatives --config php

This will show you a list of installed PHP versions as below.

There are 2 choices for the alternative php (providing /usr/bin/php).

  Selection    Path             Priority   Status
------------------------------------------------------------
* 0            /usr/bin/php8.1   81        auto mode
  1            /usr/bin/php7.4   74        manual mode
  2            /usr/bin/php8.1   81        manual mode
Press <enter> to keep the current choice[*], or type selection number:

Enter the selection number to make any PHP version as default. For example, to set PHP 7.4 as default, input “1” and hit enter.

 

Step 5: Check the installed version of PHP

To verify that PHP 7 has been installed, run the following command.

php -v

This should display the version of PHP that is currently installed on your system.

PHP 7.4.33 (cli) (built: Nov  8 2022 11:33:35) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.33, Copyright (c), by Zend Technologies

 

Step 6: Configure PHP 7

Then, need to configure PHP 7 to work with your system and applications. You can do this by editing the php.ini file using the following command.

sudo nano /etc/php/7.4/cli/php.ini

You can make any necessary changes to the file and then save it.

 

Conclusion:

In conclusion, Ubuntu's flexibility in accommodating multiple PHP versions on a single system provides web developers with a powerful tool to manage their PHP environments efficiently. The ability to switch between different PHP versions without the need for uninstallation enables seamless testing and development across various projects.

The step-by-step guide presented in this article has demonstrated the straightforward process of downgrading PHP from version 8 to version 7.4 on an Ubuntu machine.

 


You might also like:

Recommended Post
Featured Post
How To Get Current Week Records In MySQL
How To Get Current Week Record...

In this tutorial, we will see how to get current week records in MySQL. Many times we need to get current week reco...

Read More

Feb-07-2022

Laravel 9 Where Condition Example
Laravel 9 Where Condition Exam...

In this article, we will see laravel 9 where condition example. Where condition is essential in each and every quer...

Read More

Oct-12-2022

Laravel 9 Livewire Image Upload Example
Laravel 9 Livewire Image Uploa...

In this article, we will see the laravel 9 livewire image upload example. Here, we will learn how to upload an imag...

Read More

Dec-01-2022

Paypal Payment Gateway Integration In Laravel 8
Paypal Payment Gateway Integra...

In this tutorial, we will see paypal payment gateway integration in laravel 8. Paypal is an international payment p...

Read More

Jan-10-2022