
PHP is a most popular server scripting language used for creating dynamic and interactive Web pages. PHP is widely-used programming language in the Web. This tutorial explains how to install PHP 8.2 on Ubuntu 22.04
By default, Ubuntu 22.04 ships with PHP version 8.2, which is supported by the most popular CMS and frameworks such as WordPress, Magento, and Laravel.
Step 1 – Prerequisites
Before start installation, make sure your are logged in as root or user with sudo privileges.
Step 2 – Update system
Update the package index list, it’s recommend to update software repositories and install packages to sync with latest releases.
sudo apt update && sudo apt upgrade
Step 3 – Install PHP on Ubuntu
At this step your system is up to date and ready to install PHP. Run the following command to install PHP 8.2.
Installing PHP with Apache
For Apache web server to install PHP and Apache PHP module run the following commands:
sudo apt install php8.2 php-common libapache2-mod-php
Installing PHP with Nginx
By default, Nginx doesn’t have a built-in support for processing PHP files. So we need to use PHP FPM service to handle the PHP files.
sudo apt install php8.2 php-common php-fpm
After that, you need to edit domain Nginx server block and add following lines to work PHP file using Nginx:
server { # . . . other code location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php8.2-fpm.sock; } }
Save the configuration file and restart the nginx service for the new configuration take effect:
sudo systemctl restart nginx
Step 4 – Installing PHP Extensions
You can install PHP extensions as per requirements. Run below command to install most common PHP extensions required for basic usage.
sudo apt install php8.2-cli php8.2-json php8.2-pdo php8.2-mysql php8.2-zip php8.2-gd php8.2-mbstring php8.2-curl php8.2-xml php8.2-pear php8.2-bcmath
Step 5 – Testing PHP
Once the installation complete, you can verify version by typing:
php --version
PHP 8.2.0(cli) (built: Jan 15 2023 12:31:45) ( NTS ) Copyright (c) The PHP Group Zend Engine v4.2.0, Copyright (c) Zend Technologies with Zend OPcache v8.2.0, Copyright (c), by Zend Technologies
Conclusion
This tutorial explained how to install PHP 8.2 on Ubuntu 22.04 and configure your web server to process files.
If you have any questions or suggestion, please leave a comment below.
Leave a Reply