How to Install PHP on Arch Linux

Install PHP on Arch Linux with pacman and configure extensions, PHP-FPM, and Composer. Includes AUR versions and troubleshooting.

Last updatedAuthorJoshua JamesRead time9 minGuide typeArch Linux

Arch Linux keeps PHP in the official repositories, with the current branch available as php and a separate php-legacy branch for older application compatibility. Install the main package for new WordPress, Laravel, Drupal, Symfony, or CLI projects, then add PHP-FPM, Composer, and only the extensions your application actually needs.

This guide covers the Arch package layout, the php-pgsql extension package that many PostgreSQL users search for, PHP-FPM service setup, common php.ini changes, Composer, verification, troubleshooting, and clean removal.

Update Arch Linux Before PHP Installation

Synchronize package databases and upgrade installed packages before adding PHP. Arch is rolling release, so installing against stale package metadata can create avoidable dependency conflicts:

sudo pacman -Syu

These commands use sudo for tasks that need root privileges. If your user is not in the sudoers file yet, run the commands as root or follow the guide on how to add and manage sudo users on Arch Linux.

Install PHP on Arch Linux via pacman

Arch provides the normal PHP runtime and a legacy branch in the official extra repository. The php package owns /usr/bin/php; Arch does not split the CLI interpreter into a separate php-cli package.

PackageBranchRepositoryUse it when
phpCurrent PHP branchOfficial extraYou are starting a new project or your application supports the current PHP release.
php-legacyOldest supported PHP branch packaged by ArchOfficial extraYour application is not ready for the current PHP branch and explicitly supports the legacy branch.

For most readers, install php. Use php-legacy only for a documented application requirement, because it has separate binaries, configuration files, PHP-FPM service files, and extension packages.

Versioned PHP builds such as php84 in the AUR can exist, but they are community maintained and can lag behind upstream PHP security releases. Check the AUR package status, compare it with the current PHP supported versions, and review the PKGBUILD before using a versioned AUR runtime on a production system. If you need an AUR helper, install one first, such as paru on Arch Linux.

Install Current PHP

Install the current PHP branch from the official repositories:

sudo pacman -S php

Verify the CLI interpreter and branch:

php --version

Relevant output includes:

PHP 8.5.x (cli)
Zend Engine v4.5.x
    with Zend OPcache v8.5.x

Confirm package ownership when you need to distinguish Arch’s official runtime from an AUR or manually installed binary:

command -v php
pacman -Qo /usr/bin/php

Expected output shows /usr/bin/php and the php package as the owner:

/usr/bin/php
/usr/bin/php is owned by php 8.5.x-1

The php package includes the CLI interpreter and several core modules such as curl, json, mbstring, openssl, PDO, pcntl, zip, and Zend OPcache. Some bundled modules, including intl, mysqli, and pdo_mysql, may still need their lines uncommented in /etc/php/php.ini before PHP loads them.

Install PHP Legacy

If your application specifically requires the legacy branch, install php-legacy beside the current runtime:

sudo pacman -S php-legacy

The legacy binary is php-legacy, not php. Verify it separately:

php-legacy --version

php-legacy uses /etc/php-legacy/php.ini, /etc/php-legacy/conf.d/, and extension packages prefixed with php-legacy-. If a legacy web application also needs PHP-FPM, install php-legacy-fpm; its main unit is php-fpm-legacy.service, with php-legacy-fpm.service available as an alias.

Install PHP Extensions on Arch Linux

The base runtime covers the interpreter and many bundled modules, but database drivers, image processing, caching, and debugging use additional packages. Arch installs the extension files first; you then enable the matching line in php.ini or a file under /etc/php/conf.d/.

Common PHP Extension Packages

