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
$ sudo apt-get update
$ 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-cli
Current 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.
$ 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.
$ 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 Technologies
The 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
$ 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.
$ 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