PHP

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.

You can find older versions of PHP in the AUR including php53AUR, php55AUR, php56AUR, php70AUR, php71AUR, php72AUR, php73AUR and php74AUR.

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 .

date.timezone = Europe/Berlin
  • If you want to display errors to debug your PHP code, change to in :
display_errors = On
  • The open_basedir directive limits the paths that can be accessed by PHP, thus increasing security at the expense of potentially interfering with normal program execution. Starting with PHP 7.0, it is no longer set by default to more closely match upstream so users who wish to use it must configure it manually. All symbolic links are resolved, so it is not possible to avoid this restriction with a symlink. The default Arch packages for certain webapps like & installs the webapps under /usr/share/webapps and creates a symlink pointing to the actual configuration files for those webapps under /etc/webapps. So, if you are setting up , make sure both those folders listed are in the . This will obviously be different for webapps installed in other locations. Example:
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-

Existing extensions are located in directory.

For example, to enable extension create file 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, , .

gd

For uncomment the line in :

extension=gd

Imagemagick

Install the 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 } as a dependency.

PECL

Make sure the package has been installed:

# pecl install imagick

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

Multithreading

If you wish to have POSIX multi-threading you will need the parallel extension. To install the extension using you are required to use a compiled version of PHP with the the thread safety support flag . 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 :

extension=pdo_mysql
extension=mysqli

You can add minor privileged MySQL users for your web scripts. You might also want to edit and add in mysqld section 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 .

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 package and uncomment the following lines in :

extension=pdo_pgsql
extension=pgsql

Sqlite

Install and configure SQLite, then install the package and uncomment the following lines in :

extension=pdo_sqlite
extension=sqlite3

XDebug

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

Install and uncomment the following line in :

zend_extension=xdebug

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

IMAP

Install and uncomment the line at :

extension=imap

Snuffleupagus

Install , uncomment the two lines in , 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, therefore to enable it you simply have to add or uncomment the following line in your PHP configuration file:

/etc/php/php.ini
zend_extension=opcache

A list of its options and suggested settings can be found in its official entry on the PHP website.

APCu

APCu can be installed with the package. You can then enable it by uncommenting the following line in , or adding it to your PHP configuration file:

extension=apcu

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.

Development tools

  • Eclipse PDT The PHP variant of Eclipse.
https://www.eclipse.org/pdt/ || eclipse-phpAUR

Commandline tools

Composer

Composer is a dependency manager for PHP. It can be installed with the 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"

Box

Box is an application for building and managing Phars. It can be installed with the package.

PDepend

PHP Depend (pdepend) is software metrics tool for php. It can be installed with the package.

PHP Coding Standards Fixer

PHP Coding Standards Fixer is a PSR-1 and PSR-2 Coding Standards fixer for your code. It can be installed with the package.

PHP-CodeSniffer

PHP CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards. It can be installed with the package.

phpcov

phpcov is a command-line frontend for the PHP_CodeCoverage library. It can be installed with the phpcovAUR package.

phpDox

phpDox is the documentation generator for PHP projects. This includes, but is not limited to, API documentation. It can be installed with the package.

PHPLoc

PHPLoc is a tool for quickly measuring the size of a PHP project. It can be installed with the package.

PhpMetrics

PhpMetrics provides various metrics about PHP projects. It can be installed with the package.

phptok

phptok is a tool for quickly dumping the tokens of a PHP sourcecode file. It can be installed with the package.

PHPUnit

PHPUnit is a programmer-oriented testing framework for PHP. It can be installed with the phpunitAUR package.

PHPUnit Skeleton Generator

PHPUnit Skeleton Generator is a tool that can generate skeleton test classes from production code classes and vice versa. It can be installed with the package.

Producer

Producer is a command-line quality-assurance tool to validate, and then release, your PHP library package. It can be installed with the package.

Troubleshooting

PHP Fatal error: Class 'ZipArchive' not found

Ensure the zip extension is enabled.

/etc/php/php.ini not parsed

If your 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 . If you are using cli, it is .

PHP Warning: PHP Startup: <module>: 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 .

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.

gollark: CC can only really send HTTP requests, do websockets, that sort of thing.
gollark: Technically, yes, with much work, but that wouldn't give it access to more I/O.
gollark: Sadly, it can't.
gollark: (It's running in an emulator because I can't be bothered to actually open the game)
gollark: I finally finished making the overengineered new update system for my "OS" for ComputerCraft (a Minecraft mod which adds computers) work!

See also

This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.