PHP - ArchWiki (original) (raw)

PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.

Installation

Install the php package.

Due to application software that cannot use the latest PHP version, you may install php-legacy alongside. That package provides the oldest still supported (at least Security Support) PHP branch and must be configured within the applications that require it.

You can find older and pinned versions of PHP in the Arch User Repository (AUR):

Those are binary builds using the openSUSE Build Service.

Running

While PHP can be run standalone, it is typically used with web servers. That requires installing additional packages and editing configuration files. For common setups, see the following:

To run PHP scripts as plain CGI, you need the php-cgi package.

Configuration

The main PHP configuration file is well-documented and located at /etc/php/php.ini.

date.timezone = Europe/Berlin

display_errors = On

open_basedir = /srv/http/:/var/www/:/home/:/tmp/:/var/tmp/:/var/cache/:/usr/share/pear/:/usr/share/webapps/:/etc/webapps/

Extensions

A number of commonly used PHP extensions can also be found in the official repositories:

$ pacman -Ss php-

Tip Instead of editing /etc/php/php.ini, an extension may be enabled/configured in the /etc/php/conf.d directory instead (e.g. /etc/php/conf.d/imagick.ini)

Existing extensions are located in /usr/lib/php/modules directory.

For example, to enable ext-iconv extension create file /etc/php/conf.d/extensions.ini with line:

extension=iconv

Extensions for current and older versions of PHP are also available in the AUR under prefixes like php- and php56-, e.g. php-imagick, php-redis, php56-mcryptAUR.

gd

For php-gd uncomment the line in /etc/php/php.ini:

extension=gd

Imagemagick

Install the imagemagick package and install one of the listed PHP extension library.

Install php-imagick, it will create the file /etc/php/conf.d/imagick.ini to configure the extension.

If you want imagemagick to have SVG support, e.g. for nextcloud, then install librsvg as a dependency.

PECL

Make sure the php-pearAUR package has been installed:

pecl install imagick

Create a /etc/php/conf.d/imagick.ini and enable the extension:

/etc/php/conf.d/imagick.ini

extension=imagick

Multithreading

If you wish to have POSIX multi-threading you will need the parallel extension. To install the extension using pecl you are required to use a compiled version of PHP with the thread safety support flag --enable-maintainer-zts. Currently the most clean way to do this would be to rebuild the original package with the flag. Instruction can be found on the PHP pthreads extension page.

PCNTL

PCNTL allows you to create process directly into the server side machine. While this may seen as something you would want, it also gives PHP the power to mess things up really badly. So it is a PHP extension that cannot be loaded like other more convenient extension. This is because of the great power it gives to PHP. To enable it PCNTL has to be compiled into PHP.

The php package on Arch Linux is currently built with "--enable-pcntl", so that it should be available by default.

MySQL/MariaDB

Install and configure MySQL/MariaDB as described in MariaDB.

Uncomment the following lines in /etc/php/php.ini:

extension=pdo_mysql extension=mysqli

Note extension=mysql was removed in PHP 7.0.

You can add minor privileged MySQL users for your web scripts. You might also want to edit /etc/my.cnf.d/server.cnf and add in mysqld section skip-networking line so the MySQL server is only accessible by the localhost, as per MariaDB#Enable access locally only via Unix sockets. You have to restart MySQL for changes to take effect.

Redis

Install and configure Redis, then install php-redis.

Uncomment the line of the package, e.g. /etc/php/conf.d/redis.ini. Also ensure that the igbinary extension is enabled (also uncommented) in /etc/php/conf.d/igbinary.ini

PostgreSQL

Install and configure PostgreSQL, then install the php-pgsql package and uncomment the following lines in /etc/php/php.ini:

extension=pdo_pgsql extension=pgsql

Sqlite

Install and configure SQLite, then install the php-sqlite package and uncomment the following lines in /etc/php/php.ini:

extension=pdo_sqlite extension=sqlite3

XDebug

XDebug allows you to easily debug (using modified var_dump function), profile, or trace PHP code.

Install xdebug and uncomment the following line in /etc/php/conf.d/xdebug.ini:

zend_extension=xdebug.so

You can configure what XDebug does by adding a xdebug.mode line to the same file. By default, it is set to xdebug.mode=develop.

