How to Install PHP on Linux Mint 19

PHP is a popular general-purpose scripting language that is especially suited to web development.This article will help you to install PHP (7.3, 7.2, 7.1, 7.0) on Linux Mint 19 and integrate it with Nginx and Apache.

Most of the popular PHP frameworks and applications including WordPress, Laravel, Drupal and Nextcloud are compatible with PHP 7 .

Through this tutorial you will learn how to install PHP on Linux Mint 19,in this tutorial we will take on PHP 7.2 as an example.

Before you start install PHP on Linux Mint 19, you must have an account with sudo privileges and ma ke sure your Linux Mint 19 server can access the Internet.

If you are using Apache as your web server to install PHP and Apache PHP module run the following command:

sudo apt install php libapache2-mod-php

When the packages are installed, you can start the Apache service with the following command:

sudo systemctl restart apache2

Unlike Apache, Nginx doesn’t have a built in support for processing PHP files so we need to install a separate application such as PHP FPM 「fastCGI process manager」 which will handle PHP files.

You can through To install the PHP and PHP FPM packages run the following command:

sudo apt install php-fpm

When the packages are installed you can check the status of the PHP FPM service with:

systemctl status php7.2-fpm

The output as following:

* php7.2-fpm.service - The PHP 7.2 FastCGI Process Manager
   Loaded: loaded (/lib/systemd/system/php7.2-fpm.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2019-05-10 23:56:14 PDT; 1min 28s ago
     Docs: man:php-fpm7.2(8)
 Main PID: 10080 (php-fpm7.2)
   Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
    Tasks: 3 (limit: 2321)
   CGroup: /system.slice/php7.2-fpm.service
           |-10080 php-fpm: master process (/etc/php/7.2/fpm/php-fpm.conf)

Now,You can edit the Nginx server block and add the following lines so that Nginx can process PHP files:

server {

    # . . . other code

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    }
}

After saving the changes, restart the Nginx service for the new configuration to take effect.

following command:

sudo systemctl restart nginx

To extend the core functionality of PHP you can install some additional extensions. PHP extensions are available as packages and can be easily installed with:

sudo apt install php-[extname]

For example if you want to install MySQL and GD PHP extensions you would run the following command:

sudo apt install php-mysql php-gd

After installing a new PHP extension do not forget to restart the Apache or the PHP FPM service, depending on your setup.

To test whether your web server is configured properly for PHP processing, create a new file called info.php inside the /var/www/html directory with the following code:

<?php

phpinfo();

Save the file, open your browser of choice and visit http://your_server_ip/info.php

The phpinfo function will print information about your PHP configuration as shown on the image below:

if you want install PHP 7.3 on Linux Mint 19,you need enabling the Ondrej PHP repository, following command:

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php

Run the following command in the terminal to complete the installation of PHP7.3 and some of the most common PHP modules.

sudo apt install php7.3 php7.3-common php7.3-opcache php7.3-cli php7.3-gd php7.3-curl php7.3-mysql

After the installation is complete,run the following command which will print PHP version:

php -v

You will see the following output:

PHP 7.3.1-1+ubuntu18.04.1+deb.sury.org+1 (cli) (built: Apr 10 2019 1033) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.1, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.1-1+ubuntu18.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

if you want install PHP 7.1 on Linux Mint 19,then you need enabling the Ondrej PHP repository, following command:

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php

Run the following command in the terminal to complete the installation of PHP7.1 and some of the most common PHP modules.

sudo apt install php7.1 php7.1-common php7.1-opcache php7.1-cli php7.1-gd php7.1-curl php7.1-mysql

After the installation is complete,run the following command which will print PHP version:

php -v

You will see the following output:

PHP 7.1.20-1+ubuntu18.04.1+deb.sury.org+1 (cli) (built: Apr 10 2019 1009) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.1.20-1+ubuntu18.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

You have learned how to install PHP on Linux Mint 19 server. You can now log in to your Linux Mint server with to try it.

If you have any question about this tutorial please don’t forget to leave a comment.

Leave a Reply