How to Install PHP on Arch Linux

Last updated Saturday, February 7, 2026 3:11 pm 12 min read

PHP is a server-side scripting language that powers the majority of dynamic websites on the internet, including WordPress, Laravel, and Drupal applications. Its mature ecosystem, built-in web server integration, and extensive extension library make it a practical choice for everything from simple contact forms to full-scale web applications and REST APIs. This guide covers how to install PHP on Arch Linux with PHP-FPM configured for web server integration, common extensions enabled, Composer available for dependency management, and a clear path for configuring and troubleshooting your PHP environment.

Update Arch Linux Before PHP Installation

Synchronize package databases and upgrade installed packages before installing new software. Arch Linux is a rolling release distribution, so regular updates prevent dependency conflicts:

sudo pacman -Syu

This guide uses sudo for commands 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 Linux provides two PHP branches in the official repositories. The php package tracks the latest stable release, while php-legacy provides the oldest actively supported branch for applications that require it.

PackageVersionSourcePurpose
php8.5.xOfficial repoLatest stable release with newest features and performance improvements
php-legacy8.3.xOfficial repoOldest actively supported branch for applications not yet compatible with the latest PHP
php848.4.xAURIntermediate branch for applications targeting PHP 8.4 specifically

For most users, the php package is recommended because it includes the latest performance improvements, security fixes, and OPcache enabled by default.

Install PHP (Latest)

Install the latest PHP from the official repositories:

sudo pacman -S php

Verify the installation:

php --version

Expected output:

PHP 8.5.2 (cli) (built: Jan 14 2026 16:37:32) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.5.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.5.2, Copyright (c), by Zend Technologies

The php package includes dozens of built-in modules such as curl, json, mbstring, openssl, PDO, zip, and Zend OPcache. List all loaded modules with:

php -m

Install PHP-Legacy

If your application specifically requires a PHP 8.3.x runtime, install the legacy branch. Both packages can coexist on the same system:

sudo pacman -S php-legacy

The legacy binary is available as php-legacy. Verify its version separately:

php-legacy --version

The php-legacy package has its own configuration at /etc/php-legacy/php.ini and matching extension packages prefixed with php-legacy- (for example, php-legacy-fpm, php-legacy-gd). Configure it independently from the main php package.

Install PHP 8.4 from the AUR

Because Arch Linux only ships the latest and oldest supported branches in the official repositories, intermediate versions like PHP 8.4 are not available through pacman. If your project requires PHP 8.4 specifically, install the php84 package from the AUR using an AUR helper such as paru:

paru -S php84

Verify the installation:

php84 --version

AUR PHP packages follow the same naming convention with a version prefix. For example, install extensions with paru -S php84-fpm php84-gd php84-pgsql. Configuration files are stored at /etc/php84/php.ini and /etc/php84/conf.d/.

AUR packages are community-maintained and must be rebuilt after major PHP updates. If an extension fails to load after a system update, rebuild the affected package with paru -S php84-extensionname.

Install PHP Extensions on Arch Linux

The base php package covers most general-purpose needs, but database drivers, image processing, caching, and debugging require additional extension packages. Extensions on Arch Linux are installed via pacman and then enabled in the PHP configuration.

Common PHP Extensions

The following table lists frequently used extensions available in the official repositories:

PackagePurposeEnable Method
php-gdImage processing (GD library)Uncomment in php.ini
php-sqliteSQLite database driverUncomment in php.ini
php-pgsqlPostgreSQL database driverUncomment in php.ini
php-sodiumModern cryptography (libsodium)Uncomment in php.ini
php-tidyHTML cleanup and repairUncomment in php.ini
php-xslXSL transformationsUncomment in php.ini
php-imagickImageMagick image processingUncomment in conf.d/imagick.ini
php-igbinaryBinary serializer (required by php-redis)Uncomment in conf.d/igbinary.ini
php-redisRedis cache driverUncomment in conf.d/redis.ini
php-apcuUserland opcode cachingUncomment in conf.d/apcu.ini
xdebugStep debugger and profilerUncomment in conf.d/xdebug.ini

Install and Enable Extensions

Install one or more extensions with pacman. This example installs the most common set for web application development:

sudo pacman -S php-gd php-sqlite php-pgsql php-imagick php-redis

Extensions like php-gd, php-sqlite, and php-pgsql require uncommenting their lines in /etc/php/php.ini. Extensions such as php-imagick, php-redis, and php-apcu ship with separate configuration files in /etc/php/conf.d/ that also require uncommenting.

Open the PHP configuration file:

sudo nano /etc/php/php.ini

Find and uncomment (remove the leading ;) the relevant extension lines. For example, to enable GD, SQLite, and PostgreSQL:

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

To enable MySQL/MariaDB support, uncomment these lines:

extension=mysqli
extension=pdo_mysql

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

Enable conf.d Extensions

Several extensions use separate configuration files in /etc/php/conf.d/ instead of php.ini. Install the remaining packages:

