How to Install PHP on Debian 10 Linux

[ad_1]

PHP is one of the most used server-side programming languages.

In this guide, we will discuss how to install PHP on Debian 10, Buster. We’ll also show you how to integrate PHP with Nginx and Apache.

Debian 10 ships with PHP version 7.3, which is supported by the most popular CMS and frameworks such as WordPress, Magento, and Laravel.

Prerequisites #

To be able to install packages, you need to be logged in as root or user with sudo privileges
.

Installing PHP with Apache #

If you are using Apache
as your webserver to install PHP and Apache PHP module run the following commands:

sudo apt updatesudo apt install php libapache2-mod-php

Once the installation is complete, restart Apache to load the PHP module:

sudo systemctl restart apache2

Installing PHP with Nginx #

Unlike Apache, Nginx
doesn’t have a built-in support for processing PHP files. You’ll need to use the PHP FPM (“fastCGI process manager”) service to handle the PHP files.

Install the PHP and PHP FPM packages by running the following command:

sudo apt updatesudo apt install php php-fpm

Once the packages are installed, the PHP FPM service will start automatically.

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.3-fpm.sock;
    }
}

Save the configuration file and restart the nginx service
for the new configuration take effect:

sudo systemctl restart nginx

Installing PHP extensions #

You can extend the PHP core functionalities by installing additional extensions. PHP extensions are available as packages and can be easily installed by typing:

sudo apt install php-[extname]

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

sudo apt install php-mysql php-gd

When installing PHP extensions, do not forget to restart the Apache or the PHP FPM service, depending on your setup.

Testing PHP Processing #

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

/var/www/html/info.php

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

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

phpinfo Debian

Conclusion #

We have shown you how to install PHP on Debian 10 and configure your webserver to process PHP files.

If you have any questions or feedback, do not hesitate to leave a comment.

[ad_2]

Source link

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.