編譯安裝PHP7

#按需求自行刪減
cc gcc-c++ make cmake automake autoconf gd file bison patch mlocate flex 
diffutils zlib zlib-devel pcre pcre-devel 
libjpeg libjpeg-devel libpng libpng-devel libxml2 libxml2-devel
freetype freetype-devel  
glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel 
ncurses ncurses-devel 
curl curl-devel libcurl libcurl-devel 
e2fsprogs e2fsprogs-devel 
krb5 krb5-devel 
openssl openssl-devel openldap openldap-devel openldap-clients 
openldap-servers openldap-devellibxslt-devel nss_ldap
kernel-devel libtool-libs 
readline-devel gettext-devel libcap-devel
php-mcrypt libmcrypt libmcrypt-devel recode-devel 
icu gmp-devel libxslt libxslt-devel

yum install -y gcc gcc-c++ make cmake automake autoconf gd file bison patch mlocate flex diffutils zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel libcurl libcurl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers openldap-devellibxslt-devel kernel-devel libtool-libs readline-devel gettext-devel libcap-devel php-mcrypt libmcrypt libmcrypt-devel recode-devel gmp-devel icu libxslt libxslt-develphp

2)安裝 libmcrypt mhash mcrypt

注:mcrypt依賴前二者html

wget "http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz"
wget "http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz"
wget "https://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz"

注:configure: error: * libmcrypt was not foundmysql

export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

或者
ldconfiglinux

3)編譯安裝PHP7

說明:PHP7 移除了已經被廢棄的函數,如 mysql_ 系列函數在 PHP5.5 被廢棄,在 PHP7被刪除,而且 php-fpm 也已經被 php 歸入,直接在選項中開啓便可,--enable-cgi 是默認配置且 --enable-fast-cgi 已經被廢除,--enable-cgi 便可讓 fpm 模式調用。nginx

ladp在64的系統裏可能存在寫庫關聯問題,執行下面的命令
cp -frp /usr/lib64/libldap* /usr/lib/c++

#部分配置釋義
./configure \--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-mcrypt \                               # mcrypt 加密算法
--with-mhash \                                # mhash 加密算法
--with-mysqli=mysqlnd \                       # 推薦使用 mysqlnd 驅動 mysql已被廢棄
--with-pdo-mysql=mysqlnd \                    # 推薦使用 mysqlnd 驅動 mysql已被廢棄
--with-gd \                                   # gd庫
--with-iconv \
--with-zlib \
--with-curl \
--with-jpeg-dir \
--with-freetype-dir \
--with-apxs2=/usr/bin/apxs \                  # 讓 php 直接編譯到 apache 的模塊中去
--with-apache=/etc/httpd \                    # 靜態編譯apache的模塊 編譯完後去httpd.conf中加載so
--with-openssl \
--with-xmlrpc \
--with-bz2 \
--with-gettext \                               # 多語言應用開發
--with-readline \                             # readline只能在linux下win使stream_get_line
--with-recode \
--with-ldap \                                   # 目錄協議
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-fpm \                                  # php-fpm 進程管理器
--enable-cgi \                                  # 默認開啓php的cgi sapi  
--enable-xml \
--enable-bcmath \
--enable-inline-optimization \
--enable-mbregex \
--enable-mbstring \
--enable-ftp \
--enable-gd-native-ttf \
--enable-pcntl \                                #pcntl 多進程擴展模塊
--enable-sockets \
--enable-sysvmsg \                              #消息隊列
--enable-sysvshm \                              #內存共享模塊 linux 
--enable-shmop \                                #內存共享模塊 linux/windows
--enable-zip \
--enable-soap \
--enable-session \
--enable-opcache \                              # opcache 緩存優化
--enable-cli                                    # cli 其實默認就是開啓的 若禁用同時要
--without-pear

編譯參數算法

