Current Location: Home> Latest Articles> Complete Guide to Installing PHP on Debian: Quick Setup and Extension Tips

Complete Guide to Installing PHP on Debian: Quick Setup and Extension Tips

gitbox 2025-06-24

In modern web development, PHP is a popular server-side scripting language widely used across various projects. For developers working with the Debian operating system, knowing how to properly install PHP is essential. This article offers a comprehensive guide to installing PHP on Debian, helping you smoothly set up your development environment.

Preparation

Before installing PHP, it is recommended to ensure your Debian system is up to date. You can update your system by running:

<span class="fun">sudo apt update && sudo apt upgrade</span>

Installing PHP

Debian comes with a powerful package manager that you can use to install PHP and related extensions. First, run the following command to install the latest stable version of PHP:

<span class="fun">sudo apt install php</span>

Installing PHP Extensions

Depending on your project needs, you might want to install additional PHP extensions. For example, if you need MySQL database support, use the command below to install the corresponding extension:

<span class="fun">sudo apt install php-mysql</span>

Verifying the Installation

After installation, confirm that PHP is installed correctly and check its version by running:

<span class="fun">php -v</span>

This command will display the current PHP version and related information, ensuring it is working properly.

Configuring PHP

To tailor the PHP environment to your development requirements, you may need to adjust PHP’s configuration file. The main configuration file is php.ini. You can locate it by running:

<span class="fun">php --ini</span>

After locating the file, open it with a text editor, for example:

<span class="fun">sudo nano /etc/php/7.X/cli/php.ini</span>

Replace “7.X” with your actual PHP version. In this file, you can modify settings such as error reporting levels, memory limits, and more.

Restarting the Web Server

If you are running PHP through a web server like Apache or Nginx, you need to restart the server after making configuration changes to apply them. For Apache, run:

<span class="fun">sudo systemctl restart apache2</span>

Conclusion

By following these steps, you have successfully installed and configured PHP on your Debian system. Whether you are building a new project or maintaining an existing one, a stable PHP environment is key to smooth development. We hope this guide helps you quickly set up your PHP environment and wish you a successful development experience!