How to Install PHP 7.4 on Ubuntu 22.04
Ubuntu 22.04 may not come with PHP 7.4 pre-installed in its default repositories. However, you can easily install PHP 7.4 on Ubuntu 22.04 by adding the PHP repository maintained by Ondřej Surý, which provides the latest PHP versions for Ubuntu users. This guide will walk you through the steps to install PHP 7.4 on Ubuntu 22.04 and configure it for your development or production environment.
Step 1: Add PHP Repository To add the PHP repository containing PHP 7.4, open a terminal and run the following command:
sudo add-apt-repository ppa:ondrej/php
Step 2: Update Package List After adding the repository, update the package list to include the newly added PHP repository:
sudo apt update
Step 3: Install PHP 7.4 Now, you can install PHP 7.4 and the necessary PHP extensions using the following command:
sudo apt install php7.4
Step 4: Install PHP Extensions (Optional) If you require additional PHP extensions for your projects, you can install them along with PHP 7.4. For example, to install commonly used extensions like MySQL, XML, JSON, MBString, and GD, run the following command:
sudo apt install php7.4-common php7.4-mysql php7.4-xml php7.4-json php7.4-mbstring php7.4-gd php7.4-curl
Step 5: Check PHP Version After the installation is complete, verify that PHP 7.4 is installed successfully by running the following command:
php -v
Step 6: Switch PHP Version (Optional) If you have multiple PHP versions installed on your system and you want to switch between them, you can use the update-alternatives
command. This command will list all installed PHP versions and allow you to choose the default one:
sudo update-alternatives --config php
Conclusion: By following these simple steps, you can easily install PHP 7.4 on Ubuntu 22.04 and configure it for your development or production environment. PHP 7.4 offers various performance improvements, new features, and security enhancements, making it a recommended choice for PHP developers. Upgrade to PHP 7.4 today to take advantage of the latest improvements and ensure compatibility with modern PHP applications.