How to Install PHP 8.0 on Ubuntu 20.04

how to install php 8.0 on ubuntu 20.04

PHP 8.0 is officially released on November 26, 2020 it is a major update of PHP programming language. PHP 8.0 contains lots of optimizations and new features like error handling, match expression, constructor property promotion, attributes, consistency, union types, JIT, type system improvement, named arguments, null safe operator and more. Let’s see how to install PHP 8.0 on ubuntu 20.04

In this tutorial we are going to see how to install php 8.0 on ubuntu 20.04. Let’s start the PHP 8.0 installation tutorial.

Add Ondřej Surý ppa:

Before installing PHP 8.0 add the Ondřej Surý PPA to your Ubuntu 20.04. Run the below command to add the Ondřej Surý PPA repository.

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

Update the Packages:

Before starting the PHP 8.0 installation we have to update the ubuntu packages. Run the below command to update the Ubuntu packages.

sudo apt-get update

Install PHP 8.0 with Apache:

To install PHP 8.0 with Apache modules run the command below.

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

This will install PHP 8.0 with Apache on your Ubuntu 20.04.

To Install Apache Web Server on Ubuntu 20.04.

Check Status of PHP8.0:

After the successful installation check the version of PHP.

php -v

Output:

PHP 8.0.0 (cli) (built: Nov 27 2020 12:26:22) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.0, Copyright (c), by Zend Technologies

Install PHP 8.0 with Nginx:

To install PHP 8.0 with Nginx we need to install with FPM. To install php8.0 and php FPM on Ubuntu 20.04 run the commands below.

Before installing PHP 8.0 on Ubuntu 20.04 update the Ubuntu packages.

sudo apt-get update

Now install PHP 8.0 FPM with Nginx web server.

sudo apt install php8.0-fpm

This will install PHP 8.0 FPM on your Ubuntu 20.04 server

Check Status of PHP 8.0:

After the successful installation check the version of PHP.

php -v

Output:

PHP 8.0.0 (fpm-fcgi) (built: Nov 27 2020 12:26:22)
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.0, Copyright (c), by Zend Technologies

Install PHP 8.0 Extensions:

After the PHP 8.0 installation install the extensions for PHP 8.0. To install the PHP 8.0 extensions on your Ubuntu 20.04 run the command below.

sudo apt install php8.0-common php8.0-mysql php8.0-xml php8.0-curl php8.0-imap php8.0-mbstring php8.0-opcache php8.0-cli php8.0-dev php8.0-soap

Above command will install the PHP 8.0 extensions on your Ubuntu 20.04.

If you want to install any PHP 8.0 extension copy the below command and change the [EXTENSION NAME] section to your preferred PHP 8.0 extension.

sudo apt install php8.0-[EXTENSION NAME]

Update to PHP8.0  on Apache:

After the PHP 8.0 installation update the PHP version in Apache.

sudo update-alternatives --config php

Now select the PHP 8.0 version and hit enter.

After selecting PHP 8.0 now disable the older version of php

sudo a2dismod php7.*

Now enable the PHP 8.0 on your Ubuntu 20.04.

sudo a2enmod php8.0

After that restart the Apache web server

sudo service apache2 restart

Update to PHP 8.0 on Nginx:

After the PHP 8.0 installation update the PHP version in Nginx.

sudo update-alternatives --config php

Now select the PHP 8.0 version and hit enter.

After that restart the Nginx web server.

sudo service nginx restart

Now restart the PHP 8.0 FPM.

sudo service php8.0-fpm restart

After restart PHP 8.0 FPM now edit the Nginx configuration and change the FPM socket from old version to PHP 8.0.

fastcgi_pass unix:/run/php/php8.0-fpm.sock; 

Test PHP:

Now go to your browser then access your ip_address or domain name.

That’s all we have finished the PHP 8.0 installation.

Conclusion:

In this tutorial we have learned how to install PHP 8.0 on Ubuntu 20.04 and how to update older PHP version to PHP 8.0 with Apache and nginx web server. Hope this tutorial helps.

Next Article: How to Install PHP on Ubuntu 20.04

Leave a Reply

Post your comments here

You May Also Like