lakers009 发表于 2018-12-16 15:51:42

三、编译安装php

1、解决依赖关系
安装依赖包:
# yum -y groupinstall"Desktop Platform Development"
# yum install gcc make gd-devellibjpeg-devel libjpeg-turbo-devel libpng-devel libxml2-devel bzip2-devellibcurl-devel libiconv-devel libevent libevent-devel zlib-devel -y
# yuminstall freetype-devel libxslt libxslt-devel -y  如果想让编译的php支持mcrypt扩展,此处还需要单独安装此依赖包,epel6源自带可以直接安装:
# yum-y install libmcrypt libmcrypt-devel mhash mhash-devel mcrypt  注:如果你使用的epel7的源,可能会没有 mcrypt mhash mhash-devel 几个包,可以在 http://mirrors.aliyun.com/epel/6/x86_64/中下载,使用 yum localinstall xxx.rpm 或 rpm -Uvh xxx.rpm 手动安装即可。
  编译安装libiconv库
# wgethttp://down1.chinaunix.net/distfiles/libiconv-1.14.tar.gz
# tar xflibiconv-1.14.tar.gz
# cd libiconv-1.14
# ./configure--prefix=/usr/local/libiconv
# make && make install2、编译安装php-5.5.34
  首先下载源码包至本地目录,
# wget http://cn2.php.net/distributions/php-5.5.34.tar.gz
# tar xf php-5.5.34.tar.gz
# cd php-5.5.34  然后执行以下编译参数:
./configure\
--prefix=/usr/local/php\
--with-config-file-path=/etc\
--with-config-file-scan-dir=/etc/php.d \
--with-bz2\
--with-curl\
--enable-ftp\
--enable-sockets\
--disable-ipv6\
--with-gd\
--enable-gd-native-ttf\
--with-jpeg-dir\
--with-png-dir\
--with-freetype-dir\
--with-iconv-dir=/usr/local/libiconv\
--enable-mbstring\
--with-mcrypt\
--with-mhash\
--with-openssl\
--enable-bcmath\
--enable-calendar\
--with-gettext\
--enable-soap\
--with-libxml-dir=/usr\
--with-zlib\
--with-pdo-mysql=mysqlnd\
--with-mysqli=mysqlnd\
--with-mysql=mysqlnd\
--enable-dom\
--enable-xml\
--enable-fpm\
--with-fpm-user=nginx\
--with-fpm-group=nginx\
--with-libdir=lib64# make
# make test
#make intall参数说明:
""" 安装路径 """
--prefix=/usr/local/php \
""" php.ini 配置文件路径 """
--with-config-file-path= /etc \
""" 优化选项 """
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
""" 启用 opcache,默认为 ZendOptimizer+(ZendOpcache)"""
--enable-opcache \
""" FPM """
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
""" MySQL """
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
""" 国际化与字符编码支持 """
--with-gettext \
--enable-mbstring \
--with-iconv \
""" 图片格式的支持 """
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
""" 加密扩展 """
--with-mcrypt \
--with-mhash \
--with-openssl \
""" 数学扩展 """
--enable-bcmath \
""" Web 服务,soap 依赖 libxml """
--enable-soap \
--with-libxml-dir \
""" 进程,信号及内存 """
--enable-pcntl \
--enable-shmop \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
""" socket & curl"""
--enable-sockets \
--with-curl \
""" 压缩与归档 """
--with-zlib \
--enable-zip \
--with-bz2 \
Zabbix安装需要的PHP扩展参数
--enable-bcmath
--enable-mbstring
--enable-sockets
--with-gd
--with-libxml-dir=/usr/local
xmlwriter 同上
xmlreader 同上
ctype 默认支持
session 默认支持
gettext 默认支持3、为php提供配置文件:
# cp php.ini-production/etc/php.ini  说明:
  php.ini-development   //开发环境用
  php.ini-production      //生产环境用
4、配置PHP-FPM
4.1 简介:
  PHP-FPM(FastCGIProcess Manager:FastCGI进程管理器)
  PHP-FPM是一个PHPFastCGI管理器,是只用于PHP的。它提供了更好的PHP进程管理方式,可以有效控制内存和进程、可以平滑重载PHP配置,比spawn-fcgi具有更多优点,所以被PHP官方收录了。在./configure的时候带–enable-fpm参数即可开启PHP-FPM。
