Facebook X (Twitter) Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook X (Twitter) Instagram
    TecAdmin
    You are at:Home»Programming»PHP»Downgrading PHP 8 to PHP 7 on Ubuntu: A Step-by-Step Guide

    Downgrading PHP 8 to PHP 7 on Ubuntu: A Step-by-Step Guide

    By RahulFebruary 9, 20232 Mins Read

    PHP is a popular server-side scripting language used for web development. With the release of PHP 8, many developers have upgraded their systems to take advantage of its new features. However, some developers have found that the latest version is not compatible with their existing applications or systems. In such cases, downgrading to an earlier version of PHP can be an effective solution.

    In this article, we’ll provide a step-by-step guide to downgrading from PHP 8 to PHP 7 on Ubuntu.

    Step 1: Enable PHP 7 repository

    Next, you’ll need to add the repository for PHP 7 to your system. To do this, you’ll need to run the following commands:

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

    Step 2: 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 3: Set PHP 7 as Default

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

    sudo alternatives --config php 
    

    This will show you a list of install PHP version as below:

    1
    2
    3
    4
    5
    6
    7
    8
    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 4: 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.

    Output
    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 5: Configure PHP 7

    Finally, you’ll 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.

    In conclusion, downgrading from PHP 8 to PHP 7 on Ubuntu can be a straightforward process if you follow these steps carefully. By downgrading, you can ensure that your existing applications and systems continue to work as expected, while taking advantage of the stability and compatibility offered by PHP 7.

    Downgrade php PHP PHP 7 PHP 8
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    How to Disable Functions in PHP

    How to Schedule a Cron Job for PHP: A Step-by-Step Guide

    How to Compare Two Array Values in PHP: A Practical Guide

    View 2 Comments

    2 Comments

    1. Brian on August 16, 2023 2:22 pm

      The PPA is not working do you have an update? I need to downgrade my php version.

      Regards
      Brian

      Reply
      • Rahul on August 17, 2023 4:17 am

        Hi Brian,

        Which Ubuntu version are you running?

        Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Using .env Files in Django
    • Using .env File in FastAPI
    • Setting Up Email Notifications for Django Error Reporting
    • How to Enable Apache Rewrite (mod_rewrite) Module
    • What are Microservices?
    Facebook X (Twitter) Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.