PHP stands for Hypertext Preprocessor. PHP is a popular server scripting language used to create dynamic and interactive web pages. It is a server-side-based scripting language that is widely used for development. PHP is developed by Rasmus Lerdorf in 1994. Now PHP is maintained by the official PHP Development Team.
Advantages of PHP
- Open-source – PHP is open-source. It means we can modify it as per your requirement.
- Flexible – PHP is flexible enough to connect to almost all databases due to its open-source nature.
- Quick– A performance advantage of PHP is that it runs in its own memory space. Furthermore, PHP uses the Zend engine to parse PHP code and interpret it into opcodes.
- Simple – PHP is very simple to understand
- PHP supports almost every operating system such as macOS, Linux, and Windows.
New key features witnessed in the PHP 8.2 release:
- New mysqli_execute_query Function and mysqli::execute_query Method
- Read-only Classes
- Disjunctive Normal Form (DNF) Types
- Fetch enum Properties in const Expressions
- Allow true, false, and null as Standalone Types
- Allow Constants in Traits
- Redact Sensitive Parameters in Back Traces
- New Random Extension and many more.
In today’s tutorial, we’ll show you how to download, install and set up PHP 8.2 on Ubuntu 22.04 via the command line
- Ubuntu 22.04 Operating System
- Root user or another user with Sudo privileges
These are the most commonly used PHP modules for connecting PHP with different types of applications. For example, the PHP module MySQL is used for connecting PHP to MySQL.
curl fpm opcache mbstring ldap mysql imap xml intl gd cli imagick zip
Update the server
Update all the repositories on the server with the following command.
sudo apt update -y
Enable the PPA Repository
Default repositories do not include the PHP version. Therefore, we must use a third-party PPA repository. Run the following command to enable the repository.
sudo apt install software-properties-common -y sudo add-apt-repository ppa:ondrej/php -y
After adding the repository, we need to update the repository on the server with the following command.
sudo apt update -y
Install the PHP 8.2 package
To install PHP 8.2 with mostly used PHP modules, use the following command.
sudo apt install php8.2 php8.2-opcache php8.2-xml php8.2-mbstring php8.2-ldap php8.2-curl php8.2-imap php8.2-zip php8.2-mysqli php8.2-intl php8.2-gd php8.2-cli php8.2-imagick php8.2-fpm libapache2-mod-php8.2 -y
To check the default PHP version, run the following command.
To check all the installed PHP modules, run the following command.
Switch between Multiple PHP versions
In case of multiple PHP versions installed on the server or local system, follow the below steps to change the default PHP version.
- First, we need to disable the default PHP version. As an example, our server has PHP 8.0 as the default PHP version and we need to change it from PHP 8.0 to PHP 8.2.
sudo a2dismod php8.0
- After disabling the default PHP version. Now we need to set PHP 8.2 as the default PHP version
sudo a2enmod php8.2
- Set the PHP version.
sudo update-alternatives --set php /usr/bin/php8.2
- Now, we need to update the default PHP version globally with the following command.
sudo update-alternatives --config php
In today’s tutorial, we have learned about PHP 8.2 and how we can install PHP 8.2 on Ubuntu 22.04 with a few simple steps. We have also learned how we can easily switch between multiple PHP versions. You guys can follow the same to install PHP 8.2 on Ubuntu 20.04 and Ubuntu 18.04.
Thank you for your time. Please leave a comment below if you have any issues or suggestions.