sudo pacman -S php-apcu xdebug

Enable igbinary (required by php-redis) and imagick, which were installed as dependencies in the previous step:

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

Enable redis after igbinary is active:

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

Enable APCu by uncommenting the extension line in its configuration file:

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

Enable Xdebug by uncommenting the zend_extension line:

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

Verify Loaded PHP Extensions

Confirm that the extensions are loaded:

php -m

Look for the enabled extensions in the output. To search for a specific extension:

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

Expected output:

apcu
gd
igbinary
imagick
pdo_pgsql
pdo_sqlite
pgsql
redis
sqlite3
xdebug
Xdebug

Xdebug appears twice because php -m lists it under both the PHP Modules and Zend Modules sections. This is normal behavior for Zend extensions.

Set Up PHP-FPM on Arch Linux

PHP-FPM (FastCGI Process Manager) is required for running PHP with web servers like Nginx or Apache. It manages a pool of PHP worker processes and handles requests through a Unix socket or TCP port.

Install and Start PHP-FPM

Install the PHP-FPM package:

sudo pacman -S php-fpm

Enable and start the PHP-FPM service:

sudo systemctl enable php-fpm --now

Verify the service is running:

systemctl status php-fpm

Expected output (abbreviated):

● php-fpm.service - The PHP FastCGI Process Manager
     Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; preset: disabled)
     Active: active (running)

Configure the PHP-FPM Pool

The default pool configuration is at /etc/php/php-fpm.d/www.conf. By default, PHP-FPM listens on a Unix socket at /run/php-fpm/php-fpm.sock with http as both the user and group. Point your web server at this socket when configuring PHP integration.

Key settings in www.conf to review:

  • listen = /run/php-fpm/php-fpm.sock: The socket path Nginx or Apache connects to
  • listen.owner = http and listen.group = http: Must match your web server’s user
  • pm = dynamic: Process manager mode — dynamic spawns workers based on demand
  • pm.max_children: Maximum number of worker processes (tune based on available RAM)

After making changes to PHP-FPM configuration, restart the service:

sudo systemctl restart php-fpm

Configure PHP on Arch Linux

The main PHP configuration file is /etc/php/php.ini. This section covers the most commonly adjusted settings for development and production environments.

Set the Timezone

PHP uses the system timezone by default, but explicitly setting it in php.ini prevents warnings from date/time functions. Open the configuration file:

sudo nano /etc/php/php.ini

Find the date.timezone line (around line 980), uncomment it, and set your timezone from the PHP supported timezones list:

date.timezone = America/New_York

Enable Error Display for Development

For development environments, enable error display to see PHP errors directly in the browser. Find the display_errors directive and change it to On:

display_errors = On

Set display_errors = Off on production servers. Displaying errors publicly can expose sensitive information such as file paths, database credentials, and application internals.

Adjust Upload and Memory Limits

Applications like WordPress and file upload services often need higher limits than the defaults. Adjust these values in php.ini based on your requirements:

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

After saving changes to php.ini, restart PHP-FPM for the settings to take effect:

sudo systemctl restart php-fpm

Verify OPcache Status

OPcache compiles PHP scripts into bytecode and caches them in shared memory, eliminating the need to parse and compile scripts on every request. OPcache is bundled with PHP and enabled by default since PHP 8.5. Verify it is active:

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

Install Composer PHP Dependency Manager on Arch Linux

Composer is the standard dependency manager for PHP projects. It handles library installation, autoloading, and version resolution. Composer is available in the official Arch Linux repositories:

sudo pacman -S composer

Verify the installation:

composer --version
Composer version 2.9.5 2026-01-29 11:40:53

To install global Composer packages for your user, add the Composer vendor bin directory to your PATH. Open your shell configuration file:

nano ~/.bashrc

Add this line at the end:

export PATH="$HOME/.config/composer/vendor/bin:$PATH"

Apply the change:

source ~/.bashrc

Test Composer by creating a new project or requiring a package:

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

Expected output confirms Composer created the project skeleton:

Creating ./composer.json

Clean up the test directory when finished:

rm -rf ~/php-test

Test PHP Installation on Arch Linux

Verify that PHP can execute scripts and access the extensions you enabled.

Run a Test Script

Create a test PHP file:

nano ~/test.php

Add the following code:

<?php
echo "PHP " . phpversion() . "\n";
echo "Loaded extensions: " . count(get_loaded_extensions()) . "\n";
echo "OPcache: " . (function_exists('opcache_get_status') ? 'available' : 'unavailable') . "\n";
echo "cURL: " . (extension_loaded('curl') ? 'loaded' : 'not loaded') . "\n";
echo "PDO drivers: " . implode(', ', PDO::getAvailableDrivers()) . "\n";

Save the file and run it:

php ~/test.php

Expected output (varies based on enabled extensions):

