How to Upgrade to PHP 8.0 on Ubuntu

How to Upgrade to PHP 8.0 on Ubuntu

This post shows users and new students that how to Upgrade to PHP 8.0 on Ubuntu. If your are going to Upgrade to PHP 8.0 on Ubuntu then this post is ideal for you.

PHP 8.0 is a new version with lots of improvements and features. It will officially released on November 26, 2020.

For WordPress sites, latest version of PHP offers new features and improvements for developers. They will find useful and improvements that enhance security and performance of the PhP based application or website in the long run. 

PHP is a popular general purpose scripting programmiing language especially for the web development. It was originally developed by Danish Canadian programmer Rasmus Lerdorf in 1994. 

Ubuntu is a Linux Operating System based on Debian and mostly composed of non-profit(free) and open-source software. It is a complete Linux operating system that compatible with desktops, laptops, server and other devices. Ubuntu is Open Source so it is freely available for both community and professional support. If you are a learner and looking for a Linux distribution for Learning then Ubuntu Linux Operating System is best for you as a beginning.

For the new students and new users, this post will be useful and handy if they want to learn that how to upgrade PHP 8.0 on Ubuntu with Apache or Nginx web server.

We are assuming that your application or web is running on PHP version 7.4 or its earlier version and you wish to upgrade it to PHP 8.0.

This is important to confirm that your application is compatible with PHP Version that you want Upgrade. And make sure that you have a back-up of your application.

So now Follow below steps to start Upgrading to PHP 8.0 on Ubuntu.

Find out your installed PHP modules

To find out currently installed PHP modules, run the commands below.

Run the below commands to find out your currently installed PHP modules:

dpkg --get-selections | grep -i php

it is show a list similar lines like as below:

php-common                                      install
php7.4-bcmath                                   install
php7.4-cli                                      install
php7.4-common                                   install
php7.4-curl                                     install
php7.4-fpm                                      install
php7.4-gd                                       install
php7.4-gmp                                      install
php7.4-imagick                                  install
php7.4-json                                     install
php7.4-mbstring                                 install
php7.4-mysql                                    install
php7.4-opcache                                  install
php7.4-readline                                 install
php7.4-xml                                      install
php7.4-xmlrpc                                   install
php7.4-zip                                      install

Now you know your installed PHP modules.

Install PHP 8.0 On Ubuntu

At this time of writing that post, Ubuntu did not have PHP 8.0 modules in its default repositories. so you need to add third-party repositories and then install it from there.

For do that, Simply run the below commands to add the third-party repository to Ubuntu.

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

Now, update to PHP 8.0-FPM

sudo apt update

After that, run the below commands to install PHP 8.0-FPM and its related modules.

sudo apt install php8.0-fpm php8.0-common php8.0-mysql php8.0-gmp php8.0-curl php8.0-mbstring php8.0-json php8.0-xmlrpc php8.0-gd php8.0-xml php8.0-readline php8.0-cli php8.0-zip

After installing PHP 8.0 and its related modules, run the below commands for restart PHP.

sudo systemctl restart php8.0-fpm.service

That’s it. Now PHP 8.0 is installed and ready to use.

PHP 8.0 with Nginx

If you are running Nginx server on ubuntu and you want to use PHP 8.0 with Nginx then follow below steps :

You will be found Ubuntu default site configuration file at :

sudo nano /etc/nginx/sites-available/default

Edit the highlighted php block session:

# Add index.php to the list if you are using PHP
        index index.php index.html index.htm index.nginx-debian.html;


        # pass PHP scripts to FastCGI server
        #
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
        #
        #       # With php-fpm (or other unix sockets):
                fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one

Save and Exit config file. And restart Nginx HTTP server.

sudo systemctl restart nginx.service

PHP 8.0 with Apache2

For Apache2 you need to run the below commands with the installed modules above.

sudo apt update
sudo apt install php8.0 libapache2-mod-php8.0

Now run the below commands to disable PHP 7.4 or its previous versions that is installed.

sudo a2dismod php7.4

After disable PHP 7.4, run the below commands to enable PHP 8.0.

sudo a2enmod php8.0

 Now, run the below commands to restart Apache2.

sudo systemctl restart apache2.service

That’s all!

If you find any error and issue in above steps , please use comment box below to report.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top