Centos7-64bit尝试编译最新版的nginx1.9.3+php7+mysql5.6.25

http://chaxinyu8.com/?a=url&k=131cc4b4&u=aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGdxNDIxMDMzNzcwL2FydGljbGUvZGV0YWlscy80NzAwNTE2NQ==&t=Q2VudG9zNy02NGJpdOWwneivlee8luivkeacgOaWsOeJiOeahG5naW54MS45LjMrcGhwNytteXNxbDUuNi4yNSAtIC4uLg==&s=Y2VudG9zNyBwaHAgNS42IGNvbXBpbGU=

https://typecodes.com/web/centos7compilephp7.html


1 创建php用户和用户组,并在github下载php7源码

首先创建一个名为php且没有登录权限的用户和一个名为php的用户组,然后去GitHub下载php7源码包。

#######新建php用户和php组
[root@typecodes ~]# groupadd -r php && useradd -r -g php -s /bin/false -d /usr/local/php7 -M php
######从GitHub下载php7安装包
[root@typecodes ~]# wget -c --no-check-certificate -O php7-src-master.zip https://github.com/php/php-src/archive/master.zip
######开始解压php7包
[root@typecodes ~]# unzip -q php7-src-master.zip && cd php-src-master
#####安装编译php7时需要的依赖包
[root@typecodes php-src-master]# yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel 
2 PHP7编译参数的配置

准备工作做好后,就开始正式配置php5.7.7rc的安装明细了。注意,操作时一定要先把下面反斜杠“”后面添加的注释文字去掉!!!

[root@typecodes php-src-master]# ./configure
--prefix=/usr/local/php7                               [PHP7安装的根目录]
--exec-prefix=/usr/local/php7 
--bindir=/usr/local/php7/bin 
--sbindir=/usr/local/php7/sbin 
--includedir=/usr/local/php7/include 
--libdir=/usr/local/php7/lib/php 
--mandir=/usr/local/php7/php/man 
--with-config-file-path=/usr/local/php7/etc            [PHP7的配置目录]
--with-mysql-sock=/var/run/mysql/mysql.sock            [PHP7的Unix socket通信文件]
--with-mcrypt=/usr/include 
--with-mhash 
--with-openssl 
--with-mysql=shared,mysqlnd                            [PHP7依赖mysql库]              
--with-mysqli=shared,mysqlnd                           [PHP7依赖mysql库]
--with-pdo-mysql=shared,mysqlnd                        [PHP7依赖mysql库]
--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                                       [允许php会话session]
--with-curl                                            [允许curl扩展]
--with-jpeg-dir 
--with-freetype-dir 
--enable-opcache                                       [使用opcache缓存]
--enable-fpm 
--enable-fastcgi 
--with-fpm-user=nginx                                  [php-fpm的用户]
--with-fpm-group=nginx                                 [php-fpm的用户组]
--without-gdbm 
--disable-fileinfo 
  1. ./configure --prefix=/usr/local/php7 --exec-prefix=/usr/local/php7 --bindir=/usr/local/php7/bin --sbindir=/usr/local/php7/sbin --includedir=/usr/local/php7/include --libdir=/usr/local/php7/lib/php --mandir=/usr/local/php7/php/man --with-config-file-path=/usr/local/php7/etc --with-mysql-sock=/tmp/mysql.sock --with-mcrypt=/usr/include --with-mhash --with-openssl --with-mysql=shared,mysqlnd --with-mysqli=shared,mysqlnd --with-pdo-mysql=shared,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 --enable-fastcgi --with-fpm-user=nginx --with-fpm-group=nginx --without-gdbm --disable-fileinfo  

按之前的文章安装了扩展Libmcrypt,编译报错:configure: error: Don't know how to define struct flock on this system, set --enable-opcache=no

解决办法:

sudo ln -s /usr/local/mysql/lib/libmysqlclient.so /usr/lib/
sudo ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18

在/etc/ld.so.conf.d中添加local.conf文件:

#echo "/usr/local/lib">> /etc/ld.so.conf.d/local.conf

更新动态库:

#ldconfig -v



执行上面的配置命令的结果如下图所示:

PHP7编译参数的配置

3 开始编译和安装PHP7

相对编译安装MySQL的大量CPU和内存消耗,PHP7的编译安装轻松多了,整个过程大约1个小时左右。

[root@typecodes php-src-master]# make clean && make && make install 

看到下图就代表已经编译安装好了PHP7!

安装php5.7.7rc的make install命令执行结果

4 选做步骤:执行make test命令进行测试

这是一个非必需的操作步骤,执行make test命令。

开始执行make test命令进行测试

有趣的一件事就是:在test期间,会和一个IP地址72.52.91.14建立tcp连接,它对应着php官网http://www.php.net

和PHP官网交互

执行完make test命令后,最终的结果如下:

make test结果

5 查看编译成功后的PHP7安装目录

由于需要和MySQL进行通信,所以需要特别查看PHP7安装后的lib扩展库目录(/usr/local/php7/lib/php/extensions/no-debug-non-zts-20141001/)。需要确保至少存在mysqli.so、pdo_mysql.so这两个动态库文件,如下图所示。

PHP7的lib扩展库

6 开始设置PHP7的配置文件php.ini、php-fpm.conf、www.conf和php-fpm脚本

可以用编译后的配置文件复制到PHP7的配置目录(/usr/local/php7/etc/),推荐使用《PHP7中php.ini、php-fpm和www.conf的配置》文中整理的3个PHP7配置文件和php-fpm服务控制脚本。

#######方法一:直接使用编译后未经优化处理的配置
[root@typecodes php-src-master]# cp php.ini-production /usr/local/php7/etc/php.ini
[root@typecodes php-src-master]# cp /root/php-src-master/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@typecodes php-src-master]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[root@typecodes php-src-master]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
#######方法二:使用https://typecodes.com/web/php7configure.html文中的配置 
[root@typecodes php-src-master]# mv ~/php.ini /usr/local/php7/etc/php.ini && mv ~/php-fpm /etc/init.d/php-fpm
[root@typecodes php-src-master]# mv ~/php-fpm.conf /usr/local/php7/etc/php-fpm.conf && mv ~/www.conf /usr/local/php7/etc/php-fpm.d/www.conf 
7 添加php的环境变量

将php编译生成的bin目录添加到当前Linux系统的环境变量中

[root@typecodes ~]# echo -e '
export PATH=/usr/local/php7/bin:/usr/local/php7/sbin:$PATH
' >> /etc/profile && source /etc/profile 
8 创建php数据库文件的存放路径以及相关安全配置

在Linux主机上创建一个目录/mydata/php/data,用于存放php的数据库文件。同时设置其用户和用户组为之前创建的php,权限为777。这样其它用户是无法进行读写的,尽量保证数据库的安全。

#######设置PHP日志目录和php-fpm的运行进程ID文件(php-fpm.sock)目录
[root@typecodes ~]# mkdir -p /var/log/php-fpm/ && mkdir -p /var/run/php-fpm && cd /var/run/ && chown -R nginx:nginx php-fpm
#######修改session的目录配置
[root@typecodes etc]# mkdir -p /var/lib/php/session
[root@typecodes etc]# chown -R nginx:nginx /var/lib/php 
9 设置PHP开机启动以及测试配置文件是否正确
######配置开机自启动,增加到主机sysV服务
[root@typecodes php-src-master]# chmod +x /etc/init.d/php-fpm
[root@typecodes php-src-master]# chkconfig --add php-fpm
[root@typecodes php-src-master]# chkconfig php-fpm on
######测试PHP的配置文件是否正确合法
[root@typecodes sbin]# php-fpm -t
[03-May-2015 17:50:04] NOTICE: configuration file /usr/local/php7/etc/php-fpm.conf test is successful 
10 启动php服务

在完成上面的操作后,就可以正式使用php服务了。启动php进程服务的命令如下:

[root@typecodes sbin]# service php-fpm start
Starting php-fpm  done 

然后可以通过命令ps -aux|grep php查看是否成功(图中的php-fpm进程数和进程用户nginx都是由www.conf中pm.start_servers和user的值分别决定的):

查看php服务进程

11 查看PHP7版本信息

最后,可以通过命令php -v查看当前PHP版本信息,图中可以看到当前PHP7还使用了Zend OPcache缓存,是因为在php.ini文件中添加了zend_extension=opcache.so配置。




<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
阅读(70) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
评论热议
原文地址:https://www.cnblogs.com/ztguang/p/12649100.html