centos7搭建lnmp編譯安裝php【一】

冰凡發表於2016-12-30
1.官網下載安裝包php-5.6.11.tar.gz

2.通過命令解壓檔案
[root@localhost share]# tar -zxvf php-5.6.11.tar.gz

3.安裝一些庫,執行下面命令
yum install -y gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libpng libpng-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses curl openssl-devel gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel readline-devel libxslt-devel expat-devel xmlrpc-c xmlrpc-c-devel

4.進入解壓目錄執行
./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-mysql-sock --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-fpm --with-ncurses --enable-soap --with-libxml-dir --with-XMLrpc --with-openssl --with-mcrypt --with-mhash --with-pcre-regex --with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-gd-native-ttf --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --disable-mbregex --disable-mbregex-backtrack --with-libmbfl --with-onig --enable-pdo --with-pdo-mysql --with-zlib-dir --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sqlite-utf8 --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-zip --enable-mysqlnd-compression-support --with-pear
注: --with-config-file-path=/usr/local/php/etc 指定自己的php.ini路徑
5.配置執行完畢,下面執行編譯和安裝
[root@localhost php-5.6.11]# make &&make install

6.進入安裝php的目錄/usr/local/php,進入etc,
[root@localhost etc]# pwd
/usr/local/php/etc
然後複製一份php-fpm.conf配置,執行
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf

7.設定環境變數php-fpm,執行
[root@localhost etc]# vim /etc/profile
在檔案最後加入:
export PATH="/usr/local/php/sbin:$PATH"
立即使環境變數生效:
[root@localhost etc]# source /etc/profile

8.進入目錄/etc/init.d/中建立檔案php-fpm,加入如下內容:
#!/bin/bash
 #
 # Startup script for the PHP-FPM server.
 #
 # chkconfig: 345 85 15
 # description: PHP is an HTML-embedded scripting language
 # processname: php-fpm
 # config: /usr/local/php/etc/php.ini
 
 # Source function library.
 . /etc/rc.d/init.d/functions
 
 PHP_PATH=/usr/local
 DESC="php-fpm daemon"
 NAME=php-fpm
 # php-fpm路徑
DAEMON=$PHP_PATH/php/sbin/$NAME
 # 配置檔案路徑
CONFIGFILE=$PHP_PATH/php/etc/php-fpm.conf
 # PID檔案路徑(在php-fpm.conf設定)
PIDFILE=$PHP_PATH/php/var/run/$NAME.pid
 SCRIPTNAME=/etc/init.d/$NAME
 
 # Gracefully exit if the package has been removed.
 test -x $DAEMON || exit 0
 
 rh_start() {
   $DAEMON -y $CONFIGFILE || echo -n " already running"
 }
 
 rh_stop() {
   kill -QUIT `cat $PIDFILE` || echo -n " not running"
 }
 
 rh_reload() {
   kill -HUP `cat $PIDFILE` || echo -n " can't reload"
 }
 
 case "$1" in
   start)
         echo -n "Starting $DESC: $NAME"
         rh_start
         echo "."
         ;;
   stop)
         echo -n "Stopping $DESC: $NAME"
         rh_stop
         echo "."
         ;;
   reload)
         echo -n "Reloading $DESC configuration..."
         rh_reload
         echo "reloaded."
   ;;
   restart)
         echo -n "Restarting $DESC: $NAME"
         rh_stop
         sleep 1
         rh_start
         echo "."
         ;;
   *)
          echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2
          exit 3
         ;;
 esac
 exit 0

9.增加執行許可權:
[root@localhost etc]# chmod a+x /etc/init.d/php-fpm

10.把php-fpm加入chkconfig系統服務,開機自啟動
[root@localhost etc]#  chkconfig php-fpm on
[root@localhost etc]#  chkconfig --list | grep php-fpm 

相關文章