PackageWhat it addsEnable location
php-gdGD image processing/etc/php/php.ini
php-sqlitepdo_sqlite and sqlite3/etc/php/php.ini
php-pgsqlpdo_pgsql and pgsql for PostgreSQL/etc/php/php.ini
php-sodiumlibsodium cryptography extension/etc/php/php.ini
php-tidyHTML cleanup and repair/etc/php/php.ini
php-xslXSL transformations/etc/php/php.ini
php-apcuUser cache for PHP applications/etc/php/conf.d/apcu.ini
php-redisRedis/Valkey client extension/etc/php/conf.d/redis.ini
php-igbinaryBinary serializer required by php-redis/etc/php/conf.d/igbinary.ini
php-imagickImageMagick integration/etc/php/conf.d/imagick.ini
xdebugDebugger and profiler/etc/php/conf.d/xdebug.ini

The PostgreSQL package name is exactly php-pgsql. It installs both /usr/lib/php/modules/pdo_pgsql.so and /usr/lib/php/modules/pgsql.so, but PHP will not load them until extension=pdo_pgsql and extension=pgsql are enabled in /etc/php/php.ini.

Install Common PHP Extensions

Install the packages you need. This example covers common web-development needs: GD, SQLite, PostgreSQL, APCu, Redis, and Xdebug. Skip Xdebug on production servers unless you explicitly need it for controlled diagnostics.

sudo pacman -S php-gd php-sqlite php-pgsql php-apcu php-redis xdebug

php-redis pulls in php-igbinary as a dependency. Enable both when you use Redis-backed sessions, queues, or object caches:

sudo sed -i 's/^;extension=igbinary.so/extension=igbinary.so/' /etc/php/conf.d/igbinary.ini
sudo sed -i 's/^;extension=redis/extension=redis/' /etc/php/conf.d/redis.ini

Enable APCu and Xdebug from their own configuration files:

sudo sed -i 's/^;extension=apcu.so/extension=apcu.so/' /etc/php/conf.d/apcu.ini
sudo sed -i 's/^;zend_extension=xdebug.so/zend_extension=xdebug.so/' /etc/php/conf.d/xdebug.ini

Open php.ini for the extensions that are controlled by the main configuration file:

sudo nano /etc/php/php.ini

Uncomment the extension lines your application needs. For PostgreSQL and SQLite support, enable these lines:

extension=pdo_pgsql
extension=pgsql
extension=pdo_sqlite
extension=sqlite3

For GD and MySQL/MariaDB support, enable these lines:

extension=gd
extension=mysqli
extension=pdo_mysql

For internationalization, enable intl from the base package. For sodium, tidy, or XSL support, install the matching package from the table first, then enable the line your application requires:

extension=intl
extension=sodium
extension=tidy
extension=xsl

Save the file with Ctrl+O, press Enter, then exit with Ctrl+X.

Optional Imagick Extension

Install php-imagick only when your CMS or framework needs ImageMagick-based image handling. The package depends on ImageMagick, but some formats also need optional ImageMagick codec packages; the guide on how to install ImageMagick on Arch Linux covers the tool itself.

sudo pacman -S php-imagick
sudo sed -i 's/^; extension = imagick/extension=imagick/' /etc/php/conf.d/imagick.ini

If php -i later prints repeated ImageMagick dlopen warnings for missing libraries such as libopenjp2 or libavcodec, install the optional dependency that matches the format you need. On Arch, openjpeg2 provides libopenjp2, while ffmpeg provides libavcodec.

Verify Loaded PHP Extensions

The PHP CLI reads its configuration each time it starts, so you can verify extension loading immediately. Restart PHP-FPM later if the service is already installed and running.

php -m | grep -iE 'gd|sqlite|pgsql|mysqli|pdo_mysql|apcu|igbinary|redis|xdebug'

Relevant output includes the modules you enabled:

apcu
gd
igbinary
mysqli
pdo_mysql
pdo_pgsql
pdo_sqlite
pgsql
redis
sqlite3
xdebug
Xdebug

Xdebug appears twice because php -m lists it under both PHP Modules and Zend Modules.

