How to migrate to PHP 8.0 on Ubuntu

This brief tutorial shows students and new users how to migrate to PHP 8.0 to run your projects.

This post assumes that you’re running your app on PHP version 7.4 or earlier and you want to upgrade to PHP 8.0.

Anytime you’re upgrading PHP you’ll want to make sure that the version you’re upgrading to is compatible with your apps.

You’ll also want to take notes of all the PHP modules that are installed and running currently to support your projects. You’ll definitely want to make sure that current modules installed have corresponding versions with the latest PHP.

When all the boxes are checked and you’re ready to migrate, follow the steps below to get it done.

For student or new user looking for a Linux system to start with, the easiest place to start is Ubuntu Linux OS. It’s a great Linux operating system for beginners and folks looking for easier Linux distribution to use.

Ubuntu is an open source Linux operating systems that runs on desktops, laptops, server and other devices.

To get started, follow the steps below:

Find out installed PHP modules

Before you can upgrade, go and currently installed PHP modules. You’ll want to make sure you install the same modules for the latest PHP version.

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

dpkg --get-selections | grep -i php

That should list similar lines 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 that you know what PHP modules are installed, run go and do the same for the latest PHP version.

Install PHP 8.0

At the time of this writing, Ubuntu did not have PHP 8.0 packages available in its default repositories.

In order to install PHP 8.0 on Ubuntu you may have to add third-party repositories and install from there.

Simply run the commands below to add the below repository to Ubuntu.

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

Then update and upgrade to PHP 8.0-FPM

sudo apt update

Next, run the commands below to install PHP 8.0-FPM and 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 modules, run the commands below to open to restart PHP.

sudo systemctl restart php8.0-fpm.service

PHP 8.0 is installed and ready to be use.

Use PHP 8.0 with Nginx

If you’re running Nginx web server and you want to use PHP 8.0 use the steps below:

Ubuntu default site configuration file can be found at

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

Then edit the 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;

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

After that, restart Nginx HTTP server to use PHP 8.0-FPM.

sudo systemctl restart nginx.service

Use PHP 8.0 with Apache

To use PHP 8.0 with Apache instead, use the steps below:

For Apache2 you’ll want to run the commands below along with the installed modules above.

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

Then run the commands below to disable PHP 7.4 or the previous version installed.

sudo a2dismod php7.4

Now that PHP 7.4 is disabled, run the commands below to enable PHP 8.0.

sudo a2enmod php8.0

After enabling PHP 8.0, run the commands below to restart Apache2 and PHP 8.0 should be used to support WordPress.

sudo systemctl restart apache2.service

That’s it!


This post showed you how to migrate your app to PHP 8.0 from a previous version.

If you find any error above, please use the form below to report.

You may also like the post below: