安装依赖
[root@localhost ~]# yum -y install gcc gcc++ gcc-c++ wget make libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel bison autoconf libmcrypt libmcrypt-devel mhash mhash-devel mcrypt re2c
创建目录,现在php7.1.6
mkdir -p /usr/src/php7.1.6
cd /usr/src/php7.1.6
wget -c https://github.com/php/php-src/archive/php-7.1.6.tar.gz
tar -xvf php-7.1.6.tar.gz
生成php源码目录下的配置文件 configure
cd /usr/src/php7.1.6/php-src-php-7.1.6
./buildconf --force
运行完以后文件结构如下:
.
├── acinclude.m4
├── aclocal.m4
├── appveyor
├── autom4te.cache
├── build
├── buildconf
├── buildconf.bat
├── buildmk.stamp
├── CODING_STANDARDS
├── config.guess
├── config.sub
├── configure
├── configure.in
├── CONTRIBUTING.md
├── CREDITS
├── ext
├── EXTENSIONS
├── footer
├── generated_lists
├── genfiles
├── header
├── INSTALL
├── install-sh
├── LICENSE
├── ltmain.sh
├── main
├── makedist
├── Makefile.frag
├── Makefile.gcov
├── Makefile.global
├── makerpm
├── missing
├── mkinstalldirs
├── netware
├── NEWS
├── pear
├── php7.spec.in
├── php.gif
├── php.ini-development
├── php.ini-production
├── README.EXT_SKEL
├── README.GIT-RULES
├── README.input_filter
├── README.MAILINGLIST_RULES
├── README.md
├── README.namespaces
├── README.NEW-OUTPUT-API
├── README.PARAMETER_PARSING_API
├── README.REDIST.BINS
├── README.RELEASE_PROCESS
├── README.SELF-CONTAINED-EXTENSIONS
├── README.STREAMS
├── README.SUBMITTING_PATCH
├── README.TESTING
├── README.TESTING2
├── README.UNIX-BUILD-SYSTEM
├── README.WIN32-BUILD-SYSTEM
├── run-tests.php
├── sapi
├── scripts
├── server-tests-config.php
├── server-tests.php
├── snapshot
├── stamp-h.in
├── stub.c
├── tests
├── travis
├── TSRM
├── UPGRADING
├── UPGRADING.INTERNALS
├── vcsclean
├── win32
└── Zend
编译安装php7.1.6
各字段解释
./configure
--prefix=/usr/local/php \ [php安装的根目录] --exec-prefix=/usr/local/php \ [php执行文件所在目录] --bindir=/usr/local/php/bin \ [php/bin目录] --sbindir=/usr/local/php/sbin \ [php/sbin目录] --includedir=/usr/local/php/include \ [php包含文件所在目录] --libdir=/usr/local/php/lib/php \ [php/lib目录] --mandir=/usr/local/php/php/man \ [php/man目录] --with-config-file-path=/usr/local/php/etc \ [php的配置目录] --with-mysql-sock=/tmp/mysql.sock \ [php的Unix socket通信文件] --with-mcrypt \ [是php里面重要的加密支持扩展库,linux环境下该库在默认情况下不开启] --with-mhash \ [Mhash是基于离散数学原理的不可逆向的php加密方式扩展库,其在默认情况下不开启] --with-openssl \ [OpenSSL 是一个安全套接字层密码库] --with-mysqli=shared,mysqlnd \ [php依赖mysql库] --with-pdo-mysql=shared,mysqlnd \ [php依赖mysql库] --with-gd \ [gd库]
--with-iconv \ [关闭iconv函数,种字符集间的转换]
--with-zlib \ [zlib是提供数据压缩用的函式库] --enable-zip \ [打开对zip的支持] --enable-inline-optimization \ [优化线程] --disable-debug \ [关闭调试模式] --disable-rpath \ [关闭额外的运行库文件] --enable-shared \ [启用动态库] --enable-xml \ [开启xml扩展] --enable-bcmath \ [打开图片大小调整,用到zabbix监控的时候用到了这个模块] --enable-shmop \ [共享内存] --enable-sysvsem \ [内存共享方案] --enable-mbregex \ [开启多字节正则表达式的字符编码。] --enable-mbstring \ [开启多字节字符串函数] --enable-ftp \ [开启ftp] --enable-gd-native-ttf \ [开启gd库原有字体] --enable-pcntl \ [PHP的进程控制支持实现了Unix方式的多进程创建]
--enable-sockets \ [开启套节字] --with-xmlrpc \ [打开xml-rpc的c语言] --enable-soap \ [开启简单对象访问协议简单对象访问协议] --without-pear \ [开启php扩展与应用库] --with-gettext \ [开户php在当前域中查找消息] --enable-session \ [允许php会话session] --with-curl \ [允许curl扩展] --with-jpeg-dir \ [指定jpeg安装目录yum安装过后不用再次指定会自动找到] --with-freetype-dir \ [指定freetype安装目录yum安装过后不用再次指定会自动找到] --enable-opcache \ [开启使用opcache缓存] --enable-fpm \ [开启fpm] --with-fpm-user=nginx \ [php-fpm的用户] --with-fpm-group=nginx \ [php-fpm的用户组] --without-gdbm \ [数据库函数使用可扩展散列和类似于标准UNIX dbm的工作] --enable-fast-install \ [为快速安装优化] --disable-fileinfo
执行代码
./configure --prefix=/usr/local/php7.1 --exec-prefix=/usr/local/php7.1 --bindir=/usr/local/php7.1/bin --sbindir=/usr/local/php7.1/sbin --includedir=/usr/local/php7.1/include --libdir=/usr/local/php7.1/lib/php --mandir=/usr/local/php7.1/php/man --with-config-file-path=/etc/php7.1.6 --with-mysql-sock=/tmp/mysql.sock --with-mcrypt --with-mhash --with-openssl --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gd --with-iconv --with-zlib --enable-zip --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-mbregex --enable-mbstring --enable-ftp --enable-gd-native-ttf --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --without-pear --with-gettext --enable-session --with-curl --with-jpeg-dir --with-freetype-dir --enable-opcache --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --without-gdbm --enable-fast-install --disable-fileinfo
运行 make test
make test
这一步不是必须的, 如果要运行可能会让你等很长一段时间
开始编译
make&&make install
配置php
修改php配置文件之添加php配置文件
mkdir -p /etc/php7.1.6
[root@localhost php-src-php-7.1.6]# cp php.ini-production /etc/php7.1.6/php.ini
修改php配置文件之修改服务器所在时区
> 修改 `php.ini` 配置文件, 设置php所安装服务器时区
> [root@localhost php-src-php-7.1.6]#vim /etc/php7.1.6/php.ini
> 找到 `timezone` 修改时区如下:
>date.timezone = PRC
> PRC就是英文People's Republic of China, 这个你应该知道的吧! 中华人民共和国
添加 php-fpm 管理相关的配置文件到系统配置目录 /etc/init.d
[root@localhost php-src-php-7.1.6]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php7.1-fpm
添加 php-fpm 配置文件
[root@localhost etc]# pwd
/usr/local/php7.1/etc
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf
添加 www.conf 配置文件
[root@localhost php-fpm.d]# pwd
/usr/local/php7.1/etc/php-fpm.d
[root@localhost php-fpm.d]# cp www.conf.default www.conf
创建软连接
ln -s /usr/local/php7.1/sbin/php-fpm /usr/local/bin/php7.1-fpm
ln -s /usr/local/php7.1/bin/php /usr/local/bin/php7.1
>注:创建软连接要使用绝对路径,否则创建出来的软连接会一直是红色的闪烁状态,正确状态如下:
[root@localhost bin]# pwd
/usr/local/bin
[root@localhost bin]# ll
total 1832
-rwxr-xr-x 1 root root 1875611 Oct 15 10:13 composer
lrwxrwxrwx 1 root root 25 Nov 5 13:12 php7.1 -> /usr/local/php7.1/bin/php
lrwxrwxrwx 1 root root 30 Nov 5 13:16 php7.1-fpm -> /usr/local/php7.1/sbin/php-fpm
[root@localhost bin]#
将 /usr/local/bin/加入到环境变量PATH后
vim /etc/profile
export PATH=/usr/local/php5.6/bin/:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
source /etc/profile
设置php开机启动
#修改系统配置目录下的 `php-fpm` 文件可执行权限
chmod +x /etc/init.d/php7.1-fpm
#将系统配置目录下的 `php-fpm` 添加到 `系统服务`
chkconfig --add php7.1-fpm
#设置 `php-fpm` `系统服务` 为开机启动
chkconfig php7.1-fpm on
检测 php-fpm 系统服务是否启动成功
#用 chkconfig 命令检测一下服务是否运行成功
[root@localhost php-src-php-7.1.6]# chkconfig --list | grep php7.1-fpm
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
php-fpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off
# 可见服务已经在 第2 到 第5 运行等级打开
# 同样你也可以禁用 `php-fpm` 开机启动
[root@localhost php-src-php-7.1.6]# chkconfig php-fpm off
# 用 chkconfig 命令检测一下服务是否运行成功
[root@localhost php-src-php-7.1.6]# chkconfig --list | grep php7.1-fpm
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
php-fpm 0:off 1:off 2:off 3:off 4:off 5:off 6:off
#可见服务已经在 第2 到 第5 运行等级已经关闭
测试PHP的配置文件是否无误
[root@localhost init.d]# php7.1-fpm -t
Xdebug requires Zend Engine API version 220131226.
The Zend Engine API version 320160303 which is installed, is newer.
Contact Derick Rethans at http://xdebug.org/docs/faq#api for a later version of Xdebug.
[05-Nov-2018 13:34:05] NOTICE: configuration file /usr/local/php7.1/etc/php-fpm.conf test is successful
如果是多php版本共存,则需要修改www.conf文件的监听端口
vim /usr/local/php7.1/etc/php-fpm.d/www.conf
listen = 127.0.0.1:9001
#注意:如果希望nginx指定域名下的php代码交给php7.1.6版本处理,则该域名下的代理端口,要与修改的端口一致
注意:有问题请评论区留言,会及时回复