Set Up PHP-FPM on Arch Linux

PHP-FPM manages PHP worker processes for web servers such as Nginx and Apache. On Arch, the main PHP-FPM package uses the php-fpm.service unit and the default socket /run/php-fpm/php-fpm.sock.

Install and Start PHP-FPM

Install PHP-FPM from the official repository:

sudo pacman -S php-fpm

Enable the service and start it immediately:

sudo systemctl enable php-fpm --now

Verify both runtime and boot state:

systemctl is-active php-fpm
systemctl is-enabled php-fpm
active
enabled

Review the PHP-FPM Pool

The default pool configuration is /etc/php/php-fpm.d/www.conf. Check the socket and user settings before connecting a web server:

grep -E '^(user|group|listen|listen.owner|listen.group)' /etc/php/php-fpm.d/www.conf
user = http
group = http
listen = /run/php-fpm/php-fpm.sock
listen.owner = http
listen.group = http

The default Arch web-server user is http. If your Nginx or Apache configuration runs workers as a different user, update listen.owner, listen.group, and the web-server FastCGI socket path together, then restart PHP-FPM:

sudo systemctl restart php-fpm

For php-legacy-fpm, use /etc/php-legacy/php-fpm.d/www.conf and the socket /run/php-fpm-legacy/php-fpm.sock. Do not point a legacy web app at the main php-fpm socket unless it is compatible with the current PHP branch.

Configure PHP on Arch Linux

The main PHP configuration file is /etc/php/php.ini. Edit it for settings that affect both CLI scripts and PHP-FPM workers, then restart PHP-FPM for web requests to pick up the change.

Set the Timezone

Open php.ini and set date.timezone when your application needs a fixed timezone for logs, scheduled tasks, or date handling:

sudo nano /etc/php/php.ini

Use a value from the PHP supported timezones list:

date.timezone = America/New_York

Enable Error Display for Development

For local development, enable browser-visible errors while you debug:

display_errors = On

Set display_errors = Off on production servers. Public PHP errors can expose file paths, database details, and application internals.

Adjust Upload and Memory Limits

Applications such as WordPress, Drupal, and file-upload services often need higher limits than the defaults. Adjust these values to match your workload:

upload_max_filesize = 64M
post_max_size = 64M
memory_limit = 256M
max_execution_time = 300

Restart PHP-FPM after saving configuration changes:

sudo systemctl restart php-fpm

Verify OPcache Status

Zend OPcache is bundled with Arch’s current PHP package and loads by default. Verify the runtime setting with:

php -i | grep 'opcache.enable '
opcache.enable => On => On

PHP CLI opcode caching remains separate through opcache.enable_cli. Leave it off unless you have a CLI workload that benefits from it.

Install Composer PHP Dependency Manager on Arch Linux

Composer manages PHP project dependencies, autoloading, and lock files. Install Arch’s repository package for the simplest package-managed path:

sudo pacman -S composer

Verify the command and package ownership:

composer --version
pacman -Qo /usr/bin/composer

Relevant output includes:

Composer version 2.9.x
/usr/bin/composer is owned by composer 2.9.x-1

For deeper Composer setup, including project workflows and update behavior, use the dedicated guide on how to install Composer on Arch Linux.

Add Composer Global Bin to PATH

Composer stores user-level global binaries under ~/.config/composer/vendor/bin. Add that directory to your shell PATH if you install global Composer tools:

grep -qxF 'export PATH="$HOME/.config/composer/vendor/bin:$PATH"' ~/.bashrc || printf '\nexport PATH="$HOME/.config/composer/vendor/bin:$PATH"\n' >> ~/.bashrc
source ~/.bashrc

For Zsh, place the same export line in ~/.zshrc instead.

Test Composer Project Creation

Create a temporary Composer project file:

mkdir ~/php-test
cd ~/php-test
composer init --no-interaction --name="test/project"

Expected output confirms Composer wrote the project metadata:

