Skip to main content

How to Install PHP on Linux Mint

PHP is a popular server-side scripting language used for web development. It is widely supported and can be easily integrated with various web servers and databases. In this tutorial, we will walk you through a step-by-step process of installing PHP on Linux Mint, a user-friendly Linux distribution.

Prerequisites

Before we begin, ensure that you have administrative access to your Linux Mint system. Additionally, make sure that you have an active internet connection as we will need to download the necessary packages.

Step 1: Update System Packages

To start, let's update the system package list to ensure we have the latest versions of software.

Open a terminal by pressing Ctrl + Alt + T or by searching for "Terminal" in the application menu.

Run the following command to update the package list:

sudo apt update

Enter your password when prompted, and wait for the process to complete.

Step 2: Install PHP

Now that the package list is up to date, we can install PHP. Linux Mint provides a package manager called apt to handle software installations.

In the same terminal, run the following command to install PHP along with some commonly used extensions:

sudo apt install php libapache2-mod-php php-mysql

This command installs PHP, the Apache PHP module, and the MySQL extension for PHP.

During the installation, you may be prompted to confirm the disk space usage and dependencies. Press y and hit Enter to proceed.

Once the installation is complete, you can verify the PHP version by running:

php -v

You should see the installed PHP version and other details.

Step 3: Configure PHP

By default, PHP is already configured to work with Apache, but there are a few additional configurations you can make.

Open the PHP configuration file in a text editor using the following command:

sudo nano /etc/php/7.4/apache2/php.ini

This command opens the php.ini file for PHP version 7.4 with the Nano text editor. Feel free to replace 7.4 with your installed PHP version if it differs.

Within the file, you can modify various PHP settings according to your requirements. For example, you can increase the maximum file upload size by locating the upload_max_filesize directive and updating its value.

After making any changes, save the file by pressing Ctrl + O, then exit the editor by pressing Ctrl + X.

Step 4: Restart Apache

To apply the changes made in the PHP configuration, we need to restart the Apache web server.

Run the following command to restart Apache:

sudo service apache2 restart

This command restarts the Apache service, ensuring that the updated PHP configuration takes effect.

Step 5: Test PHP Installation

To confirm that PHP is working correctly, let's create a simple PHP file and access it through a web browser.

Create a new file called info.php in the default web server directory using the following command:

sudo nano /var/www/html/info.php

Within the file, enter the following PHP code:

<?php
phpinfo();
?>

Save the file and exit the text editor.

Now, open a web browser and enter the following URL:

http://localhost/info.php

If PHP is installed correctly, you should see a page displaying detailed information about the PHP installation, including the PHP version, extensions, and other configuration settings.

Conclusion

Congratulations! You have successfully installed PHP on Linux Mint. You can now start developing web applications using this powerful scripting language. Remember to keep your PHP installation and system updated for security and performance reasons.

If you encounter any issues during the installation process or have specific requirements, refer to the official PHP documentation or seek assistance from the Linux Mint community.

Happy coding!