Installing from packages on Debian GNU/Linux and related distributions
While PHP can be installed from source, it is also available through packages from Debian GNU/Linux. This is also true for other distributions based on Debian, such as Ubuntu, Kali Linux, and Linux Mint.
While PHP can be installed from source, it is also available through packages from Debian GNU/Linux. This is also true for other distributions based on Debian, such as Ubuntu, Kali Linux, and Linux Mint.
Third-party-support
The packages can be installed using either the apt or aptitude commands. This manual page uses these two commands interchangeably.
Using APT
First, note that other related packages may be desired like libapache2-mod-php to integrate with Apache httpd 2, and php-pear for PEAR.
Second, before installing a package, it's wise to ensure the package list is up to date. Typically, this is done by running the command apt update.
Debian Install Example with Apache httpd 2
# apt install php-common libapache2-mod-php php-cliAPT will automatically install the PHP module for Apache httpd 2 and all of its dependencies, and then activate it. Apache httpd should be restarted in order for the changes to take place. For example:
Restarting Apache httpd once PHP is installed
# systemctl restart apache2Better control of configuration
In the last section, PHP was installed with only core modules. It's very likely that additional modules will be desired, such as MySQL, cURL, GD, etc. These may also be installed via the apt command.
Methods for listing additional PHP packages
# apt-cache search php
# apt search php | grep -i mysql
# aptitude search phpThe list of packages will include a large number of packages that includes basic PHP components, such as php-cgi, php-cli, and php-dev, as well as many PHP extensions. When extensions are installed, additional packages will be automatically installed as necessary to satisfy the dependencies of those packages.
Install PHP with MySQL, cURL
# apt install php-mysql php-curlAPT will automatically add the appropriate lines to the different Ini related files like /etc/php/8.x/apache2/php.ini, /etc/php/8.x/cli/php.ini, /etc/php/8.x/mods-available/*.ini, etc. and depending on the extension will add entries similar to extension=foo.so. However, restarting the web server is required before these changes take effect.
Common Problems
- If the PHP scripts are not parsing via the web server, then it's likely that PHP was not added to the web server's configuration file, which on Debian may be
/etc/apache2/apache2.confor similar. See the Debian manual for further details. - If an extension was seemingly installed yet the functions are undefined, be sure that the appropriate ini file is being loaded and/or the web server was restarted after installation.