PHP (简体中文)

翻译状态:本文是 PHP翻译。上次翻译日期:2020-02-14。如果英文版本有所更改,则您可以帮助同步翻译。

PHP是一种广泛使用的通用脚本语言,特别适合于 Web 开发,可嵌入到 HTML 中。

安装

安装 软件包 php。AUR 中也提供了老的版本,包括 , php55AUR, , php70AUR, , 和 php73AUR.

注意:要想像纯CGI那样运行PHP,你需要安装 。

运行

虽然PHP可以独立运行,它通常用于HTTP服务器如: Apache HTTP Server(LAMP 组合), nginx, lighttpdHiawatha.

使用命令:“ ”可以独立运行PHP。 见 documentation.

配置

主要PHP配置位于 .

date.timezone = Europe/Berlin
  • 如果你想调试PHP时显示错误,在中将display_errors 设为 :
display_errors=On
  • open_basedir 限制 PHP 可以访问的目录,可以增加安全性,但是会影响程序的正常执行。从 PHP 7.0 开始,和上游一样默认不再设置,要使用的用户请手动设置。符号链接会被解析,所以无法通过符号链接跳过限制。某些软件的 Arch 软件包,例如 和 安装在 ,然后在 中创建了配置文件的符号链接。设置 open_basedir 时请加入这两个目录。例如:
open_basedir = /srv/http/:/var/www/:/home/:/tmp/:/var/tmp/:/var/cache/:/usr/share/pear/:/usr/share/webapps/:/etc/webapps/

扩展

一些常用的PHP扩展也可以在官方库发现:

$ pacman -Ss php-

要安装 PHP 的扩展,可以在 AUR 中搜索 php-* 或 php56-*, 例如 , 。

gd

欲使用 php-gd 在 中取消下列内容的注释:

extension=gd

imagemagick

运行安装 . pecl 包含于 包. 在 中加入

extension=imagick

多线程

要使用 POSIX 多线程,需要 pthreads 扩展 。用 安装 pthreads (https://pecl.php.net/package/pthreads) 扩展,需要 PHP 在编译时启用线程安全选项. 当前最简单的方式是用需要的选项重新编译.

可在 PHP pthreads extension 页面找到指令介绍。

PCNTL

利用 PCNTL 可以在服务器上直接创建进程。虽然这可能是你想要的,但是这样也会让 PHP 有能力把机器搞的一团糟。所以 PHP 不能和其他扩展一样加载,要启用此扩展,需要重新编译PHP。ArchLinux 的 PHP 已经加入 "--enable-pcntl"选项,默认已经启用。

MySQL/MariaDB

根据 MariaDB 页面安装并配置 MySQL/MariaDB.

取消 中 下面行前面的注释 :

extension=pdo_mysql.so
extension=mysqli.so
警告: PHP 7.0 中 删除了 mysql.so

可以给网络脚本最低的 MySQL 用户权限,可以编辑 取消 行的注释,这样 MySQL 服务器就只能本地访问。设置之后需要重启 MySQL。

Redis

安装并配置 Redis,然后安装 .

在 中取消 redis 扩展的注释。同时在 中启用(取消注释) igbinary 扩展。

PostgreSQL

安装并配置 PostgreSQL,然后安装 软件包并取消 中下面几行的注释:

extension=pdo_pgsql
extension=pgsql

Sqlite

安装并配置 SQLite,然后安装 软件包并取消 中下面几行的注释:

extension=pdo_sqlite
extension=sqlite3

XDebug

用 XDebug 可以很容易的通过修改的 var_dump() 函数进行调试,安装 xdebug 并取消 中如下行前面的注释:

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

IMAP

安装 并取消 中如下行前面的注释:

 extension=imap

缓存

PHP有两种缓存: opcode/bytecode 缓存和userland/user data 缓存,这两种缓存都大幅度提升性能,因此最好开启。

OPCache

OPCache随PHP发布,因此在PHP configuration file中开启或添加此行即可:

你可在官网 找到其他设置以及建议设置。

警告: 如果你使用推荐设置,要确保你一仔细看过说明,某些情况下可能导致如下错误:zend_mm_heap corrupted

APCu

通过 软件包安装 APCu, 然后在 中取消下面行的注释:

extension=apcu.so

作者 建议进行一些设置:

开发工具

    Aptana Studio

    Aptana Studio 是一个用于PHP和网页开发的IDE. 它能通过 包来安装. 没有3.2.2版本的PHP调试器.

    Eclipse PDT

    Eclipse PDT 是eclipse的PHP变种. 它能通过 包来安装. 可阅览 Eclipse 获取更多信息.

    你可能需要其他插件来获取JavaScript支持和数据库查询.

    Komodo

    Komodo 是一个集成了PHP+HTML+JavaScript的非常好的IDE. Komodo Edit 是免费的只支持编辑的变种. 可以通过 komodo-editAUR 安装。

    Netbeans

    NetBeans IDE 是一个用于很多语言的IDE,包括PHP. 它的特性包括调试、重构、代码模板、自动补全、XML特性、网页设计和其他开发功能(包括很棒的CSS自动补全功能和PHP/JavaScript代码建议)。 可以通过 来安装.

    PhpStorm

    JetBrains PhpStorm 是一个商业的、跨平台PHP IDE,它基于jetbrains的intellij IDEA平台。它可以通过 来安装, 或者通过 来进行30天免费试用 version. 你可以从jetbrains获取免费的教育许可.

    Zend Studio

    Zend Studio 是官方的基于Eclipse的PHP IDE. 这个IDE有自动补全、高级代码格式化、WYSIWYG HTML编辑器、重构和所有的Eclipse特性比如数据库访问和版本控制集成和你能从Eclipse获取的所有其他插件。你可以通过 来安装.

    Commandline tools

    Composer

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

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

    phpcov

    phpcov is a command-line frontend for the PHP_CodeCoverage library. It can be installed with the 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 phptokAUR package.

    PHPUnit

    PHPUnit is a programmer-oriented testing framework for PHP. It can be installed with the 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.

    故障排除

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

    参见

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