Installing distro-packaged PHP on Ubuntu or Debian adds a supported interpreter for Composer runs, cron jobs, deployment hooks, and one-off maintenance scripts without turning the first install into a web-server setup decision.
On both distro families, the php-cli package resolves the default CLI runtime for the enabled repositories. That dependency package pulls in the matching versioned interpreter, while optional capabilities such as cURL, MySQL drivers, and XML parsers stay in separate php-* packages so the base install stays small and explicit.
The exact branch follows the active package sources. Current package checks map php-cli to PHP 8.3 on Ubuntu 24.04 LTS and to PHP 8.4 on Debian 13 stable, so pinned archives or third-party repositories can change both the resolved package names and the configuration paths that appear after install.
Related: Install PHP-FPM on Ubuntu or Debian
Related: Find PHP configuration files
Steps to install PHP on Ubuntu or Debian:
- Refresh the package index so APT resolves PHP packages from the currently enabled repositories.
$ sudo apt-get update
- Check which versioned CLI package the php-cli dependency package resolves on the current host.
$ apt-cache policy php-cli php-cli: Installed: (none) Candidate: 2:8.3+93ubuntu2 Version table: 2:8.3+93ubuntu2 500 500 http://ports.ubuntu.com/ubuntu-ports noble/main arm64 Packages $ apt-cache depends php-cli php-cli Depends: php8.3-cliCurrent package checks map php-cli to php8.3-cli on Ubuntu 24.04 LTS and to php8.4-cli on Debian 13 stable. Checking the dependency first keeps multi-version hosts and pinned-repository systems from installing the wrong branch by assumption.
- Install the distro-packaged PHP command-line runtime.
$ sudo apt-get install --yes php-cli
Current Ubuntu 24.04 LTS package checks resolve this to php8.3-cli, while current Debian 13 stable package checks resolve it to php8.4-cli. This page keeps the first install on the CLI runtime only; add PHP-FPM separately when the host also needs a web-facing FastCGI service.
- Verify that the php command is available and reporting the installed CLI runtime.
$ php -v PHP 8.3.6 (cli) (built: Jan 27 2026 03:09:47) (NTS) Copyright (c) The PHP Group Zend Engine v4.3.6, Copyright (c) Zend Technologies with Zend OPcache v8.3.6, Copyright (c), by Zend TechnologiesThe decisive check is the first line showing the dotted release and the cli SAPI. The exact version changes with the distro release and enabled repositories.
Related: How to check PHP version
- Install only the extension bundles the application needs after the base interpreter is working.
$ sudo apt-get install --yes php-curl php-mysql php-xml
The unversioned php-* packages follow the distro-default PHP branch, so current Ubuntu 24.04 resolves them to matching php8.3-* packages while current Debian 13 resolves them to matching php8.4-* packages. Use explicit versioned package names only when a host intentionally carries more than one branch.
- Confirm that the requested modules are loaded by the same CLI runtime that the application will use.
$ php -m | grep -E '^(curl|mysqli|mysqlnd|pdo_mysql|xml|xmlreader|xmlwriter)$' curl mysqli mysqlnd pdo_mysql xml xmlreader xmlwriter
The php-mysql bundle loads mysqlnd, mysqli, and pdo_mysql, while php-xml adds xml, xmlreader, and xmlwriter. When shell output and web output later disagree, compare the active configuration files before changing extensions.
Related: Show loaded PHP extensions
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
