Centos6.6編譯安裝PHP7.0.13詳解
創(chuàng)新互聯(lián)公司專業(yè)為企業(yè)提供汕城網(wǎng)站建設(shè)、汕城做網(wǎng)站、汕城網(wǎng)站設(shè)計(jì)、汕城網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)與制作、汕城企業(yè)網(wǎng)站模板建站服務(wù),10年汕城做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
1: Yum源更改為阿里的鏡像源
#mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
#wget -O /etc/yum.repos.d/CentOS-Base.repo
http://mirrors.aliyun.com/repo/Centos- 6.repo
#yum clean all
#yum makecache
2: 安裝php所必要的依賴包
#yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel -y
#yum install freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel -y
libiconv-devel 默認(rèn)的yum源中沒(méi)有需要編譯安裝
#wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
#cd libiconv-1.14
#./configure --prefix=/usr/local/libiconv
#make && make install
3:安裝mhash和mcrypt算法
一:下載相應(yīng)的軟件包
1:下載libmcrypt(安裝mcrypt需要此軟件包)
#wgethttps://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
2:下載mhash(安裝mcrypt需要此軟件包)
#wgethttps://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
3:下載mcrypt
#wgethttps://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
二、安裝軟件包
1、安裝libmcrypt
cd /usr/local/src #進(jìn)入軟件包存放目錄
tar zxvf libmcrypt-2.5.8.tar.gz #解壓
cd libmcrypt-2.5.8 #進(jìn)入安裝目錄
./configure #配置
make #編譯
make install #安裝
2、安裝mhash
cd /usr/local/src
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure
make
make install
3、安裝mcrypt
cd /usr/local/src
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
ln -s /usr/local/bin/libmcrypt_config /usr/bin/libmcrypt_config #添加軟連接
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH #添加環(huán)境變量
./configure
make
make install
4:安裝編譯php7.0.13
#wget http://cn2.php.net/distributions/php-7.0.13.tar.gz
#cd php-7.0.13
#./configure --prefix=/application/php-7.0.13/ --with-MySQLi=mysqlnd --with-iconv-dir=/usr/local/libiconv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --disable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-short-tags --enable-zend-signals --enable-static --with-xsl --with-fpm-user=nginx --with-fpm-group=nginx --enable-ftp --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd
#make
#make install
到源碼包目錄把PHP的配置文件copy到php的安裝目錄
#cd /home/ntw1990/tools/php-7.0.13
# cp php.ini-production /application/php-7.0.13/etc/
將 php 的 bin 和 sbin 加入環(huán)境變量:
#echo "export PATH=$PATH:/application/php-7.0.13/bin:/application/php-7.0.13/sbin" >> /etc/profile
#source /etc/profile
# cd /application/php-7.0.13/etc/
#cp php-fpm.conf.default php-fpm.conf
# /application/php-7.0.13/sbin/php-fpm ( 啟動(dòng)php進(jìn)程)
#ps -ef | grep php-fpm (檢測(cè)下php-fpm進(jìn)程)
5:測(cè)試php與nginx和mysql的通信正常與否
1:測(cè)試和nginx的通信是否正常 (隨意編輯一個(gè)虛擬主機(jī),本人的如下配置)
# vim /application/nginx/conf/extra/blog.conf
server { listen 80; server_name blog.niutianwen.org; root /application/nginx/html/blog; index index.php index.html index.htm; location / { } location ~ \.(php|php5)?$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi.conf; } }
# 在測(cè)試虛擬主機(jī)的網(wǎng)站首頁(yè)寫(xiě)一個(gè)php的測(cè)試腳本
# mkdir /application//nginx/html/blog -p 創(chuàng)建網(wǎng)站根目錄
# cd /application//nginx/html/blog
# echo "" >test_info.php
打開(kāi)firefox測(cè)試效果:
1:首先做好主機(jī)名和ip的對(duì)應(yīng)
#vim /etc/hosts
本機(jī)ip地址 blog.niutianwen.org
2:在瀏覽器中打開(kāi)http://blog.niutianwen.org/test_info.php
如出現(xiàn)以下界面表示php和nginx的通信是正常的!
2:測(cè)試和Mysql的通信是否正常
# cd /application//nginx/html/blog
# vim mysql_connect.php
2:在瀏覽器中打開(kāi)http://blog.niutianwen.org/mysql_connect.php
如出現(xiàn)下面紅線標(biāo)的那一行表示php連接Mysql是正常的!
6:使用centos6.6系統(tǒng)默認(rèn)的進(jìn)程管理方式啟動(dòng)php-fpm
#vim /etc/init.d/php-fpm
#! /bin/sh # Comments to support chkconfig on CentOS # chkconfig: 2345 65 37 # set -e #PATH=/application/php-7.0.13/sbin:/application/php-7.0.13/bin DESC="php-fpm daemon" NAME=php-fpm #php-fpm命令的路徑 DAEMON=/application/php-7.0.13/sbin/$NAME #php-fpm的配置文件 CONFIGFILE=/application/php-7.0.13/etc/php-fpm.conf #php-fpm的pid文件 PIDFILE=/application/php-7.0.13/var/run/$NAME.pid SCRIPTNAME=/etc/init.d/$NAME # Gracefully exit if the package has been removed. test -x $DAEMON || exit 0 function_start() { [ -f $PIDFILE ] && rm -rf $PIDFILE $DAEMON -y $CONFIGFILE -g $PIDFILE && echo "Php-fpm is started" } function_stop() { netstat -tunlp | grep $NAME | grep -v -e grep -e vim | awk -F'/' '{print $1}' |awk '{print $NF}' | xargs -I {} kill -QUIT {} 2> /dev/null [ $? -eq 0 ] && echo " Php-fpm is stopped" } function_reload() { [ `netstat -tunlp | grep 9000|wc -l` -eq 0 ] && echo "$DESC is not startup!" && exit 0 PID=`ps -ef | grep $NAME | grep -v -e grep -e vim | grep master | awk '{print $2}'` echo $PID kill -USR2 $PID && echo "php-fpm is reloaded!" } case "$1" in start) echo -n "Starting $DESC....----->>>>" function_start ;; stop) echo -n "Stopping $DESC....---->>>>" function_stop ;; reload) echo -n "Reloading $DESC configuration....---->>>>" function_reload echo "reloaded." ;; restart) echo -n "Restarting $DESC....---->>>>" function_stop sleep 3 function_start ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 exit 3 ;; esac
至此。centos6.6編譯安裝PHP7.0.12就OK了!