How to Install PHP on Debian 9

Install PHP on Debian 9, ships with PHP version 7.Zero will soon attain give up-of-lifestyles for help and not acquire security updates.Install PHP on Debian 9Debian 9 ships with PHP version 7.Zero will soon attain give up-of-lifestyles for help and not acquire security updates.

In this educational, we can walk you via the steps for putting in PHP 7.2 on a Debian 9 server. We will even display you a way to configure Apache and Nginx to run PHP.

Install PHP on Debian 9,Prerequisites

Before starting with this tutorial, make sure you are logged in as a user with sudo privileges.

Install PHP on Debian 9,Installing PHP 7.2 on Debian 9

The following steps describe how to install PHP 7.2 using the Ondrej Sury repository.

1.First, replace the apt package deal listing and set up the dependencies important to feature a brand new repository over HTTPS:

sudo apt update

sudo apt install apt-transport-https ca-certificates curl software-properties-common

2.tart by importing the repository’s GPG key using the following curl command:

curl -fsSL https://packages.sury.org/php/apt.gpg | sudo apt-key add –

Add the ondrej’s repository to your system’s software repository list by typing:

sudo add-apt-repository “deb https://packages.sury.org/php/ $(lsb_release -cs) main”

3. Now that we have the ondrej’s repository enabled on our system, we can install PHP by specifying the version we want to use:

sudo apt updatesudo apt install php7.2-common php7.2-cli

4. Verify the installation, by running the following command which will print the PHP version.

php -v

PHP 7.2.8-1+0~20180725124257.2+stretch~1.gbp571e56 (cli) (built: Jul 25 2018 12:43:00) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.8-1+0~20180725124257.2+stretch~1.gbp571e56, Copyright (c) 1999-2018, by Zend Technologies

Install PHP on Debian 9,Configuring Apache to run PHP

Unlike Apache, Nginx doesn’t have a constructed in aid for processing PHP files so we need to put in a separate software inclusive of PHP FPM (“fastCGI technique supervisor”) as a way to take care of PHP files. To install the PHP and PHP FPM applications run the following command:

sudo apt install php7.2-fpm

Once the programs are established the PHP FPM carrier will start routinely. You can take a look at the provider repute with:

systemctl status php7.2-fpm

● 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 Thu 2018-08-30 21:06:53 UTC; 1min 4s ago Docs: man:php-fpm7.2(8) Main PID: 16791 (php-fpm7.2) Status: “Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec” CGroup: /system.slice/php7.2-fpm.service ├─16791 php-fpm: master process (/etc/php/7.2/fpm/php-fpm.conf) ├─16792 php-fpm: pool www └─16793 php-fpm: pool www

You can now edit your domain 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;
}

}

Restart the Nginx service so that the new configuration take effect:

sudo systemctl restart nginx

Installing PHP extensions

We can make bigger the middle capability of PHP through putting in extra extensions. PHP extensions are available as programs and may be without problems hooked up with:

sudo apt install php-[extname]

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

sudo apt install php7.2-mysql php7.2-gd

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

Testing PHP Processing

To take a look at whether or not your internet server is configured well for PHP processing, create a new document called data.Hypertext Preprocessor inside the /var/www/html directory with the following code:

/var/www/html/info.php

<?php

phpinfo();

Save the report, open your browser of desire and go to http://your_server_ip/information.Php The phpinfo function will print records about your PHP configuration as proven at the photograph below:

 

Conclusion

You have efficiently established PHP for your Debian 9 server and found out the way to configure your net server to method PHP documents.

If you have any question or remarks do not hesitate to go away a remark.