1. Linux + nginx + PHP7 环境

1.1. 步骤

1.1.1. root 用户登录

1.1.2. 下载压缩文件

php mirror 下载 php-7.1.1

1.1.3. 安装 openssl

1.1.4. 安装依赖

yum install libc-client-devel libc-client
ln -s /usr/lib64/libc-client.so /usr/lib/libc-client.so

1.1.5. 安装 PHP

cd php-7.1.1.tar.gz
./configure --with-libxml-dir --with-openssl  --with-zlib --with-curl --enable-dba --with-imap-ssl  --with-imap --enable-intl --enable-zip --with-pear --with-pdo-mysql --enable-fpm --enable-mbstring  --with-kerberos=/usr

make
make test
make install

Installing shared extensions:     /usr/local/lib/php/extensions/no-debug-non-zts-20160303/
Installing PHP CLI binary:        /usr/local/bin/
Installing PHP CLI man page:      /usr/local/php/man/man1/
Installing PHP FPM binary:        /usr/local/sbin/
Installing PHP FPM config:        /usr/local/etc/
Installing PHP FPM man page:      /usr/local/php/man/man8/
Installing PHP FPM status page:   /usr/local/php/php/fpm/
Installing phpdbg binary:         /usr/local/bin/
Installing phpdbg man page:       /usr/local/php/man/man1/
Installing PHP CGI binary:        /usr/local/bin/
Installing PHP CGI man page:      /usr/local/php/man/man1/
Installing build environment:     /usr/local/lib/php/build/
Installing header files:           /usr/local/include/php/
Installing helper programs:       /usr/local/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/php/man/man1/
  page: phpize.1
  page: php-config.1
Installing PEAR environment:      /usr/local/lib/php/
[PEAR] Archive_Tar    - already installed: 1.4.0
[PEAR] Console_Getopt - already installed: 1.4.1
[PEAR] Structures_Graph- already installed: 1.1.1
[PEAR] XML_Util       - already installed: 1.3.0
[PEAR] PEAR           - already installed: 1.10.1
Warning! a PEAR user config file already exists from a previous PEAR installation at '/root/.pearrc'. You may probably want to remove it.
Wrote PEAR system config file at: /usr/local/etc/pear.conf
You may want to add: /usr/local/lib/php to your php.ini include_path
/root/download/php-7.1.1/build/shtool install -c ext/phar/phar.phar /usr/local/bin
ln -s -f phar.phar /usr/local/bin/phar
Installing PDO headers:           /usr/local/include/php/ext/pdo/

安装后

/usr/local/bin/php-config 部分内容

extension_dir='/usr/local/lib/php/extensions/no-debug-non-zts-20160303'
configure_options=" '--with-libxml-dir' '--with-openssl' '--with-zlib' '--with-curl' '--enable-dba' '--with-imap-ssl' '--with-imap' '--enable-intl' '--enable-zip' '--with-pear' '--with-pdo-mysql' '--enable-fpm' '--enable-mbstring' '--with-kerberos=/usr'"

1.1.6. 配置

配置 php.ini

查看 php.ini 位置

# php --ini
Configuration File (php.ini) Path: /usr/local/lib
Loaded Configuration File:         /usr/local/lib/php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)
cp php.ini-development /usr/local/lib/php.ini

修改

vim /usr/local/lib/php.ini
cgi.fix_pathinfo=0
date.timezone = Asia/Shanghai

配置 php-fpm.conf

cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf

修改 /usr/local/etc/php-fpm.conf

include=etc/php-fpm.d/*.conf
cp /usr/local/etc/php-fpm.d/www.conf.default /usr/local/etc/php-fpm.d/www.conf

修改 /usr/local/etc/php-fpm.d/www.conf

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
user = nobody
group = nobody

添加 nobody 群组

groupadd nobody

配置 php-fpm

cp sapi/fpm/php-fpm /usr/local/bin

配置 php 启动脚本

cp sapi/fpm/init.d.php-fpm.in /etc/init.d/php-fpm
chmod a+x /etc/init.d/php-fpm
vim /etc/init.d/php-fpm

参考 /usr/local/bin/php-config

prefix=/usr/local
exec_prefix=${prefix}

php_fpm_BIN=${exec_prefix}/sbin/php-fpm
php_fpm_CONF=${prefix}/etc/php-fpm.conf
php_fpm_PID=${prefix}/var/run/php-fpm.pid

1.1.7. 启动 php-fpm

/etc/init.d/php-fpm start

1.2. 不重装PHP安装PHP模块/扩展

得到 php-config 路径

$ command -v php-config
/usr/local/bin/php-config

得到 phpize 路径

$ command -v phpize
/usr/local/bin/phpize

1.2.1. 安装 zlib

$ cd php-7.1.1/ext/zlib
$ cp config0.m4 config.m4
$ /usr/local/bin/phpize
$ ./configure --with-php-config=/usr/local/bin/php-config
$ make
$ make test
$ make install
Installing shared extensions:     /usr/local/lib/php/extensions/no-debug-non-zts-20131226/

/usr/local/lib/php.ini 添加

extension = "zlib.so"

重启 php

/etc/init.d/php-fpm restart

查看是否生效

php -m | grep zlib

1.2.2. 安装 gmp

$ cd php-7.1.1/ext/gmp
$ cp config0.m4 config.m4
$ /usr/local/bin/phpize
$ ./configure --with-php-config=/usr/local/bin/php-config
$ make
$ make test
$ make install
Installing shared extensions:     /usr/local/lib/php/extensions/no-debug-non-zts-20131226/

/usr/local/lib/php.ini 添加

extension = "gmp.so"

重启 php

/etc/init.d/php-fpm restart

查看是否生效

php -m | grep gmp

1.2.3. Questions

  1. configure: error: Unable to locate gmp.h

yum install -y gmp-devel

  1. configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.

yum install -y re2c

1.3. pecl

pecl install xdebug
pecl install mongodb
pecl install redis

results matching ""

    No results matching ""