使用PHP-FPM来控制PHP-CGI的FastCGI进程
/usr/local/php/sbin/php-fpm{start|stop|quit|restart|reload|logrotate}
--start 启动php的fastcgi进程
--stop 强制终止php的fastcgi进程
--quit 平滑终止php的fastcgi进程
--restart 重启php的fastcgi进程
--reload 重新平滑加载php的php.ini
--logrotate 重新启用log文件
4.2 配置php-fpm:
  4.2.1为php-fpm提供SysV init脚本,并将其添加至开机启动服务列表:
# cd php-5.5.34
# cp sapi/fpm/init.d.php-fpm/etc/rc.d/init.d/php-fpm
# chmod +x/etc/rc.d/init.d/php-fpm
# chkconfig --addphp-fpm
# chkconfig php-fpm on  4.2.2为php-fpm提供配置文件:
# cp /usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.conf  4.2.3编辑php-fpm的配置文件:
# vim /usr/local/php/etc/php-fpm.conf
配置fpm的相关选项为你所需要的值,默认会启用pid文件:
pm.max_children = 150
pm.start_servers = 8
pm.min_spare_servers = 5
pm.max_spare_servers= 105、启动php-fpm:
# service php-fpm start
说明:php-fpm 可用参数start|stop|force-quit|restart|reload|status6、为了方便使用,可以将 PHP 命令添加到环境变量
# vim~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
       . ~/.bashrc
fi
# User specific environment and startupprograms
#将PATH=$PATH:$HOME/bin 改为:PATH=$PATH:$HOME/bin:/usr/local/php/bin
PATH=$PATH:$HOME/bin:/usr/local/php/bin
export PATH
保存退出!使 PHP 环境变量生效:
# . ~/.bash_profile查看看 PHP 版本
# php -v
PHP 5.5.34 (cli) (built: Apr7 2016 11:22:13)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015Zend Technologies
   with XCache v3.1.2, Copyright (c) 2005-2014, by mOo
   with XCache Cacher v3.1.2, Copyright (c)2005-2014, by mOo7、检验:
  使用如下命令来验正(如果此命令输出有中几个php-fpm进程就说明启动成功了):
# psaux | grep php-fpm
root      54722 0.00.3 1757285932 ?       Ss   20:19   0:00 php-fpm: master process(/usr/local/php/etc/php-fpm.conf)                                                                  
www       54723 0.00.2 1757285144 ?       S    20:19   0:00 php-fpm: pool www                                                                                                         
www       54724 0.00.2 1757285144 ?       S    20:19   0:00 php-fpm: pool www                                                                                                         
www       54725 0.00.2 1757285144 ?       S    20:19   0:00 php-fpm: pool www                                                                                                         
www       54726 0.00.2 1757285144 ?       S    20:19   0:00 php-fpm: pool www                                                                                                         
www       54727 0.00.2 1757285144 ?       S    20:19   0:00 php-fpm: pool www                                                                                                         
root      54837 0.00.0 103308   852 pts/1   S+   20:22   0:00 grep php-fpm  默认情况下,fpm监听在127.0.0.1的9000端口,也可以使用如下命令验正其是否已经监听在相应的套接字。
# netstat -tnlp |grep php-fpm
tcp      0   0 127.0.0.1:9000             0.0.0.0:*                   LISTEN      54722/php-fpm8、整合nginx和php5
8.1.编辑/etc/nginx/nginx.conf,启用如下选项:
# 在所支持的主页面格式中添加php格式的主页
location / {
         roothtml;
         indexindex.php index.htmlindex.htm;
       }
# 1. 启用fastcgi,去掉前面的“#”号,
# 2. 注意fastcgi下的root要与server下的其它location的root目录一致,
# 3. 将fastcgi_param 的/scripts改为$document_root
location ~ \.php$ {
            root          html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_indexindex.php;
         #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
       fastcgi_param SCRIPT_FILENAME$document_root$fastcgi_script_name;
                include      fastcgi_params;
         }8.2.重新载入nginx的配置文件:
# service nginx reload9、测试:
  php程序与mysql安装情况:
# cd /usr/local/nginx/html/
# vim index.php
  然后浏览器输入ip地址:
http://s1.运维网.com/wyfs02/M02/7F/8A/wKioL1ch7tuBNUeKAADakr8MRWg032.pngnginx ,mysql,php安装成功!



页: [1]
查看完整版本: 三、编译安装php