Centos6.6编译安装PHP7.0详解

前端之家收集整理的这篇文章主要介绍了Centos6.6编译安装PHP7.0详解前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Centos6.6编译安装PHP7.0.13详解

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 默认的yum源中没有需要编译安装

#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算法

一:下载相应的软件包

1:下载libmcrypt安装mcrypt需要此软件包

#wget https://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz

2:下载mhash

#wget https://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz

3:下载mcrypt

#wget https://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz

二、安装软件包

1、安装libmcrypt

cd /usr/local/src#进入软件包存放目录

tar zxvf libmcrypt-2.5.8.tar.gz#解压

cd libmcrypt-2.5.8#进入安装目录

./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

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#添加环境变量


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 加入环境变量:

#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 ( 启动PHP进程)

#ps -ef | grep PHP-fpm (检测下PHP-fpm进程)


5:测试PHPNginxMysqL的通信正常与否

1:测试和Nginx的通信是否正常 (随意编辑一个虚拟主机,本人的如下配置)

# vim/application/Nginx/conf/extra/blog.conf

server{
listen80;
server_nameblog.niutianwen.org;
root/application/Nginx/html/blog;
indexindex.PHPindex.htmlindex.htm;
location/{
}
location~\.(PHP|PHP5)?${
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.PHP;
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
includefastcgi.conf;
}
}


# 在测试虚拟主机的网站首页写一个PHP的测试脚本

#mkdir /application//Nginx/html/blog -p 创建网站根目录

# cd/application//Nginx/html/blog

# echo "<?PHP PHPinfo(); ?>" >test_info.PHP


打开firefox测试效果

1:首先做好主机名和ip的对应

#vim /etc/hosts

本机ip地址 blog.niutianwen.org

2:在浏览器中打开http://blog.niutianwen.org/test_info.php

如出现以下界面表示PHPNginx的通信是正常的!

wKioL1gzDq3wwe_nAAF4ASpMWh4663.png-wh_50


2:测试和MysqL的通信是否正常

#cd/application//Nginx/html/blog

# vimMysqL_connect.PHP

<?PHP
$link=MysqLi_connect('127.0.0.1','root','niutianwen');
if(!$link){
echo"Error:UnabletoconnecttoMysqL.".PHP_EOL;
echo"Debuggingerrno:".MysqLi_connect_errno().PHP_EOL;
echo"Debuggingerror:".MysqLi_connect_error().PHP_EOL;
exit;
}
echo"Success:AproperconnectiontoMysqLwasmade!Themy_dbdatabaseisgreat.".PHP_EOL;
echo"Hostinformation:".MysqLi_get_host_info($link).PHP_EOL;
MysqLi_close($link);
?>


2:在浏览器中打开http://blog.niutianwen.org/mysql_connect.php

如出现下面红线标的那一行表示PHP连接MysqL是正常的!

wKioL1gzEqaBI15xAACfj1891nk046.png-wh_50


6:使用centos6.6系统默认的进程管理方式启动PHP-fpm

#vim /etc/init.d/PHP-fpm

#!/bin/sh
#CommentstosupportchkconfigonCentOS
#chkconfig:23456537
#
set-e

#PATH=/application/PHP-7.0.13/sbin:/application/PHP-7.0.13/bin
DESC="PHP-fpmdaemon"
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

#Gracefullyexitifthepackagehasbeenremoved.
test-x$DAEMON||exit0

function_start(){
[-f$PIDFILE]&&rm-rf$PIDFILE
$DAEMON-y$CONFIGFILE-g$PIDFILE&&echo"PHP-fpmisstarted"
}

function_stop(){
netstat-tunlp|grep$NAME|grep-v-egrep-evim|awk-F'/''{print$1}'|awk'{print$NF}'|xargs-I{}kill-QUIT{}2>/dev/null
[$?-eq0]&&echo"PHP-fpmisstopped"
}

function_reload()
{
[`netstat-tunlp|grep9000|wc-l`-eq0]&&echo"$DESCisnotstartup!"&&exit0
PID=`ps-ef|grep$NAME|grep-v-egrep-evim|grepmaster|awk'{print$2}'`
echo$PID
kill-USR2$PID&&echo"PHP-fpmisreloaded!"
}

case"$1"in
start)
echo-n"Starting$DESC....----->>>>"
function_start

;;
stop)
echo-n"Stopping$DESC....---->>>>"
function_stop
;;
reload)
echo-n"Reloading$DESCconfiguration....---->>>>"
function_reload
echo"reloaded."
;;
restart)
echo-n"Restarting$DESC....---->>>>"
function_stop
sleep3
function_start
;;
*)
echo"Usage:$SCRIPTNAME{start|stop|restart|force-reload}">&2
exit3
;;
esac

至此。centos6.6编译安装PHP7.0.12就OK了!

原文链接:https://www.f2er.com/centos/379816.html

猜你在找的CentOS相关文章