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 Generate PDF From HTML View In Laravel
How Generate PDF From HTML Vie...

In this example, I will teach you how to generate PDF files from an HTML view in laravel. For generating PDF files I wil...

Read More

Jun-01-2020

How To Check Email Already Exist Or Not In Laravel
How To Check Email Already Exi...

In this article, we will show how to check whether the email already exists or not in laravel. Also, we will check...

Read More

Aug-07-2020

How To Store Backup On Dropbox In Laravel 9
How To Store Backup On Dropbox...

In this article, we will see how to store the backup on dropbox in laravel 9. Here, we will learn to store database...

Read More

Jan-16-2023

Send Email In Laravel
Send Email In Laravel

In this article, we will explore the process of sending emails in Laravel, covering versions 6, 7, 8, 9, and 10. Email f...

Read More

Sep-02-2020