Note To always attempt to start a remote debugging session and connect to a debugging client it is also necessary to set xdebug.remote_autostart=on. For Xdebug 3 the default port is 9003, to change it set xdebug.remote_port=9000

Snuffleupagus

Install php-snuffleupagus, uncomment the two lines in /etc/php/conf.d/snuffleupagus.ini, and put the path to the snuffleupagus.rules file in the second line:

extension=snuffleupagus.so sp.configuration_file=/etc/php/conf.d/snuffleupagus.rules

Caching

There are two kinds of caching in PHP: opcode/bytecode caching and userland/user data caching. Both allow for substantial gains in applications speed, and therefore should be enabled wherever possible.

OPcache

OPcache comes bundled with the standard PHP distribution and is enabled by default since version 8.5 (November 2025). A list of its options and suggested settings can be found in its official entry on the PHP website.

Warning If you choose to apply the suggested settings its manual offers, be sure to read carefully the first comment below those instructions as well. In some configurations those settings result in errors such as zend_mm_heap corrupted being produced.

APCu

APCu can be installed with the php-apcu package. You can then enable it by uncommenting the following line in /etc/php/conf.d/apcu.ini, or adding it to your PHP configuration file:

extension=apcu

This article or section is out of date.

Its author recommends a few suggested settings, among which:

Tip You can add those settings either to APCu's own /etc/php/conf.d/apcu.ini or directly to your PHP configuration file. Just make sure not to enable the extension twice as it will result in errors being diplayed in the system logs.

https://code.visualstudio.com/ || code

http://www.aptana.com/products/studio3.html || aptana-studioAUR

https://www.eclipse.org/pdt/ || eclipse-php-binAUR

http://komodoide.com/ || komodo-ideAUR, editor only: komodo-editAUR

https://netbeans.org/ || netbeans

https://www.jetbrains.com/phpstorm/ || phpstormAUR, 30-day trial: phpstorm-eapAUR

Composer

Composer is a dependency manager for PHP. It can be installed with the composer package.

Allow user-wide installations

To allow global package installations for the current user (e.g. $ composer global require "package/name"), you may want to specify a default location by using an environment variable:

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

Usage with php-legacy

Some applications may require php-legacy, but by default, composer runs with the latest version of PHP. Thus, in order to use the legacy version instead, one must replace composer with php-legacy /usr/bin/composer in their scripts, makefiles and other applicable locations. An example of this is when building Nextcloud apps.

Others

https://box-project.github.io/box2/ || php-boxAUR

https://pdepend.org/ || pdependAUR

https://github.com/FriendsOfPHP/PHP-CS-Fixer || php-cs-fixerAUR

https://pear.php.net/package/PHP_CodeSniffer/ || php-codesnifferAUR

https://github.com/sebastianbergmann/phpcov || phpcovAUR

http://phpdox.de/ || phpdoxAUR

https://github.com/sebastianbergmann/phploc/ || phplocAUR

https://www.phpmetrics.org/ || phpmetricsAUR

https://phpunit.de || phpunitAUR

http://getproducer.org/ || producerAUR

Troubleshooting

PHP Fatal error: Class 'ZipArchive' not found

Ensure the zip extension is enabled.

/etc/php/php.ini

extension=zip

/etc/php/php.ini not parsed

If your php.ini is not parsed, the ini file is named after the sapi it is using. For instance, if you are using uwsgi, the file would be called /etc/php/php-uwsgi.ini. If you are using cli, it is /etc/php/php-cli.ini.

PHP Warning: PHP Startup: : Unable to initialize module

When running php, this error indicates that the aforementioned module is out of date. This will rarely happen in Arch Linux, since maintainers make sure core PHP and all modules be only available in compatible versions.

This might happen in conjunction with a module compiled from the AUR. You usually could confirm this by looking at the dates of the files /usr/lib/php/modules/.

To fix, find a compatible update for your module, probably by looking up the AUR using its common name.

If it applies, flag the outdated AUR package as outdated.

Permission denied issues when using php-fpm

There is a default AppArmor php-fpm profile which prohibits php-fpm from accessing files outside system paths. You may need to manually allow access to your custom web path by creating /etc/apparmor.d/local/php-fpm:

/etc/apparmor.d/local/php-fpm

/path/to/my/web/path/** rw,

See also