How to Install PHP 8 on Ubuntu 22.04

If you want to install and configure the latest version of PHP in your Ubuntu Linux system; In this tutorial guide, we will show you how to install the latest PHP version such as 8.1,2,3 or so on in your Ubuntu 22.04 system or server, and configure it with Apache.

How to Install PHP 8. x (0,1,2,3 or so on) on Ubuntu 22.04

Here are some steps for installing PHP 8 with versions such as 8. x (0,1,2,3 or so on) in Ubuntu 22.04

  • Step 1 – Update System Repositories
  • Step 2 – Add PPA for PHP
  • Step 3 – Install PHP 8. x(1,2,3)
  • Step 4 – Install PHP 8. x(1,2,3) Extensions
  • Step 5 – Verify PHP Version
  • Step 6 – Configure PHP 8. x

Step 1 – Update System Repositories

Open the command line or terminal and run the following command into it to update the latest packages or dependencies on Ubuntu 22.04 system:

sudo apt update
sudo apt upgrade

Step 2 – Add PPA for PHP

Run the following command to install or add PPA for PHP:

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

Only add this if we are about to install a PHP version other than version 8.1.

Step 3 – Install PHP 8. x(1,2,3)

To install PHP 8.1 on an Ubuntu machine, you can use the following commands:

sudo apt install php8.1 -y

To install PHP 8.2 on an Ubuntu machine, you can use the following commands:

sudo apt install php8.2 -y

Once the installation has been completed, we can confirm the installation using the following command:

php -v

Step 4 – Install PHP 8. x(1,2,3) Extensions

Using the following command, you can install PHP extensions:

sudo apt install php8.1-extension_name

To install PHP 8.1 extensions on an Ubuntu machine, you can use the following commands:

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

To install PHP 8.2 extensions on an Ubuntu machine, you can use the following commands:

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

Step 5 – Verify PHP Version

Once you have installed php in your system as per your required version such as 8.1,2,3, or so on. So you can use this command and check your version.

php -v
Output
PHP 8.1.5 (cli) (built: Apr 21 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

Step 6 – Configure PHP 8. x

This step is very important. It helps to configure php step by step as per your system.

To configure PHP, you need to modify the php.ini file. You can use the following command for that:

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

Finally run the following command on the terminal to restart Apache web server:

sudo service apache2 restart

Conclusion

This tutorial taught us how to install PHP 8.1,2,3 or so on versions on your Ubuntu 22.04 server for Apache.

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

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