Writing ./composer.json

Remove the temporary test directory when finished:

cd ~
rm -rf ~/php-test

Test PHP Installation on Arch Linux

Use a small PHP script to confirm the interpreter, OPcache, and selected extensions load correctly.

Run a Test Script

Create a test file:

nano ~/test.php

Add the following code:

<?php
echo "PHP " . PHP_MAJOR_VERSION . "." . PHP_MINOR_VERSION . "\n";
echo "OPcache: " . (extension_loaded('Zend OPcache') ? 'loaded' : 'not loaded') . "\n";
echo "cURL: " . (extension_loaded('curl') ? 'loaded' : 'not loaded') . "\n";
echo "PostgreSQL PDO: " . (extension_loaded('pdo_pgsql') ? 'loaded' : 'not loaded') . "\n";
echo "SQLite PDO: " . (extension_loaded('pdo_sqlite') ? 'loaded' : 'not loaded') . "\n";

Run the script:

php ~/test.php

Expected output after enabling PostgreSQL and SQLite support:

PHP 8.5
OPcache: loaded
cURL: loaded
PostgreSQL PDO: loaded
SQLite PDO: loaded

Test PHP with the Built-In Development Server

PHP includes a built-in development server for quick local checks without Nginx or Apache. Create a temporary phpinfo file:

echo "<?php phpinfo();" > ~/phpinfo.php

Start the local server:

php -S localhost:8080 -t ~

Open http://localhost:8080/phpinfo.php in a browser, then press Ctrl+C in the terminal when finished. Delete the test files afterward:

rm ~/test.php ~/phpinfo.php

The built-in server is for local development checks only. Use PHP-FPM with a web server for production sites.

Troubleshoot PHP on Arch Linux

Extension Not Loaded After Installation

Error: An installed extension does not appear in php -m.

Cause: The package installed the module file, but PHP still needs the corresponding extension= or zend_extension= line enabled.

Fix: Check whether the line is still commented. For PostgreSQL support, use:

grep -E '^;?extension=(pdo_pgsql|pgsql)' /etc/php/php.ini

If the lines start with ;, uncomment them and restart PHP-FPM:

sudo sed -i -e 's/^;extension=pdo_pgsql/extension=pdo_pgsql/' -e 's/^;extension=pgsql/extension=pgsql/' /etc/php/php.ini
sudo systemctl restart php-fpm

Verify the loaded modules:

php -m | grep -iE 'pdo_pgsql|pgsql'
pdo_pgsql
pgsql

PHP Fatal Error: Class ‘ZipArchive’ Not Found

Error: PHP Fatal error: Class 'ZipArchive' not found

Cause: The zip extension is not loaded.

Fix: Arch’s current php package ships zip. Check the line in php.ini and enable it if needed:

grep -E '^;?extension=zip' /etc/php/php.ini
sudo sed -i 's/^;extension=zip/extension=zip/' /etc/php/php.ini
sudo systemctl restart php-fpm

Verify the extension is loaded:

php -m | grep '^zip$'
zip

PHP Warning: Unable to Initialize Module

Error: PHP Warning: PHP Startup: <module>: Unable to initialize module

Cause: The extension was built for a different PHP branch, or an AUR extension was not rebuilt after a PHP update.

Fix: Reinstall official extensions with pacman. For example, reinstall php-pgsql when PostgreSQL modules fail to load:

sudo pacman -S php-pgsql
php -m | grep -iE 'pdo_pgsql|pgsql'

For AUR extensions, rebuild the exact package that matches your AUR PHP branch. Do not mix php84-* extensions with the official php runtime or official php-* extensions with php84.

PHP-FPM Socket Permission Denied

Error: A web server returns 502 Bad Gateway or logs a socket permission error when connecting to PHP-FPM.

Cause: The web server user cannot access the PHP-FPM socket, or the web-server configuration points to the wrong PHP-FPM socket path.

