pcre pcre-devel zlib zlib-devel openssl openssl-devel gd gd-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel lua-devel
autoconf libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel libidn libidn-devel libtool libtool-libs libevent-devel libevent openldap openldap-devel nss_ldap openldap-clients openldap-servers libtool-ltdl libtool-ltdl-devel bison libgcrypt php-mcrypt libmcrypt libmcrypt-devel cmake gcc gcc-c++ ncurses-devel perl-Data-Dumper libicu-devel libquadmath-devel python-devel bzip2-devel
我也不做区分了;这些是搭建lnpm环境需要安装的相关依赖包,就全安装完了。
下载php,我是到官网去下载的
下载一个最新稳定版的tar.gz格式
之后用xftp工具远程链接linux,把下载包放到linux的/usr/local/目录下
1解压:
[root@localhost
[root@localhost]# tar -zxvf php-7.1.12.tar.gz
2编译:
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mcrypt=/usr/include --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-gd --with-iconv --with-zlib --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-curl --with-jpeg-dir --with-freetype-dir --enable-opcache --with-png-dir --with-libxml-dir --with-mcrypt --with-mhash
编译中有报错error的内容,看报错内容相应解决,有些报错是没找到依赖包需查看依赖包是否全部安装好了;还有一些没安装mysql的要先安装mysql
解决php编译报错configure: error: mcrypt.h not found. Please reinstall libmcrypt.
yum install -y epel-release
yum install -y libmcrypt-devel
两个不能一起安装,因为CentOs6默认的yum源没有 libmcrypt-devel这个包,只能借助epel的yum源,所以先安装epel,再安装
libmcrypt
全部编译完成之后执行:
make && make install
3.配置启动:
make安装完成之后会出现目录/usr/local/php;
执行下面这句话
[root@localhost local]# ll /usr/local/php/etc/
可以看到目录下的配置文件,一般我都会把配置文件转移到非root用户的其它用户的家目录下面
比如我创建一个adv用户,在adv用户下面创建一个目录保存php 的配置文件;
[root@localhost home]# cd /home/adv/
[root@localhost adv]# mkdir phpfpm
[root@localhost adv]# cd phpfpm/
[root@localhost phpfpm]# mkdir conf
此时我们已经有了这样的目录/home/adv/phpfpm/conf
接下来把配置文件cp到/home/adv/phpfpm/conf目录下
1.先把php.ini文件cp到/home/adv/phpfpm/conf目录下
php.ini文件在你刚刚解压的php-7.1.12文件里
[root@localhost /]# cp /usr/local/php-7.1.12/php.ini-production /home/adv/phpfpm/conf/php.ini
[root@localhost /]# cp /usr/local/php/etc/php-fpm.conf.default /home/adv/phpfpm/conf/php-fpm.conf
p /usr/local/php/etc/php-fpm.d/www.conf.default /home/adv/phpfpm/conf/backend.conf
现在我们可以看到/home/adv/phpfpm/conf/目录下有三个文件
2修改配置文件:
修改php-fpm.conf文件
[root@localhost /]# vim php-fpm.conf
还有其它的配置需要修改根据个人需要自行修改
3.编辑启动php文件; 因为我们把配置文件转移到了adv用户下,所以需要指定配置文件来启动php
启动脚本:[root@localhost phpfpm]# vim /home/adv/phpfpm/phpfpm.sh
#!/bin/bash CURRDIR=`dirname "$0"` BASEDIR=`cd "$CURRDIR"; pwd` NAME="php-fpm" CMD=/usr/local/php/sbin/php-fpm if [ "$1" = "-d" ]; then shift EXECUTEDIR=$1'/' shift else EXECUTEDIR=$BASEDIR'/' fi if [ ! -d "$EXECUTEDIR" ]; then echo "ERROR: $EXECUTEDIR is not a dir" exit fi if [ ! -d "$EXECUTEDIR"/conf ]; then echo "ERROR: could not find $EXECUTEDIR/conf/" exit fi if [ ! -d "$EXECUTEDIR"/logs ]; then mkdir "$EXECUTEDIR"/logs fi cd "$EXECUTEDIR" PID_FILE="$EXECUTEDIR"/logs/php-fpm.pid check_pid() { RETVAL=1 if [ -f $PID_FILE ]; then PID=`cat $PID_FILE` ls /proc/$PID &> /dev/null if [ $? -eq 0 ]; then RETVAL=0 fi fi } check_running() { PID=0 RETVAL=0 check_pid if [ $RETVAL -eq 0 ]; then echo "$CMD is running as $PID, we'll do nothing" exit fi } start() { check_running "$CMD" -y "$EXECUTEDIR/conf/php-fpm.conf" -c "$EXECUTEDIR/conf/php.ini" -p `pwd` } stop() { kill -SIGQUIT `cat $PID_FILE` } status() { check_pid if [ $RETVAL -eq 0 ]; then echo "php-fpm is running as $PID ..." else echo "php-fpm is not running" fi } reload() { check_pid if [ $RETVAL -eq 0 ]; then kill -SIGUSR2 `cat $PID_FILE` else echo "php-fpm is not running" fi } reopen() { check_pid if [ $RETVAL -eq 0 ]; then kill -SIGUSR1 `cat $PID_FILE` else echo "php-fpm is not running" fi } RETVAL=0 case "$1" in start) start ;; stop) stop ;; restart) stop start ;; status) status ;; reload) reload ;; reopen) reopen ;; *) echo "Usage: $0 {start|stop|restart|status|reload|reopen}" RETVAL=1 esac exit $RETVAL
编写好之后就可以用,启动测试
[root@localhost phpfpm]# bash phpfpm.sh
Usage: phpfpm.sh {start|stop|restart|status|reload|reopen}
[root@localhost phpfpm]#
可以看到 phpfpm.sh {start|stop|restart|status|reload|reopen} 启动有这些可执行
启动:
[root@localhost phpfpm]# bash phpfpm.sh start
执行以下命令查看是否启动成功,是否有进程
root@localhost phpfpm]# ps -ef | grep php
可以看到红色框框标明的说明启动成功了;
既然配置放到了adv用户下,启动还是建议用adv这个用户来启动;