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(安装mcrypt需要此软件包)
#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
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#添加环境变量
./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 加入环境变量:
#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:测试php与nginx和mysql的通信正常与否
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
如出现以下界面表示php和nginx的通信是正常的!
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是正常的!
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/binDESC="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.pidSCRIPTNAME=/etc/init.d/$NAME#Gracefullyexitifthepackagehasbeenremoved.test-x$DAEMON||exit0function_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!"&&exit0PID=`ps-ef|grep$NAME|grep-v-egrep-evim|grepmaster|awk'{print$2}'`echo$PIDkill-USR2$PID&&echo"php-fpmisreloaded!"}case"$1"instart)echo-n"Starting$DESC....----->>>>"function_start;;stop)echo-n"Stopping$DESC....---->>>>"function_stop;;reload)echo-n"Reloading$DESCconfiguration....---->>>>"function_reloadecho"reloaded.";;restart)echo-n"Restarting$DESC....---->>>>"function_stopsleep3function_start;;*)echo"Usage:$SCRIPTNAME{start|stop|restart|force-reload}">&2exit3;;esac
至此。centos6.6编译安装PHP7.0.12就OK了!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。