PHP configuration/zh

PHP is a web template system that accidentally grew up into a fairly general language. PHP的语法、适配性以及执行方式和Perl非常相似；解释器负责执行脚本，实时编译成bytecode, 之后执行. PHP解释器使用CGI风格在命令行运行，或者更常用的方法，作为一个Apache的模块运行.

MediaWiki兼容性
您可以使用的MediaWiki版本列出的相应PHP版本的设置，请查看：Compatibility#PHP.

安装
请参考 https://secure.php.net/install

要求
MediaWiki需要如下PHP扩展： 不支持通过PDO访问MySQL和PostgreSQL
 * 兼容的Perl正则表达式
 * Session
 * 标准PHP库
 * Document Object 模块
 * iconv 字符集会话库
 * JSON（JavaScript对象符号） (alternatively, the pecl-json-c fork)
 * mbstring 多字节字符集支持
 * fileinfo MIME 类型检测
 * 最少下列数据库之一：
 * MySQL
 * PostgreSQL
 * SQLite (through PDO)

兼容Perl正则表达式、Session、标准PHP库和默认开启的JSON支持；Perl正则表达式和标准PHP库支持在PHP 5.3中无法被关闭.

可选
在编译时，MediaWiki还可以使用以下可选PHP功能支持：
 * 可以选择zlib库来压缩file cache
 * sockets 支持网络通信，使用memcached
 * FastStringSearch

例子
可以使用以下编译选项：

 './configure' \ '--with-mysql' \ '--with-apxs2=/usr/sbin/apxs2' \ '--with-zlib' \ '--with-ldap' \ '--with-gd' \ '--with-jpeg-dir' \ '--with-iconv-dir' \ '--enable-mbstring' 可以使用这些编译选项：


 * --with-mysql : 允许PHP进行MySQL访问. （我认为）这是一个必须开启的选项. 您需要在此之前安装MySQL来开启这个选项.
 * --with-apxs2=/usr/sbin/apxs2 : 如果您需要build一个mod_php，可以使用这个选项. APXS是一个Apache module编译选项配置. 您需要对您的系统做一定的修改（或者省略路径）.
 * --with-zlib : 允许PHP读取/写入压缩文件（zipped files）并向Apache或者其他HTTP服务器发送压缩后的数据.
 * --with-ldap : 如果您需要让您的wiki使用LDAP验证，这个选项很重要
 * --with-gd : 如果您需要在PHP中使用图片处理，或者您可以使用ImageMagick. Because this option requires that you have various libraries installed... but presumably IM has the same deps... oh well...
 * --with-jpeg-dir : Seems nonsensical
 * --with-iconv-dir : Seems nonsensical
 * --enable-mbstring : Allows multibyte character string support. This is optional, as slower custom code will be used if not available.

Opcode caching

 * See

Due to MediaWiki's large codebase, it is highly recommended that a system be used to cache the compiled scripts; there are a number of such plugins for PHP, some free, some proprietary. There is a list of some caches:
 * Alternative PHP Cache -- used at Wikimedia
 * Windows Cache Extension for PHP -- recommended for IIS users

Fortunately, these all seem to be easy to install as Zend plugins, you just drop in a library and change your php.ini. No fussy recompiling of the entire PHP!

Depending on the cache and options used, you may have to perform a special operation whenever updating script files.

MediaWiki can also interact with that caches and use them for object caching, see.

Runtime configuration (php.ini)
Some settings in php.ini affects MediaWiki behavior and some of them are incompatible with MediaWiki


 * register_globals


 * safe_mode
 * Safe mode is an ill-conceived, broken-by-design setting in PHP; MediaWiki can work with this option on, but some features won't work.


 * magic_quotes_gpc
 * This options adds quotes to data in,   and  . MediaWiki can work with this option turned on, but will have to remove these quotes and thus will be slower.


 * magic_quotes_runtime
 * This option corrupts data input unpredictably by adding quotes in e.g. opened files, data received from database etc. MediaWiki will refuse to install if this option is turned on.


 * magic_quotes_sybase
 * same as magic_quotes_runtime


 * mbstring.func_overload
 * This option causes errors and may corrupt data unpredictably; MediaWiki will refuse to install if this option is turned on.


 * zend.ze1_compatibility_mode
 * This option causes horrible bugs; MediaWiki will refuse to install if this option is turned on.


 * memory_limit
 * MediaWiki needs sufficiently memory to work. The minimal limit should be something like 20 MB, but if you want MediaWiki to work correctly, consider using at least 50 MB.


 * disable_functions
 * To be able to find GNU diff3 and git during installation process this entry must not contain passthru


 * post_max_size
 * If you are getting the error " " then it could be because this is set with a "MB" prefix, instead of just "M" (the former is interpreted at bytes, not megabytes).

Image Resizing
ImageMagick can be used for image resizing. When it is not available, the GD PHP module is used instead where found.