PHP 8.5.2
Loaded extensions: 44
OPcache: available
cURL: loaded
PDO drivers: pgsql, sqlite

Test PHP-FPM with the Built-in Web Server

PHP includes a built-in development web server for quick testing without Nginx or Apache. Create a phpinfo file:

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

Start the built-in server:

php -S localhost:8080 -t ~

Open http://localhost:8080/phpinfo.php in a browser to see the full PHP configuration page. Press Ctrl+C to stop the server when finished. Delete the test files afterward:

rm ~/test.php ~/phpinfo.php

The built-in web server is intended for development and testing only. For production deployments, use PHP-FPM with a dedicated web server like Nginx or Apache.

Troubleshoot PHP on Arch Linux

Extension Not Loaded After Installation

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

Cause: Most extensions require manual enablement in /etc/php/php.ini by uncommenting the corresponding extension= line. Some extensions use separate files in /etc/php/conf.d/.

Fix: Check which file controls the extension. For example, for php-gd:

grep 'extension=gd' /etc/php/php.ini

If the line starts with ;, it is commented out. Uncomment it and restart PHP-FPM:

sudo sed -i 's/;extension=gd/extension=gd/' /etc/php/php.ini
sudo systemctl restart php-fpm

For extensions managed via conf.d, check the corresponding file:

ls /etc/php/conf.d/
cat /etc/php/conf.d/apcu.ini

PHP Fatal Error: Class ‘ZipArchive’ Not Found

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

Cause: The zip extension is disabled in php.ini.

Fix: Uncomment the zip extension line in /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 compiled against a different PHP version. This typically happens with AUR-installed extensions after a PHP update.

Fix: Rebuild the affected extension from the AUR or reinstall the official package:

sudo pacman -S php-imagick

If the extension was installed from the AUR, rebuild it using your AUR helper:

paru -S php-extensionname

PHP-FPM Socket Permission Denied

Error: Your web server returns a 502 Bad Gateway or logs a “permission denied” error when connecting to the PHP-FPM socket.

Cause: The web server user does not have permission to read the PHP-FPM socket file.

Fix: Verify that listen.owner and listen.group in /etc/php/php-fpm.d/www.conf match your web server’s user. The default Arch Linux configuration uses http for both, which matches the default Nginx and Apache user:

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

If your web server runs as a different user, update these values and restart PHP-FPM:

sudo systemctl restart php-fpm

Remove PHP from Arch Linux

If PHP-FPM is running, stop and disable the service before removal:

sudo systemctl stop php-fpm && sudo systemctl disable php-fpm

Remove PHP and all installed extensions. Adjust this command to include only the packages you have installed:

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

The -Rns flags remove the packages (-R), orphaned dependencies (-s), and configuration backup files (-n).

Verify removal:

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

Pacman does not remove Composer project files, vendor directories, or application code stored in your home directory or web root. Back up any project files you want to keep before cleaning up manually.

rm -rf ~/.config/composer

Frequently Asked Questions About PHP on Arch Linux

What is the difference between php and php-legacy on Arch Linux?

The php package provides the latest stable PHP release (currently 8.5.x), while php-legacy provides the oldest actively supported branch (currently 8.3.x). Both can be installed simultaneously. Use php-legacy only if your application specifically requires an older PHP version.

Why is my PHP extension not loading after installation on Arch Linux?

Most PHP extensions require manual enablement after installation. Extensions like php-gd, php-sqlite, and php-pgsql need their lines uncommented in /etc/php/php.ini. Others like php-apcu and xdebug require uncommenting in their respective files under /etc/php/conf.d/. Run php -m to verify which extensions are currently loaded.

Is OPcache enabled by default in PHP on Arch Linux?

Yes. Starting with PHP 8.5, OPcache is bundled and enabled by default. You can verify this by running php -i | grep opcache.enable, which should return On. No additional configuration is needed for basic OPcache functionality.

How do I switch between PHP versions on Arch Linux?

Install both php and php-legacy packages. The latest PHP is available as the php command, while the legacy version uses the php-legacy command. Each has its own configuration directory and extension packages. For web servers, configure the appropriate PHP-FPM service (php-fpm or php-legacy-fpm) in your server configuration.

Do I need to restart PHP-FPM after editing php.ini on Arch Linux?

Yes. Changes to php.ini or files in /etc/php/conf.d/ only take effect after restarting the PHP-FPM service with sudo systemctl restart php-fpm. The CLI interpreter (php command) reads the configuration on each invocation, so CLI changes are immediate.

Conclusion

You now have PHP installed on Arch Linux with extensions configured, PHP-FPM ready for web server integration, and Composer available for dependency management. For database-driven PHP applications, pair this setup with MariaDB, PostgreSQL, or SQLite on Arch Linux. For deeper coverage of PHP modules, web server integration, and PHP-FPM tuning, refer to the Arch Wiki PHP documentation.

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 coffee Buy 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:

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

Leave a Comment

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

Let us know you are human: