How to Install PHP on Debian 10?

How to Install PHP on Debian 10?

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.

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 update
sudo 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 update
sudo 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:

<?php

phpinfo();

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:

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.

php linux

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Hire PHP Developer

Looking to develop a PHP based website from scratch or revamp your existing website? **[HourlyDeveloper.io](https://hourlydeveloper.io/ "HourlyDeveloper.io")** has always been an industry leader for companies and business owners looking to hire...

Hire Dedicated PHP Developer

Looking to hire affordable yet experienced PHP developers? **[Hire Dedicated PHP Developer](https://hourlydeveloper.io/hire-dedicated-php-developer/ "Hire Dedicated PHP Developer")**, who can convert your idea to reality, within the stipulated...

Hire Dedicated Linux Developer

Looking to develop real-time applications? **[Hire Dedicated Linux Developer](https://hourlydeveloper.io/hire-dedicated-linux-developer/ "Hire Dedicated Linux Developer")** from **[HourlyDeveloper.io](https://hourlydeveloper.io/...

Country State City Dropdown list in PHP MySQL PHP

Country state city dropdown using ajax in php. You'll learn how to populate country city state dropdown based on previous selection in php using ajax

PHP json_decode Example | Decode JSON Data in PHP Tutorial

PHP json_decode is an inbuilt function that takes the JSON encoded string and converts it into a PHP variable. JSON stands for JavaScript Object Notation.