PHP, or Hypertext Preprocessor, is a widely-used, versatile, and powerful server-side scripting language designed for web development. It enables developers to create dynamic web pages by embedding PHP code within HTML documents. Over the years, PHP has evolved to be one of the most popular languages for web development, powering millions of websites, including popular platforms such as WordPress, Joomla, and Drupal.
In this introduction, we will explore the following key aspects of PHP:
- Open Source: PHP is an open-source language, meaning it is freely available for use, modification, and distribution. This allows for a large community of developers to collaborate and contribute to its development, ensuring continuous improvements and updates.
- Cross-Platform Compatibility: PHP can run on various platforms such as Windows, Linux, and macOS, making it a versatile choice for web developers.
- Ease of Use: PHP is known for its simplicity and ease of use, allowing even beginners to start developing web applications quickly.
- Scalability: PHP is highly scalable and can handle a large number of users and traffic, making it suitable for both small and large-scale web applications.
- Strong Community Support: PHP has a vibrant and active community, providing extensive documentation, tutorials, and online resources for learning and troubleshooting.
- Object-Oriented Programming: PHP supports object-oriented programming (OOP), which allows for the creation of reusable, modular, and maintainable code.
- Frameworks: PHP has a wide range of robust and reliable frameworks, such as Laravel, Symfony, and CodeIgniter, that speed up development time and provide a structured environment for building web applications.
The upcoming guide will demonstrate how to install PHP on Linux Mint 21 or Linux Mint 20 using the default repository associated with Linux Mint. For most developers and advanced users who want to install PHP on Linux Mint using the well-known and popular Ondrey Sury Launchpad PPA for the latest versions of PHP 8.2, 8.1, 8.0, detailed instructions will also be provided.
Table of Contents
Section 1: Install PHP with Linux Mint Repository
This section will walk you through installing PHP on Linux Mint using the default repository. We will cover each step in detail, explaining what each command does and why it’s necessary.
Step 1: Update Linux Mint
Before you begin, run the following commands to ensure your system is current. These commands will update the package index and upgrade installed packages to their latest versions:
sudo apt update sudo apt upgrade
Step 2: Install PHP
Now, let’s install PHP by running the following command:
sudo apt install php
This command will download and install PHP and its required dependencies from the Linux Mint repository. Once the installation is complete, you’ll have PHP installed on your system.
Step 3: Install PHP FPM
PHP FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation that provides improved performance and resource management for PHP applications. To install PHP FPM, run the following command:
sudo apt install php-fpm
Step 4: Install PHP Extensions
PHP extensions are additional modules that extend the functionality of PHP. You can install specific extensions depending on your project requirements. For example, if you need to connect to a MySQL database, you’ll need to install the
To install a PHP extension, use the following command format:
sudo apt install php-[extension-name]
[extension-name] with the name of the extension you want to install.
Step 5: Confirm PHP Installation
After installing PHP and any necessary extensions, you can verify the installation by checking the PHP version. Run the following command:
This command will display the installed PHP version, confirming that PHP has been installed correctly.
Step 6: Check PHP Status
To ensure that PHP FPM is running properly, you can check its status by running the following command:
sudo systemctl status php7.4-fpm
php7.4-fpm with the specific version of PHP FPM installed on your system. If PHP FPM is running correctly, you’ll see its status as
Section 2: Install PHP with PPA
In this section, we will guide you through the process of installing PHP using the Ondrey Sury Launchpad PPA. This method allows you to install the latest versions of PHP (8.0, 8.1, and 8.2) on your Linux Mint system. We will explain each command in detail, so you understand what is happening before and after executing them.
Step 1: Import PHP LaunchPAD PPA
First, you must import the Ondrey Sury Launchpad PPA, which provides the latest PHP packages. To do this, run the following command:
sudo apt install software-properties-common sudo add-apt-repository ppa:ondrej/php
These commands will install the
software-properties-common package (if not already installed) and add the Ondrey Sury PHP PPA to your system.
Step 2: Update Package List
After adding the PPA, update your package list to include the latest PHP packages from the PPA repository:
sudo apt update
This command ensures that your system has access to the most recent PHP packages available in the PPA.
Step 3: Install PHP
Now, you can choose which version of PHP you want to install. We will provide instructions for installing PHP 8.0, 8.1, and 8.2.
Option 1: Install PHP 8.0
To install PHP 8.0, run the following command:
sudo apt install php8.0
This command will download and install PHP 8.0 and its required dependencies on your system.
Option 2: Install PHP 8.1
To install PHP 8.1, run the following command:
sudo apt install php8.1
This command will download and install PHP 8.1 and its required dependencies on your system.
Option 3: Install PHP 8.2
To install PHP 8.2, run the following command:
sudo apt install php8.2
This command will download and install PHP 8.2 and its required dependencies on your system.
Step 4: Install PHP-FPM
After installing the desired PHP version, install the corresponding PHP-FPM package to improve performance and resource management.
Option 1: Install PHP 8.0 FPM
To install PHP 8.0 FPM, run the following command:
sudo apt install php8.0-fpm
This command will install the PHP 8.0 FPM package, enabling your web server to handle PHP requests more efficiently.
Option 2: Install PHP 8.1 FPM
To install PHP 8.1 FPM, run the following command:
sudo apt install php8.1-fpm
This command will install the PHP 8.1 FPM package, enabling your web server to handle PHP requests more efficiently.
Option 3: Install PHP 8.2 FPM
To install PHP 8.2 FPM, run the following command:
sudo apt install php8.2-fpm
This command will install the PHP 8.2 FPM package, enabling your web server to handle PHP requests more efficiently.
Step 5: Install PHP Extensions
Now, let’s install PHP extensions to extend the functionality of PHP for your specific project requirements.
Step 1: List Extensions
To list available PHP extensions for a specific PHP version, run the following command:
sudo apt-cache search php8.2
8.2 with the version number of your installed PHP. This command will display a list of available extensions for PHP 8.2.
Alternatively, using the following command will list already enabled PHP extensions:
Step 2: Install Extensions
To install a specific extension for PHP 8.2, use the following command format:
sudo apt install php8.2-[extension-name]
[extension-name] with the name of the extension you want to install. For example, to install the
mysqli extension for PHP 8.2, run:
sudo apt install php8.2-mysqli
Section 3: Additional Commands & Tips
This section will cover some useful commands and tips for managing multiple PHP versions on your Linux Mint system. We will explain each command and its purpose so you understand the process of switching between different PHP versions.
Switch PHP Alternative Versions
On Linux Mint, you can switch between different versions of PHP using the
update-alternatives command. Here are the steps to switch to alternative PHP versions:
Step 1: Check the Current PHP Version
First, check the current PHP version active on your system by running the following command:
This command will display the active PHP version on your system.
Step 2: List Available PHP Versions
Use the following command to see a list of all available PHP versions on your system:
This command will show a list of installed PHP versions, allowing you to choose which version to switch to.
Step 3: Switch PHP Version
To switch to a different version of PHP, use the following command format:
sudo update-alternatives --set php /usr/bin/php[version]
[version] with the desired PHP version number. For example, to switch to PHP 8.1 from 8.2, you would use the following command:
sudo update-alternatives --set php /usr/bin/php8.1
After executing the command, you will likely see an output similar to the following in your terminal:
update-alternatives: using /usr/bin/php8.1 to provide /usr/bin/php (php) in manual mode
This output confirms that you have successfully switched to the specified PHP version.
Step 4: Verify the New PHP Version
After switching to a different PHP version, you can verify the newly activated version by running the following command:
This command will display the currently active PHP version, confirming that you have successfully switched to the desired PHP version.
Following these steps, you can easily switch between different PHP versions on your Linux Mint system, allowing you to test your PHP applications with multiple PHP versions or adapt your development environment to specific project requirements.
Conclusion: Installing PHP on Linux Mint
In conclusion, installing PHP on Linux Mint is a straightforward process that can be accomplished using the default Linux Mint repository or the Ondrey Sury Launchpad PPA for the latest PHP versions. Following the steps in this guide will help you set up your development environment with the desired PHP version and extensions to match your project requirements. By understanding how to switch between different PHP versions and manage extensions, you can maintain a flexible and efficient development environment for your PHP projects.
Additional Resources and Links
Below are some official resources and links that can help you deepen your understanding of PHP and its related components:
- PHP Official Website: The official website for PHP, where you can find the latest news, updates, and downloads related to PHP.
- PHP Documentation: The official PHP documentation provides comprehensive information on PHP functions, classes, and extensions.
- PHP Wiki: The PHP Wiki is a collaborative platform where PHP developers and users can share information, tips, and best practices for working with PHP.
- Linux Mint Official Website: The official website for Linux Mint, where you can find the latest news, updates, and downloads related to the Linux Mint operating system.