Fix: Check the socket owner and group:

grep -E '^(listen|listen.owner|listen.group)' /etc/php/php-fpm.d/www.conf
listen = /run/php-fpm/php-fpm.sock
listen.owner = http
listen.group = http

Update your web-server configuration or PHP-FPM pool so the socket path and user match, then restart PHP-FPM:

sudo systemctl restart php-fpm

Imagick dlopen Warnings

Error: php -i prints repeated ImageMagick dlopen warnings for missing media libraries.

Cause: php-imagick loads ImageMagick, and ImageMagick can advertise coder modules for optional formats whose libraries are not installed.

Fix: Install the optional ImageMagick dependency for the format you use, or leave the extension disabled if your application does not need Imagick. For JPEG 2000 warnings that mention libopenjp2, install openjpeg2:

sudo pacman -S openjpeg2

For media-codec warnings that mention libavcodec, install ffmpeg instead:

sudo pacman -S ffmpeg

Verify Imagick still loads after installing the matching support package:

php -i | grep 'imagick module'

Remove PHP from Arch Linux

Remove PHP only after confirming no local web application, PHP-FPM pool, Composer workflow, or system service still depends on it. PHP is often part of a larger web stack, and removing it can break active sites.

Stop and disable PHP-FPM when it is no longer needed:

sudo systemctl disable php-fpm --now

Remove only the packages you installed. This example matches the main runtime, PHP-FPM, Composer, and the common extension set used earlier:

sudo pacman -Rns php php-fpm composer php-gd php-sqlite php-pgsql php-apcu php-redis xdebug

Add optional packages such as php-sodium, php-tidy, php-xsl, php-imagick, php-legacy, or php-legacy-fpm only if you installed them. The -Rns flags remove the named packages, orphaned dependencies, and package backup files. If pacman refuses because another installed package depends on PHP, keep PHP installed or remove the dependent package first; do not force dependency breaks.

Optional media support libraries from Imagick troubleshooting are shared by other image and video tools. Remove one only when you installed it for this PHP stack and no other application needs it; substitute ffmpeg if that was the support package you added:

sudo pacman -R openjpeg2

Verify package removal with pacman:

pacman -Q php
error: package 'php' was not found

Pacman does not remove project directories, Composer global packages, Composer caches, website files, or application uploads. Back up anything you want to keep before deleting user data manually.

Optionally remove Composer’s user-level configuration and cache after you have backed up anything useful:

rm -rf ~/.config/composer ~/.cache/composer

Conclusion

You now have PHP installed on Arch Linux from the official repositories, with extension package names mapped to their enablement files, PHP-FPM ready for web-server integration, and Composer available for project dependencies. For database-backed PHP applications, pair this runtime with MariaDB, PostgreSQL, or SQLite on Arch Linux. For deeper Arch-specific PHP configuration, review the Arch Wiki PHP documentation.

Share this guide

Help another Linux user troubleshoot faster

Share this guide with someone troubleshooting Linux systems or saving it for later.

Follow LinuxCapable

Want more LinuxCapable guides in Google?

Add LinuxCapable as a preferred source so Google can show more of our fresh Linux tutorials in Top Stories and From your sources when relevant.

Add LinuxCapable as a preferred source on Google
Search LinuxCapable

Need another guide?

Search LinuxCapable for package installs, commands, troubleshooting, and follow-up guides related to what you just read.

Found this guide useful?

Support LinuxCapable to keep tutorials free and up to date.

Buy me a coffeeBuy me a coffee
Before commenting, please review our Comments Policy.
Formatting tips for your comment

You can use basic HTML to format your comment. Useful tags currently allowed in published comments:

You type Result
<code>command</code> command
<strong>bold</strong> bold
<em>italic</em> italic
<blockquote>quote</blockquote> quote block

Got a Question or Feedback?

We read and reply to every comment - let us know how we can help or improve this guide.

Verify before posting: