先安裝相關依賴包php
yum installpython
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-develmysql
我也不作區分了;這些是搭建lnpm環境須要安裝的相關依賴包,就全安裝完了。linux
下載php,我是到官網去下載的http://www.php.net/downloads.phpc++
下載一個最新穩定版的tar.gz格式sql
以後用xftp工具遠程連接linux,把下載包放到linux的/usr/local/目錄下npm
1解壓:vim
[root@localhostbash
[root@localhost]# tar -zxvf php-7.1.12.tar.gzsession
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
cp /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這個用戶來啓動;