Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Programming»PHP»How to Install PHP 8 on Ubuntu 20.04

    How to Install PHP 8 on Ubuntu 20.04

    By RahulSeptember 12, 20214 Mins Read

    PHP is an acronym of “Hypertext Preprocessor” is a scripting language widely used for developing web applications. It is the server-side scripting language that is embedded in HTML. Which is used to manage dynamic content, databases, session tracking, even build entire e-commerce websites.

    Advertisement

    PHP 8.0 is the latest stable version available for production use. The debian packages for PHP 8 is available under ppa:ondrej/php PPA for Ubuntu systems.

    In this tutorial, you will learn the following.

    1. Install PHP 8 on Ubuntu
    2. Install PHP 8 Extensions
    3. Setup PHP 8 with Apache
    4. Setup PHP 8 with Nginx
    5. Switch between multiple PHP versions

    So, let’s begin with a tutorial to install and Use PHP 8.0 on Ubuntu 20.04 LTS Focal system.

    Step 1 – Install PHP 8 on Ubuntu

    The Ondrej PHP PPA is always up to date and contains the latest PHP versions. Use the following commands to add PPA and install PHP 8.0 on Ubuntu 20.04 system.

    1. Firstly, you need to install a required package on your system. Open a terminal and execute the following commands.
      sudo apt update && sudo apt install software-properties-common -y 
      
    2. Enable PPA – Next, Use the following command to enable PHP PPA and update apt cache
      sudo add-apt-repository ppa:ondrej/php 
      
    3. Install PHP 8 – Next, Type below command to install the PHP 8.0 on Ubuntu system.
      sudo apt install php8.0 
      

      Press ‘Y’ for any confirmation asked by the installer.

    Once completed the above commands, you have successfully installed PHP 8.0 on the Ubuntu system.

    Step 2 – Installing PHP Extensions

    Now, install the required PHP modules for your application. Use the following command to search all available PHP 8.0 modules.

    sudo apt search php8.0-* 
    

    Then install the required PHP modules. The following command will install some frequently used PHP modules on your system.

    sudo apt install php8.0-gd php8.0-xml php8.0-soap php8.0-mbstring php8.0-mysql 
    

    You may also need to install other PHP modules recommended by the application.

    Step 3 – Install PHP 8 with Apache

    Apache is a popular web server widely used for deploying PHP web applications. On Debian-based systems this is available with the name “apache2”.

    An Apache module is available to integrate PHP. For PHP 8.0 install the following Apache module

    sudo apt install libapache2-mod-php8.0 
    

    Then enable PHP 8 module

    sudo a2enmod php8.0 
    

    All done, now your can host a PHP application with Apache using PHP 8.

    To test the integration, create a phpinfo() file and verify the version.

    Step 4 – Install PHP 8 with Nginx

    There is no official PHP module for the Nginx server. In that case, we will use PHP-FPM to deploy PHP applications over Nginx web servers.

    So, first, install PHP fpm on your system.

    sudo apt install php8.0-fpm 
    

    Once the installation is finished, enable and start the service.

    sudo systemctl enable php8.0-fpm 
    sudo systemctl start php8.0-fpm 
    

    Next, update the Nginx server block configuration with the following code.

    server {
    
       # server block code ...
    
        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/run/php/php8.0-fpm.sock;
        }
    }
    

    The above code instructs the Nginx server to process all files with the “.php” extension using PHP-fpm.

    Finally, restart the Nginx webserver to apply the changes.

    sudo systemctl restart nginx 
    

    Step 5 – Switch Default PHP Version

    You can easily switch between multiple PHP version installed on any system. Execute the following command on terminal:

    sudo update-alternatives --config php  
    

    This system has PHP 8.0 and PHP 7.4 installed. Select a PHP version on our choice.

    There are 2 choices for the alternative php (providing /usr/bin/php).
    
      Selection    Path             Priority   Status
    ------------------------------------------------------------
    * 0            /usr/bin/php8.0   80        auto mode
      1            /usr/bin/php7.4   74        manual mode
      2            /usr/bin/php8.0   80        manual mode
    
    Press  to keep the current choice[*], or type selection number: [ENTER CHOICE HERE]
    

    Conclusion

    This tutorial helps you to install PHP 8.0 on Ubuntu 20.04 Linux system. You may also need to install MySQL on your Ubuntu system.

    PHP PHP 8 PHP 8.0
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    Installing PHP on Pop!_OS

    How to Install PHP 8.x on Pop!_OS

    Managing Dependencies with Composer: A Beginner’s Guide

    10 Simple Ways to Speed Up Your WordPress Website

    10 Simple Ways to Speed Up Your WordPress Website

    View 11 Comments

    11 Comments

    1. cesar on April 3, 2022 3:11 pm

      Thank you.
      Obrigado !

      Reply
    2. Sukhveer Singh on December 2, 2021 7:00 pm

      It saved my day. Thankyo so much.

      Reply
    3. markus on September 12, 2021 11:12 am

      Typo:

      sudo add update && sudo apt install software-properties-common -y

      should be:

      sudo apt update && sudo apt install software-properties-common -y

      Reply
      • Rahul on September 12, 2021 11:50 am

        Thanks markus, Typo has been corrected.

        Reply
    4. Giovanny on July 28, 2021 5:26 pm

      How to install GD extension in ubuntu 20.10?

      Reply
    5. 8ctopus on July 7, 2021 6:12 am

      sudo apt install software-properties-common needs to be installed before you can add the repository

      Reply
      • Rahul on July 7, 2021 8:52 am

        Thaks, tutorial has been updated accordingly.

        Reply
    6. Raja on June 10, 2021 4:35 pm

      Excellent..It was too helpful

      Reply
    7. Pronay on May 21, 2021 4:57 pm

      Great Exploration and I have successfully Upgraded to PHP 8.0 from PHP 7.4

      Reply
    8. Ganesh Ghalame on April 29, 2021 4:56 am

      sudo a2enmode php8.0 spelling mistake needs to be sudo a2enmod php8.0

      Reply
      • Rahul on May 6, 2021 4:15 am

        Thanks Ganesh

        Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • How to Split Large Archives in Linux using the Command Line
    • System.out.println() Method in Java: A Beginner’s Guide
    • Split Command in Linux With Examples (Split Large Files)
    • Test Your Internet Speed from the Linux Terminal
    • 11 Practical Example of cat Command in Linux
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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