Difference between revisions of "PHP"

From ArchWiki
Jump to: navigation, search
m
(MySQL/MariaDB: Remove duplicated information. Already mentioned in MySQL.)
 
(111 intermediate revisions by 35 users not shown)
Line 1: Line 1:
[[Category:Programming language]]
+
[[Category:Programming languages]]
 
[[de:PHP]]
 
[[de:PHP]]
 
[[es:PHP]]
 
[[es:PHP]]
 +
[[fr:Lamp]]
 +
[[it:PHP]]
 +
[[ja:PHP]]
 +
[[ru:PHP]]
 
[[sr:PHP]]
 
[[sr:PHP]]
 +
[[zh-CN:PHP]]
 
[http://www.php.net/ PHP] is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.
 
[http://www.php.net/ PHP] is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.
  
 
== Installation ==
 
== Installation ==
[[pacman|Install]] the {{Pkg|php}} package from the [[Official Repositories|official repositories]].
 
  
A number of commonly used PHP extensions can also be found in the official repository:
+
[[Install]] the {{Pkg|php}} package from the [[official repositories]].
# pacman -Ss php-
+
  
== Setup ==
+
Note that to run PHP scripts as plain CGI, you need the {{Pkg|php-cgi}} package.
While PHP can be run standalone, it is typically used with http servers such as apache, nginx and lighttpd.
+
 
* '''nginx''': see [[Nginx]] page.
+
== Running ==
* '''apache''': to setup PHP, Apache and MySQL, commonly known as the LAMP, see [[LAMP]] article.
+
 
* '''lighttpd''': see [[Lighttpd]] article.
+
While PHP can be run standalone, it is typically used with http servers such as [[Apache HTTP Server]] (this is frequently called [[LAMP]] setup), [[nginx]], [[lighttpd]] and [[Hiawatha]].
 +
 
 +
To run PHP standalone issue the {{ic|php -S localhost:8000 -t public_html/}} command. See [https://secure.php.net/manual/en/features.commandline.webserver.php documentation].
  
 
== Configuration ==
 
== Configuration ==
The main PHP confiuration file is well-documented and located at {{ic|/etc/php/php.ini}}.
+
 
=== Extensions ===
+
The main PHP configuration file is well-documented and located at {{ic|/etc/php/php.ini}}.
For {{Pkg|php-gd}} uncomment the line
+
 
 +
* It is recommended to set your timezone ([https://secure.php.net/manual/en/timezones.php list of timezones]) in {{ic|/etc/php/php.ini}} like so:
 +
 
 +
date.timezone = Europe/Berlin
 +
 
 +
* If you want to display errors to debug your PHP code, change {{ic|display_errors}} to {{ic|On}} in {{ic|/etc/php/php.ini}}:
 +
 
 +
display_errors=On
 +
 
 +
* The [http://php.net/open-basedir 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 [https://www.archlinux.org/news/php-70-packages-released/ no longer set by default] to more closely match upstream so users who wish to use it must configure it manually. Example:
 +
 
 +
open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/
 +
 
 +
== Extensions ==
 +
 
 +
A number of commonly used PHP extensions can also be found in the official repositories:
 +
 
 +
$ pacman -Ss php-
 +
 
 +
{{Tip|Instead of editing {{ic|/etc/php/php.ini}}, a extension may be enabled/configured in the {{ic|/etc/php/conf.d}} directory instead (e.g. {{ic|/etc/php/conf.d/gd.ini}})}}
 +
 
 +
=== gd ===
 +
 
 +
For {{Pkg|php-gd}} uncomment the line in {{ic|/etc/php/php.ini}}:
 +
 
 
  extension=gd.so
 
  extension=gd.so
  
== Zend Core + Apache ==
+
=== imagemagick ===
Zend Core is the official PHP distribution provided by [http://www.zend.com zend.com]. It includes an installer/updater, zend optimizer, oracle support, and necessary libraries. However, it lacks support for postgresql, firebird, and odbc.
+
 
* Install {{Pkg|mod_fcgid}}, a FastCGI module for Apache (the official one sucks).
+
For {{Pkg|imagemagick}} run {{ic|# pecl install imagick}}. The ''pecl'' binary is included in the {{AUR|php-pear}} package. Then add
* Install Zend Core (official PHP distribution)
+
 
** Uninstall the {{Pkg|php}} package.
+
extension=imagick.so
** Download and install zend core from [http://www.zend.com/products/zend_core] ; '''don't''' install the bundle apache or tell it to setup your web server. It always installs to {{ic|/usr/local/Zend/Core}} due to hard-coded path.
+
 
** Create a script {{ic|/usr/local/bin/zendcore}} and create symlinks to ''php'', ''php-cgi'', ''pear'', ''phpize'' under ''/usr/local/bin''<br>{{ic|1=#!/bin/bash                                                                                                                                      <br>export LD_LIBRARY_PATH="/usr/local/Zend/Core/lib"<br>exec /usr/local/Zend/Core/bin/`basename $0` "$@"}}
+
to {{ic|/etc/php/php.ini}}.
* Setup Apache:
+
 
** In {{ic|/etc/httpd/conf/httpd.conf}}, add<br>{{ic|LoadModule fcgid_module lib/apache/mod_fcgid.so<br><Directory /srv/http><br>AddHandler fcgid-script .php<br>FCGIWrapper /usr/local/bin/php-cgi .php<br>Options ExecCGI<br>Allow from all<br></Directory><br>SocketPath /tmp/fcgidsock<br>SharememPath /tmp/fcgidshm}}
+
=== pthreads ===
** Remember to change the Directory path
+
 
* Disable Zend Optimizer (so you can use cache):
+
If you wish to have POSIX multi-threading you will need the pthreads extension. To install the pthreads (http://pecl.php.net/package/pthreads) extension using {{ic|pecl}} you are required to use a compiled version of PHP with the the thread safety support flag {{ic|--enable-maintainer-zts}}. Currently the most clean way to do this would be to rebuild the original package with the flag.
** Edit {{ic|/etc/php.ini}}, uncomment the following line near the end of file:<br>{{ic|<nowiki>zend_extension_manager.optimizer="/usr/local/Zend/Core/lib/zend/optimizer"</nowiki>}}
+
 
* Install APC (Alternative PHP Cache):
+
Instruction can be found on the [[PHP pthreads extension]] page.
** Run {{ic|pear install pecl.php.net/apc}} as superuser.
+
 
** Edit {{ic|/etc/php.ini}}, add the line after ''"; Zend Core extensions..."'' (line 1205):<br>{{ic|<nowiki>extension=apc.so</nowiki>}}
+
=== PCNTL ===
* Update Zend Core and/or install other components
+
 
** Just run {{ic|/usr/local/Zend/Core/setup}}
+
PCNTL allows you to create process directly into the server side machine. While this may seen as something you would want, it also gives the power to PHP to mess things up really bad. 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 (by default it is disabled) PCNTL has to be compiled into PHP.
 +
 
 +
=== MySQL/MariaDB ===
 +
 
 +
Install and configure MySQL/MariaDB as described in [[MariaDB]].
 +
 
 +
Uncomment [https://secure.php.net/manual/en/mysqlinfo.api.choosing.php the following lines] in {{ic|/etc/php/php.ini}}:
 +
 
 +
extension=pdo_mysql.so
 +
extension=mysqli.so
 +
 
 +
{{Warning|{{ic|mysql.so}} was [https://secure.php.net/manual/en/migration70.removed-exts-sapis.php removed] in PHP 7.0.}}
 +
 
 +
You can add minor privileged MySQL users for your web scripts. You might also want to edit {{ic|/etc/mysql/my.cnf}} and uncomment the {{ic|skip-networking}} line so the MySQL server is only accessible by the localhost. You have to restart MySQL for changes to take effect.
 +
 
 +
=== PostgreSQL ===
 +
 
 +
Install and configure [[PostgreSQL]], then install the {{pkg|php-pgsql}} package and uncomment the following lines in {{ic|/etc/php/php.ini}}:
 +
 
 +
extension=pdo_pgsql.so
 +
extension=pgsql.so
 +
 
 +
=== Sqlite ===
 +
 
 +
Install and configure [[SQLite]], then install the {{pkg|php-sqlite}} package and uncomment the following lines in {{ic|/etc/php/php.ini}}:
 +
 
 +
extension=pdo_sqlite.so
 +
extension=sqlite3.so
 +
 
 +
=== XDebug ===
 +
 
 +
XDebug allows you to easily debug php code using modified var_dump() function. Install {{Pkg|xdebug}} and uncomment the lines at  {{ic|/etc/php/conf.d/xdebug.ini}}:
 +
 
 +
zend_extension=xdebug.so
 +
xdebug.remote_enable=on
 +
xdebug.remote_host=127.0.0.1
 +
xdebug.remote_port=9000
 +
xdebug.remote_handler=dbgp
 +
 
 +
=== IMAP ===
 +
 
 +
Install {{Pkg|php-imap}} and uncomment the line at  {{ic|/etc/php/php.ini}}:
 +
 
 +
extension=imap.so
 +
 
 +
== 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.
 +
 
 +
* [[wikipedia:Zend Opcache|Zend OPCache]] provides only ''opcode'' caching.
 +
* [https://github.com/krakjoe/apcu/ APCu] provides only ''userland'' caching.
 +
 
 +
For optimal caching, you should enable '''both'''. To do this, follow ''both'' [[#OPCache]] ''and'' [[#APCu]].
 +
 
 +
=== 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 [[#Configuration|PHP configuration file]]:
 +
{{hc|/etc/php/php.ini|2=zend_extension=opcache.so}}
 +
 
 +
A list of its options and suggested settings can be found in its [https://secure.php.net/manual/en/book.opcache.php official entry] on the PHP website.
 +
 
 +
{{Warning|If you choose to apply the [https://secure.php.net/manual/en/opcache.installation.php#opcache.installation.recommended suggested settings] its manual offers, be sure to read carefully [https://secure.php.net/manual/en/opcache.installation.php#114567 the first comment] below those instructions as well. In some configurations those settings result in errors such as {{ic|zend_mm_heap corrupted}} being produced.}}
 +
 
 +
=== APCu ===
 +
 
 +
APCu can be installed with the {{Pkg|php-apcu}} package. You can then enable it by uncommenting the following line in {{ic|/etc/php/conf.d/apcu.ini}}, or adding it to your [[#Configuration|PHP configuration file]]:
 +
 
 +
extension=apcu.so
 +
 
 +
Its author recommends a few [https://github.com/krakjoe/apcu/blob/master/INSTALL suggested settings], among which:
 +
* {{ic|1=apc.enabled=1}} and {{ic|1=apc.shm_size=32M}} are not really required as they represent the [https://secure.php.net/manual/en/apc.configuration.php default values];
 +
* {{ic|1=apc.ttl=7200}} on the other hand seems [https://secure.php.net/manual/en/apc.configuration.php#ini.apc.ttl rather beneficial];
 +
* finally, {{ic|1=apc.enable_cli=1}}, which although [https://secure.php.net/manual/en/apc.configuration.php#ini.apc.enable-cli not recommended] by the manual may be required by some software such as [https://github.com/owncloud/core/issues/17329#issuecomment-119248944 ownCloud].
 +
 
 +
{{Tip|You can add those settings either to APCu's own {{ic|/etc/php/conf.d/apcu.ini}} '''or''' directly to your [[#Configuration|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 ==
 
== Development tools ==
  
=== Komodo ===
+
=== Aptana Studio ===
Good integration for PHP+HTML+JavaScript. Lacks code formatting and unicode support in doc comments.
+
  
[http://www.activestate.com/products/komodo_ide/ Komodo IDE] | [http://www.activestate.com/products/komodo_edit/ Komodo Edit (free)]
+
[http://www.aptana.com/products/studio3.html Aptana Studio] is an IDE for programming in PHP and web development. It can be installed with the {{AUR|aptana-studio}} package. Does not have a PHP debugger as of version 3.2.2.
  
Add custom encodings:
+
=== Eclipse PDT ===
*Edit {{ic|''KOMODO_INSTALL_DIR''/lib/mozilla/components/koEncodingServices.py}}, line 84, add:
+
 
  ('cp950', 'Chinese(CP-950/Big5)', 'CP950', &#39;&#39;, 1,'cp950'),
+
[http://www.eclipse.org/pdt/ Eclipse PDT] is the PHP variant of Eclipse. It can be installed with the {{Pkg|eclipse-php}} package. See [[Eclipse]] for more information.
  ('cp936', 'Chinese(CP-936/GB2312)', 'CP936', &#39;&#39;, 1,'cp936'),
+
 
  ('GB2312', 'Chinese(GB-2312)', 'GB2312', &#39;&#39;, 1,'GB2312'),
+
You would need other plugins for JavaScript support and DB query.
  ....
+
 
The format is (''encoding name in python'', ''description'', ''short description'', BOM, ''is ASCII-superset?'', ''font encoding'')
+
=== Komodo ===
 +
 
 +
[http://komodoide.com/ Komodo] is an IDE with good integration for PHP+HTML+JavaScript. [http://komodoide.com/komodo-edit/ Komodo Edit] is a free editor-only variant and installable with the {{AUR|komodo-edit}} package.
  
 
=== Netbeans ===
 
=== Netbeans ===
A complete IDE for many languages including PHP. Includes features like debugging, refactoring, code tempalting, autocomplete, XML features, and web design and development functionalities (very good CSS autocomplete functionality and PHP/JavaScript code notifications/tips).
 
  
=== Eclipse PDT ===
+
[https://netbeans.org/ NetBeans IDE] is a complete IDE for many languages including PHP. Includes features like debugging, refactoring, code templating, autocomplete, XML features, and web design and development functionalities (very good CSS autocomplete functionality and PHP/JavaScript code notifications/tips). Install it with the {{Pkg|netbeans}} package.
[http://www.zend.com/pdt Eclipse PDT] is not very complete at the current stage (v0.7); for instance, it cannot pop-up class list automatically when you type, though you can add custom auto-activation trigger keys.
+
  
You would need other plugins for javascript support and DB query.
+
=== PhpStorm ===
 +
 
 +
[[Wikipedia:PhpStorm|JetBrains PhpStorm]] is a commercial, cross-platform IDE for PHP built on JetBrains' IntelliJ IDEA platform. It can be installed with the {{AUR|phpstorm}} package, or with {{AUR|phpstorm-eap}} for the 30-day trial version. You can get a free license for education from Jetbrains.[https://www.jetbrains.com/student/]
  
 
=== Zend Studio ===
 
=== Zend Studio ===
[http://www.zend.com/products/studio/ Zend Studio] is the official PHP IDE, based on eclipse. The IDE has autocomplete, advanced code formatting, WYSIWYG html editor, refactoring, and all the eclipse features such as db access and version control integration and whatever you can get from other eclipse plugins.
 
  
=== Aptana Studio ===
+
[http://www.zend.com/products/studio/ Zend Studio] is the official PHP IDE, based on eclipse. The IDE has autocomplete, advanced code formatting, WYSIWYG html editor, refactoring, and all the eclipse features such as db access and version control integration and whatever you can get from other eclipse plugins. You can install it with the {{AUR|zendstudio}} package.
A good IDE for programming in PHP and web development. The current version (3.2.2) does not have a PHP debugger.
+
  
=== Zend Code Analyzer ===
+
== Commandline tools ==
A PHP code analyzer from Zend Studio. The program is indispensable for any serious PHP coding.
+
  
==== Installation ====
+
=== Box ===
* Download and install Zend Studio Neon
+
* In the installation dir, run {{ic|find . -name "ZendCodeAnalyzer}} to get the path.
+
* Copy ZendCodeAnalyzer to {{ic|/usr/local/bin/zca}}
+
* Now you can remove zend studio; you won't need a key or anything.
+
  
==== Vim Integration ====
+
[http://box-project.github.io/box2/ Box] is an application for building and managing Phars.
Add the following lines into your {{ic|.vimrc}}:
+
It can be installed with the {{AUR|php-box}} package.
autocmd FileType php setlocal makeprg=zca\ %<.php
+
autocmd FileType php setlocal errorformat=%f(line\ %l):\ %m
+
  
==== Eclipse Integration ====
+
=== Composer ===
''Error Link'' plugin:
+
* Symlink ''zca'' to ''build.zca'' (so Error Link can recognize it)
+
* Install [http://sunshade.sourceforge.net/ Sunshade] plugin suite;
+
* Preference -> Sunshade -> Error Link -> Add: ''{{ic|^(.*\.php)\(line (\d+)\): ()(.*)}}''
+
* Run -> External Tools -> Open External Tools Dialog -> Select "Program" -> Clicn on "New":<br>Name: Zend Code Analyzer<br>Location: ''/usr/local/bin/build.zca''<br>Working Directory: ''${container_loc}''<br>Arguments: ''--recursive ${resource_name}''
+
  
==== Komodo Integration ====
+
[https://getcomposer.org/ Composer] is a dependency manager for PHP.
Toolbox -> Add -> New Command:
+
It can be installed with the {{Pkg|composer}} package.
* Command: ''zca --recursive %F''
+
 
* Run in: Command Output Tab
+
=== PDepend ===
* Parse output with: ''{{ic|^(?P<file>.+?)\(line (?P<line>\d+)\): (?P<content>.*)$}}''
+
 
* Select ''Show parsed output as a list''
+
[http://pdepend.org/ PHP Depend] (pdepend) is software metrics tool for php.
 +
It can be installed with the {{AUR|pdepend}} package.
 +
 
 +
=== PHP Coding Standards Fixer ===
 +
 
 +
[http://cs.sensiolabs.org/ PHP Coding Standards Fixer] a is PSR-1 and PSR-2 Coding Standards
 +
fixer for your code.
 +
It can be installed with the {{AUR|php-cs-fixer}} package.
 +
 
 +
=== PHP-CodeSniffer ===
 +
 
 +
[http://pear.php.net/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 {{AUR|php-codesniffer}} package.
 +
 
 +
=== phpcov ===
 +
 
 +
[https://github.com/sebastianbergmann/phpcov phpcov] is a command-line frontend for the PHP_CodeCoverage library.
 +
It can be installed with the {{AUR|phpcov}} package.
 +
 
 +
=== phpDox ===
 +
 
 +
[http://phpdox.de/ phpDox] is the documentation generator for PHP projects. This includes, but is not limited to, API documentation.
 +
It can be installed with the {{AUR|phpdox}} package.
 +
 
 +
=== PHPLoc ===
 +
 
 +
[https://github.com/sebastianbergmann/phploc/ PHPLoc] is a tool for quickly measuring the size of a PHP project.
 +
It can be installed with the {{AUR|phploc}} package.
 +
 
 +
=== PhpMetrics ===
 +
 
 +
[http://www.phpmetrics.org/ PhpMetrics] provides various metrics about PHP projects.
 +
It can be installed with the {{AUR|phpmetrics}} package.
 +
 
 +
=== phptok ===
 +
 
 +
[https://github.com/sebastianbergmann/phptok phptok] is a tool for quickly dumping the tokens of a PHP sourcecode file.
 +
It can be installed with the {{AUR|phptok}} package.
 +
 
 +
=== PHPUnit ===
 +
 
 +
[https://phpunit.de PHPUnit] is a programmer-oriented testing framework for PHP.
 +
It can be installed with the {{AUR|phpunit}} package.
 +
 
 +
=== PHPUnit Skeleton Generator===
 +
 
 +
[https://github.com/sebastianbergmann/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 {{AUR|phpunit-skeleton-generator}} package.
  
 
== Troubleshooting ==
 
== Troubleshooting ==
 +
 
=== PHP Fatal error:  Class 'ZipArchive' not found ===
 
=== PHP Fatal error:  Class 'ZipArchive' not found ===
 +
 
Ensure the zip extension is enabled.
 
Ensure the zip extension is enabled.
 
{{hc|$ grep zip /etc/php/php.ini|2=
 
{{hc|$ grep zip /etc/php/php.ini|2=
 
extension=zip.so}}
 
extension=zip.so}}
 +
 +
=== /etc/php/php.ini not parsed ===
 +
 +
If your {{ic|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 {{ic|/etc/php/php-uwsgi.ini}}. If you are using cli, it is {{ic|/etc/php/php-cli.ini}}.
 +
 +
=== PHP Warning:  PHP Startup: ''<module>'': Unable to initialize module ===
 +
 +
When running {{ic|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 {{ic|/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''.
 +
 +
== See also ==
 +
 +
* [http://www.php.net/ PHP Official Website]

Latest revision as of 05:36, 8 June 2016

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 from the official repositories.

Note that to run PHP scripts as plain CGI, you need the php-cgi package.

Running

While PHP can be run standalone, it is typically used with http servers such as Apache HTTP Server (this is frequently called LAMP setup), nginx, lighttpd and Hiawatha.

To run PHP standalone issue the php -S localhost:8000 -t public_html/ command. See documentation.

Configuration

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

  • It is recommended to set your timezone (list of timezones) in /etc/php/php.ini like so:
date.timezone = Europe/Berlin
  • If you want to display errors to debug your PHP code, change display_errors to On in /etc/php/php.ini:
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. Example:
open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/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, a extension may be enabled/configured in the /etc/php/conf.d directory instead (e.g. /etc/php/conf.d/gd.ini)

gd

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

extension=gd.so

imagemagick

For imagemagick run # pecl install imagick. The pecl binary is included in the php-pearAUR package. Then add

extension=imagick.so

to /etc/php/php.ini.

pthreads

If you wish to have POSIX multi-threading you will need the pthreads extension. To install the pthreads (http://pecl.php.net/package/pthreads) extension using pecl you are required to use a compiled version of PHP with the 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 the power to PHP to mess things up really bad. 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 (by default it is disabled) PCNTL has to be compiled into PHP.

MySQL/MariaDB

Install and configure MySQL/MariaDB as described in MariaDB.

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

extension=pdo_mysql.so
extension=mysqli.so
Warning: mysql.so was removed in PHP 7.0.

You can add minor privileged MySQL users for your web scripts. You might also want to edit /etc/mysql/my.cnf and uncomment the skip-networking line so the MySQL server is only accessible by the localhost. You have to restart MySQL for changes to take effect.

PostgreSQL

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

extension=pdo_pgsql.so
extension=pgsql.so

Sqlite

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

extension=pdo_sqlite.so
extension=sqlite3.so

XDebug

XDebug allows you to easily debug php code using modified var_dump() function. Install xdebug and uncomment the lines at /etc/php/conf.d/xdebug.ini:

zend_extension=xdebug.so
xdebug.remote_enable=on
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_handler=dbgp

IMAP

Install php-imap and uncomment the line at /etc/php/php.ini:

extension=imap.so

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.

  • Zend OPCache provides only opcode caching.
  • APCu provides only userland caching.

For optimal caching, you should enable both. To do this, follow both #OPCache and #APCu.

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.so

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.so

Its author recommends a few suggested settings, among which:

  • apc.enabled=1 and apc.shm_size=32M are not really required as they represent the default values;
  • apc.ttl=7200 on the other hand seems rather beneficial;
  • finally, apc.enable_cli=1, which although not recommended by the manual may be required by some software such as ownCloud.
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

Aptana Studio

Aptana Studio is an IDE for programming in PHP and web development. It can be installed with the aptana-studioAUR package. Does not have a PHP debugger as of version 3.2.2.

Eclipse PDT

Eclipse PDT is the PHP variant of Eclipse. It can be installed with the eclipse-php package. See Eclipse for more information.

You would need other plugins for JavaScript support and DB query.

Komodo

Komodo is an IDE with good integration for PHP+HTML+JavaScript. Komodo Edit is a free editor-only variant and installable with the komodo-editAUR package.

Netbeans

NetBeans IDE is a complete IDE for many languages including PHP. Includes features like debugging, refactoring, code templating, autocomplete, XML features, and web design and development functionalities (very good CSS autocomplete functionality and PHP/JavaScript code notifications/tips). Install it with the netbeans package.

PhpStorm

JetBrains PhpStorm is a commercial, cross-platform IDE for PHP built on JetBrains' IntelliJ IDEA platform. It can be installed with the phpstormAUR package, or with phpstorm-eapAUR for the 30-day trial version. You can get a free license for education from Jetbrains.[1]

Zend Studio

Zend Studio is the official PHP IDE, based on eclipse. The IDE has autocomplete, advanced code formatting, WYSIWYG html editor, refactoring, and all the eclipse features such as db access and version control integration and whatever you can get from other eclipse plugins. You can install it with the zendstudioAUR package.

Commandline tools

Box

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

Composer

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

PDepend

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

PHP Coding Standards Fixer

PHP Coding Standards Fixer a is PSR-1 and PSR-2 Coding Standards fixer for your code. It can be installed with the php-cs-fixerAUR 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 php-codesnifferAUR 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 phpdoxAUR package.

PHPLoc

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

PhpMetrics

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

phptok

phptok is a tool for quickly dumping the tokens of a PHP sourcecode file. It can be installed with the phptokAUR 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 phpunit-skeleton-generatorAUR package.

Troubleshooting

PHP Fatal error: Class 'ZipArchive' not found

Ensure the zip extension is enabled.

$ grep zip /etc/php/php.ini
extension=zip.so

/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: <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 /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.

See also