Installation guides

Installing PHP on Debian

Step-by-Step Guide

  1. Update the Package Index
    Open a terminal and update the package index to ensure you have the latest information about available packages:
   sudo apt update
  1. Install PHP
    Install PHP along with some common PHP modules using the apt package manager:
   sudo apt install php libapache2-mod-php php-mysql

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

  1. Verify PHP Installation
    Check the PHP version to ensure it is installed correctly:
   php -v

You should see the PHP version information displayed.

  1. Test PHP with Apache
    To test PHP with Apache, create a new PHP file in the web root directory:
   sudo nano /var/www/html/info.php

Add the following PHP code to the file:

   <?php
   phpinfo();
   ?>

Save and close the file.

  1. Restart Apache
    Restart Apache to apply the changes:
   sudo systemctl restart apache2
  1. Access the PHP Info Page
    Open your web browser and visit http://your_server_ip/info.php. You should see the PHP information page, indicating that PHP is working correctly with Apache.
  2. Install Additional PHP Modules (Optional)
    You can install additional PHP modules as needed. To search for available PHP modules, use:
   sudo apt-cache search php-

To install a specific PHP module, use:

   sudo apt install php-module_name

Replace module_name with the name of the module you wish to install.

  1. Configure PHP Settings (Optional)
    You can configure PHP settings by editing the php.ini file. The location of the php.ini file may vary depending on your PHP version. For PHP 7.4, the file is typically located at /etc/php/7.4/apache2/php.ini:
   sudo nano /etc/php/7.4/apache2/php.ini

After making changes, restart Apache to apply them:

   sudo systemctl restart apache2
  1. Remove the PHP Info Page
    For security reasons, it’s a good idea to remove the PHP info page after testing:
   sudo rm /var/www/html/info.php
Other Recent Posts