./configure --prefix=/usr/local/php \
--with-mysql-sock \
--with-mysqli \
--with-libxml-dir \
--with-openssl \
--with-mcrypt \
--with-mhash \
--with-pcre-regex \
--with-zlib \
--with-iconv \
--with-bz2 \
--with-curl \
--with-cdb \
--with-pcre-dir \
--with-gd \
--with-openssl-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--with-gettext \
--with-gmp \
--with-mhash \
--with-libmbfl \
--with-onig \
--with-pdo-mysql \
--with-zlib-dir \
--with-readline \
--with-libxml-dir \
--with-xsl \
--with-pear \
--enable-fpm  \
--enable-soap \
--enable-bcmath \
--enable-calendar \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--enable-ftp \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--enable-pdo \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--enable-zip \
--enable-mysqlnd-compression-support \
--enable-intl
  • --enable-cgi --disable-cgi :
    在5.3.0後 enable-cgi 等同於--enable-fastcgi 也就是說此後不須要在額外聲明 --enable-fastcgi,且 --enable-force-cgi-redirect 也默認有效且被廢棄在編譯選項中,要禁用需修改php.ini的cgi.force_redirect爲0sql

  • --with-apxs2 --with-apache:
    --with-apxs2是直接把php編譯到apache的模塊中去 --with-apache是置頂apache的serverRoot路徑,生成apache的php模塊 修改apache配置文件手動加載:
    AddType application/x-httpd-php .php .html .htmapache

  • php7.0廢除了--with-mysql編譯選項,且推薦使用mysqlnd驅動json

  • -bash: --with-openssl: command not found:
    which openssl 查看目錄 添加環境變量
    export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

4)php-fpm 服務腳本

#! /bin/sh
# Comments to support chkconfig on CentOS
# chkconfig: 2345 65 37
#
set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="php-fpm daemon"
NAME=php-fpm

#php-fpm命令的路徑
DAEMON=/usr/local/php/sbin/$NAME

#php-fpm的配置文件
CONFIGFILE=/usr/local/php/etc/php-fpm.conf

#php-fpm的pid文件
PIDFILE=/usr/local/php/var/run/$NAME.pid

SCRIPTNAME=/etc/init.d/$NAME

# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
d_start() { 
    $DAEMON -y $CONFIGFILE || echo -n " already running"
}

d_stop() {
     kill -QUIT `cat $PIDFILE` || echo -n " not running"
}

d_reload() { 
    kill -HUP `cat $PIDFILE` || echo -n " can't reload"
}

case "$1" in 
  start) 
          echo -n "Starting $DESC is success" 
          d_start 
          echo "." ;; 
  stop) 
          echo -n "Stopping $DESC is success" 
          d_stop 
          echo "." ;; 
  reload) 
          echo -n "Reloading $DESC configuration..." 
          d_reload 
          echo "reloaded." ;; 
    restart) 
          echo -n "Restarting $DESC is success" 
          d_stop 
          sleep 1 
          d_start 
          echo "." ;; 
    *) 
          echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 
          exit 3 ;;
esac

內置php-fpm

cd /usr/local/php7/etc
mv php-fpm.conf.default php-fpm.conf
mv php-fpm.d/www.conf.default php-fpm.d/www.conf

#進入源碼安裝包目錄
cd /data/php-7.0.11

#copy php配置文件 獲得php.ini 配置這裏不做說明      
cp php.ini-production /usr/local/php/etc/php.ini  
cd sapi/fpm              #進到源碼包裏的sapi/fpm目錄
cp init.d.php-fpm /etc/init.d/php-fpm      #copy cgi管理器 獲得php-fpm
chmod +x /etc/init.d/php-fpm               #附上可執行權限
chkconfig --add php-fpm                    #加入開機啓動項
chkconfig php-fpm on
service php-fpm start                      #啓動php-fpm
ps -ef | grep php-fpm                      #查看php-fpm啓動狀態

測試

vi /var/www/html/index.php
<?php
$con = new mysqli('127.0.0.1', 'root', '123456', '', 3306);
$res = $con->query('show databases;');
var_dump($res->fetch_assoc());
?>
/usr/local/php/sbin/php-fpm -v
PHP 7.0.11 (fpm-fcgi) (built: Aug 27 2016 20:46:44)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies

service php-fpm start 啓動

相關文章
相關標籤/搜索