站点图标 嘟嘟

Debian免编译快速安装PHP(v5.6,v7.0,v7.1)教程

说明:这里安装PHP将完全不编译任何组件,完全依赖软件源安装。提供PHP软件源的Ondřej Surý大神是Debian社区中PHP源的维护者,所以无需担心软件的安全和性能问题肯定比我们自己编译更好,软件源安装的PHP默认以Unix Socket的状态运行在/run/php/php7.1-fpm.sock,比使用TCPlocalhost:9000的方式性能更好。

安装

适用系统:Debian 9/Debian 8

1、安装软件源拓展
Sury官方默认源:https://packages.sury.org/php/
镜像源:https://mirror.xtom.com.hk/sury/php/

添加GPG

wget -O /etc/apt/trusted.gpg.d/php.gpg https://mirror.xtom.com.hk/sury/php/apt.gpg 

安装apt-transport-https

apt-get install apt-transport-https

添加sury软件源

sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'  

更新软件源缓存

apt-get update

2、安装PHP
安装PHP7.1

apt install php7.1-fpm php7.1-mysql php7.1-curl php7.1-gd php7.1-mbstring php7.1-mcrypt php7.1-xml php7.1-xmlrpc php7.1-zip php7.1-opcache -y

安装PHP7.0

apt install php7.0-fpm php7.0-mysql php7.0-curl php7.0-gd php7.0-mbstring php7.0-mcrypt php7.0-xml php7.0-xmlrpc php7.0-zip php7.0-opcache -y

安装PHP5.6

apt install php5.6-fpm php5.6-mysql php5.6-curl php5.6-gd php5.6-mbstring php5.6-mcrypt php5.6-xml php5.6-xmlrpc php5.6-zip php5.6-opcache -y

3、设置PHP
这里以PHP7.1为例,其他版本仅需将版本号改成自己所用的即可。
安装完成后,编辑/etc/php/7.1/fpm/php.ini替换;cgi.fix_pathinfo=1cgi.fix_pathinfo=0
快捷命令:

sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/' /etc/php/7.1/fpm/php.ini 

4、管理PHP
安装好了先重启一下!
更多操作:

systemctl restart php7.1-fpm #重启
systemctl start php7.1-fpm #启动
systemctl stop php7.1-fpm #关闭
systemctl status php7.1-fpm #检查状态

查看当前PHP版本:

php -v

5、更新PHP
运行下面的命令系统就会更新所有可以更新的软件包括PHP

apt update
apt upgrade -y

6、安装更多组件
上面的一条命令安装PHP只是安装了部分PHP拓展,更多的软件可见:

root@Rats:~# apt-cache search php7.1
libapache2-mod-php7.1 - server-side, HTML-embedded scripting language (Apache 2 module)
php-all-dev - package depending on all supported PHP development packages
php7.1 - server-side, HTML-embedded scripting language (metapackage)
php7.1-cgi - server-side, HTML-embedded scripting language (CGI binary)
php7.1-cli - command-line interpreter for the PHP scripting language
php7.1-common - documentation, examples and common module for PHP
php7.1-curl - CURL module for PHP
php7.1-dev - Files for php7.1 module development
php7.1-gd - GD module for PHP
php7.1-gmp - GMP module for PHP
php7.1-json - JSON module for PHP
php7.1-ldap - LDAP module for PHP
php7.1-mysql - MySQL module for PHP
php7.1-odbc - ODBC module for PHP
php7.1-opcache - Zend OpCache module for PHP
php7.1-pgsql - PostgreSQL module for PHP
php7.1-pspell - pspell module for PHP
php7.1-readline - readline module for PHP
php7.1-recode - recode module for PHP
php7.1-snmp - SNMP module for PHP
php7.1-sqlite3 - SQLite3 module for PHP
php7.1-tidy - tidy module for PHP
php7.1-xml - DOM, SimpleXML, WDDX, XML, and XSL module for PHP
php7.1-xmlrpc - XMLRPC-EPI module for PHP
libphp7.1-embed - HTML-embedded scripting language (Embedded SAPI library)
php7.1-bcmath - Bcmath module for PHP
php7.1-bz2 - bzip2 module for PHP
php7.1-enchant - Enchant module for PHP
php7.1-fpm - server-side, HTML-embedded scripting language (FPM-CGI binary)
php7.1-imap - IMAP module for PHP
php7.1-interbase - Interbase module for PHP
php7.1-intl - Internationalisation module for PHP
php7.1-mbstring - MBSTRING module for PHP
php7.1-mcrypt - libmcrypt module for PHP
php7.1-phpdbg - server-side, HTML-embedded scripting language (PHPDBG binary)
php7.1-soap - SOAP module for PHP
php7.1-sybase - Sybase module for PHP
php7.1-xsl - XSL module for PHP (dummy)
php7.1-zip - Zip module for PHP
php7.1-dba - DBA module for PHP

文章来源:Debian 免编译安装 PHP-FPM