start here
Linux Setup
Linux is the most common environment for deployed PHP applications, and it is also a common local development environment through native Linux, WSL, containers, and dev containers.
The useful skill is not memorising one distribution's package names. It is proving which PHP runtime is active, where configuration is loaded from, which extensions are enabled, and whether CLI PHP and PHP-FPM match the project.
Package Managers And PHP Versions
Linux distributions install PHP through package managers.
Debian and Ubuntu use apt:
apt-cache policy php
php -v
Fedora, RHEL, and similar systems use dnf:
dnf list installed "php*"
php -v
Arch uses pacman:
pacman -Qs php
php -v
Use the package manager to understand what is installed, but use php -v to prove what your shell actually runs.
Find The Active Binary
Check the active CLI PHP binary:
which php
which -a php
php -v
which -a php is useful when several PHP binaries are visible on PATH. The first one is the one your shell runs.
If the project runs in Docker, WSL, or a remote server, run these checks inside that environment. Your host machine's PHP may be irrelevant.
Configuration Paths
Linux package layouts vary by distribution. Debian-style systems often use versioned directories such as:
/etc/php/8.3/cli/php.ini
/etc/php/8.3/fpm/php.ini
/etc/php/8.3/mods-available
/etc/php/8.3/cli/conf.d
/etc/php/8.3/fpm/conf.d
Other distributions may use paths such as:
/etc/php.ini
/etc/php.d
The reliable command is:
php --ini
Also check:
php -i | grep "Loaded Configuration File"
php -i | grep "Scan this dir"
CLI and FPM may load different php.ini files. A setting can be correct for terminal commands and wrong for web requests.
Extensions
List loaded extensions:
php -m
php -m | grep mbstring
php -m | grep pdo
Common project extensions include:
mbstring
intl
pdo
pdo_mysql
curl
zip
gd
opcache
redis
From PHP:
<?php
declare(strict_types=1);
foreach (['mbstring', 'intl', 'pdo', 'opcache'] as $extension) {
echo $extension . ': ';
echo extension_loaded($extension) ? 'loaded' : 'missing';
echo PHP_EOL;
}
// Prints:
// mbstring: loaded
// intl: loaded
// pdo: loaded
// opcache: loaded
If an extension is installed but not loaded, inspect the .ini files under the active configuration scan directory.
PHP-FPM Services
Production-style Linux PHP commonly uses PHP-FPM behind Nginx, Apache, or Caddy.
Check services with systemd:
systemctl status php-fpm
systemctl status php8.3-fpm
systemctl list-units "php*"
The exact service name depends on the distribution and PHP version.
Check FPM configuration and pools:
php-fpm -v
php-fpm -tt
On some systems the command may be versioned, such as php-fpm8.3.
Do not assume CLI PHP and FPM are the same runtime. Check both when debugging web-only problems.
Permissions And Users
Linux services run as users. PHP-FPM may run as www-data, nginx, apache, or a project-specific user.
Permission bugs often look like application bugs:
- uploads fail
- cache cannot be written
- logs do not appear
- sessions fail
- generated files are owned by the wrong user
Useful checks:
whoami
id
ps aux | grep php-fpm
ls -la storage
The user running CLI commands may not be the same user running web requests.
Composer Platform Checks
Run the project-level platform check:
composer check-platform-reqs
If this fails, compare:
which php
php -v
php -m
php --ini
Composer errors about missing extensions usually mean the active CLI runtime does not match the project requirements.
Linux Setup Checklist
For a Linux setup note, record:
- Distribution and version.
- Whether PHP runs on the host, in WSL, in Docker, or on a remote server.
- What
which phpandphp -vreturn. - What
php --inireturns. - Which extensions are required.
- Whether PHP-FPM is used and what the service is called.
- Which user runs PHP-FPM.
- Whether
composer check-platform-reqspasses.
This checklist gives you enough information to debug setup, extension, and permission issues without guessing.
What You Should Be Able To Do
After this lesson, you should be able to verify Linux PHP from the terminal, inspect configuration paths, check extensions, distinguish CLI from PHP-FPM, identify service users, and confirm Composer platform requirements.
For junior PHP work, this matters because Linux is where many PHP applications ultimately run. Knowing how to inspect the runtime makes you useful in both development and deployment conversations.
Practice
Practice: Create A Linux PHP Setup Note
Create a short Linux setup note for a PHP project.
Task
Include commands to show:
- active PHP binary
- all visible PHP binaries
- PHP version
- loaded configuration files
- loaded extensions
- PHP-FPM service status, if used
- Composer platform requirements
Also note whether PHP is running on the host, in WSL, in Docker, or on a remote server.
Show solution
A useful Linux setup note proves the active runtime and the service runtime.
which php
which -a php
php -v
php --ini
php -m
systemctl list-units "php*"
composer check-platform-reqs
If PHP-FPM is used, add the specific service check:
systemctl status php-fpm
systemctl status php8.3-fpm
Example notes:
Runtime location: Docker container
Active CLI PHP: /usr/local/bin/php
Web runtime: php-fpm service inside container
Composer platform check: passes
The important point is to run the checks in the same environment where the project runs. Host PHP, container PHP, WSL PHP, and remote server PHP can all be different.
Task: Config Paths
Create a checklist for finding Linux PHP configuration paths.
Requirements
Include commands to find:
- the loaded CLI
php.ini - the additional
.iniscan directory - likely Debian-style CLI and FPM config paths
- likely Fedora/RHEL-style config paths
Afterward, add a short note explaining why CLI and FPM configuration can differ.
Show solution
php --ini
php -i | grep "Loaded Configuration File"
php -i | grep "Scan this dir"
Likely Debian-style paths:
/etc/php/8.3/cli/php.ini
/etc/php/8.3/fpm/php.ini
/etc/php/8.3/cli/conf.d
/etc/php/8.3/fpm/conf.d
Likely Fedora/RHEL-style paths:
/etc/php.ini
/etc/php.d
CLI and FPM configuration can differ because they are separate SAPIs. A setting or extension can be enabled for terminal commands while the web runtime still loads a different php.ini or conf.d directory.
Task: Extension Check
Create a Linux extension check for a PHP project.
Requirements
Include:
- terminal commands to list and search loaded extensions
- a PHP snippet that checks
mbstring,intl,pdo, andopcache - a Composer command that checks project platform requirements
Use strict types in the PHP snippet. Keep example output inside the PHP code block as comments.
Show solution
php -m
php -m | grep mbstring
php -m | grep opcache
Check project requirements:
composer check-platform-reqs
Use PHP for a repeatable check:
<?php
declare(strict_types=1);
foreach (['mbstring', 'intl', 'pdo', 'opcache'] as $extension) {
echo $extension . ': ';
echo extension_loaded($extension) ? 'loaded' : 'missing';
echo PHP_EOL;
}
// Prints:
// mbstring: loaded
// intl: loaded
// pdo: loaded
// opcache: loaded
If an extension is missing, check the active binary and loaded configuration before installing packages. You need the extension enabled for the runtime the project actually uses.