How to Install and Run PHP 8.x on Ubuntu 20.04

Hello dev, Today we are going to learn How to Install and Run PHP 8.x on Ubuntu 20.04. This tutorial will cover on installing and running PHP 8.x on ubuntu 20.04.

This example is focused on Ubuntu 22.04 on Install and Use PHP 8.x. In this article, we will implement a Steps to Install PHP 8.x on Ubuntu 22.04. you will learn How to Install and Configure PHP 8.x on Ubuntu 22.04?. you will learn Easy Way to Install PHP 8.x on Ubuntu 22.04. you will do the following things for Using Commands to Install PHP 8.x on Ubuntu 20.04.

Steps on How to Install and Run PHP 8.x on Ubuntu 20.04:

  • Step 1: Update System Dependencies
  • Step 2: Add PHP PPA
  • Step 3: Install PHP 8.x for Apache
  • Step 4: Install PHP 8.x Extensions
  • Step 5: Verify PHP Version
  • Step 6: Configure PHP 8.x
  • Step 7: Conclusion

Also Read: Laravel 9 Vue JS Form Validation Example

Step 1: Update System Dependencies

First we are going to update system dependencies. Run the following command at a command prompt to update the latest packages or dependencies.

sudo apt update
sudo apt upgrade

Step 2: Add PHP PPA

Now in this step we are adding PHP PPA. Using following command to install PHP 8.1.

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

Also Read: Laravel Vue 3 File Uploading with Progress Bar using Vite Example

Step 3: Install PHP 8.x for Apache

Step three is to install PHP 8.x for apache. Execute the following command on command prompt to install PHP 8.1.

sudo apt install php8.1

To confirm the installation using the following command.

php -v

Step 4: Install PHP 8.x Extensions

Now we are going to install PHP 8.x extensions. Using the following command, we can install PHP extensions.

sudo apt install php8.1-extension_name

Now, install some commonly used php-extensions with the following command.

sudo apt install php8.1-common php8.1-mysql php8.1-xml php8.1-xmlrpc php8.1-curl php8.1-gd php8.1-imagick php8.1-cli php8.1-dev php8.1-imap php8.1-mbstring php8.1-opcache php8.1-soap php8.1-zip php8.1-redis php8.1-intl -y

Also Read: How to Remove a Specific Element From an Array in PHP

Step 5: Verify PHP Version

Now we are going to verify php version. Using the following command, we can easily verify PHP version.

php -v

Output:

PHP 8.1.5 (cli) (built: JULY 28 2022 10:32:13) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.5, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.5, Copyright (c), by Zend Technologies

Also Read: Laravel 9 Vue JS CRUD App using Vite Example

Step 6: Configure PHP 8.x

Last step is to configure PHP 8.x. Execute the following command on command prompt to edit php.ini

sudo nano /etc/php/8.1/apache2/php.ini

Hit F6 for search inside the editor and update the following values for better performance.

upload_max_filesize = 32M 
post_max_size = 48M 
memory_limit = 256M 
max_execution_time = 600 
max_input_vars = 3000 
max_input_time = 1000

Then execute the following command on command prompt to restart apache web server.

sudo service apache2 restart

Step 7: Conclusion

Today, We had learn How to Install and Run PHP 8.x on Ubuntu 20.04. Hope this tutorial helped you with learning Ubuntu. If you have any question you can ask us at comment section below. If you like the tutorial please subscribe our YouTube Channel and follow us on social network Facebook and Instagram.

Also Read: How to Install and Configure phpMyAdmin in Ubuntu 22.04

3 Comments

Leave a Reply