LNMP之编译安装PHP5.5.30

1、编译前操作:

1.1、netstat-tulnp|egrep"80|3306"tcp000.0.0.0:800.0.0.0:*LISTEN25392/nginxtcp00:::3306:::*LISTEN53278/mysqld

1.2、yuminstallzliblibxmllibjpeglibjpeg-develfreetype-devellibpnglibpng-develcurlcurl-devellibiconvzlib-devellibxml2-devel-y


#国际化本地化字符集转换软件包

1.3、wgethttp://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gztarxflibiconv-1.14.tar.gzcdlibiconv-1.14./configure--prefix=/usr/local/libconv1.14make&&makeinstall

1.4、wgethttp://ncu.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gztarxflibmcrypt-2.5.8.tar.gzcdlibmcrypt-2.5.8./configure--prefix=/usr/local/libmcrypt2.5.8make&&makeinstall/sbin/ldconfigcdlibltdl/./configure--enable-ltdl-installmake&&makeinstall

1.5、wgethttp://nchc.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gztarxfmhash-0.9.9.9.tar.gzcdmhash-0.9.9.9./configure--prefix=/usr/local/mhash0.9.9.9make&&makeinstall

1.6、ln-s/usr/local/libmcrypt2.5.8/lib/libmcrypt.la/usr/lib/libmcrypt.laln-s/usr/local/libmcrypt2.5.8/lib/libmcrypt.so/usr/lib/libmcrypt.soln-s/usr/local/libmcrypt2.5.8/lib/libmcrypt.so.4/usr/lib/libmcrypt.so.4ln-s/usr/local/libmcrypt2.5.8/lib/libmcrypt.so.4.4.8/usr/lib/libmcrypt.so.4.4.8ln-s/usr/local/mhash0.9.9.9/lib/libmhash.a/usr/lib/libmhash.aln-s/usr/local/mhash0.9.9.9/lib/libmhash.la/usr/lib/libmhash.laln-s/usr/local/mhash0.9.9.9/lib/libmhash.so/usr/lib/libmhash.soln-s/usr/local/mhash0.9.9.9/lib/libmhash.so.2/usr/lib/libmhash.so.2ln-s/usr/local/mhash0.9.9.9/lib/libmhash.so.2.0.1/usr/lib/libmhash.so.2.0.1ln-s/usr/local/libmcrypt2.5.8/bin/libmcrypt-config/usr/bin/libmcrypt-configln-s/usr/local/libmcrypt2.5.8/include/mcrypt.h/usr/local/include/mcrypt.h

1.7、wgethttp://nchc.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gztarxfmcrypt-2.6.8.tar.gzcdmcrypt-2.6.8/sbin/ldconfigexportLD_LIBRARY_PATH=/usr/local/libmcrypt2.5.8/lib:/usr/local/lib:/usr/local/mhash0.9.9.9/libexportLDFLAGS="-L/usr/local/libmcrypt2.5.8/lib-I/usr/local/mhash0.9.9.9/include/"exportCFLAGS="-I/usr/local/mhash0.9.9.9/include/"./configure--prefix=/usr/local/mcrypt2.6.8--with-libmcrypt-prefix=/usr/local/libmcrypt2.5.8make&&makeinstall



错误1、./configure错误及解决方案

***Couldnotrunlibmcrypttestprogram,checkingwhy...***Thetestprogramcompiled,butdidnotrun.Thisusuallymeans***thattherun-timelinkerisnotfindingLIBMCRYPTorfindingthewrong***versionofLIBMCRYPT.IfitisnotfindingLIBMCRYPT,you'llneedtosetyour***LD_LIBRARY_PATHenvironmentvariable,oredit/etc/ld.so.conftopoint***totheinstalledlocationAlso,makesureyouhaverunldconfigifthat***isrequiredonyoursystem******Ifyouhaveanoldversioninstalled,itisbesttoremoveit,although***youmayalsobeabletogetthingstoworkbymodifyingLD_LIBRARY_PATH***configure:error:***libmcryptwasnotfound解决方法:exportLD_LIBRARY_PATH=/usr/local/libmcrypt2.5.8/lib:/usr/local/lib:/usr/local/mhash0.9.9.9/libexportLDFLAGS="-L/usr/local/libmcrypt2.5.8/lib-I/usr/local/mhash0.9.9.9/include/"exportCFLAGS="-I/usr/local/mhash0.9.9.9/include/"


2编译安装及配置php

2.1安装编译php5.5.30

wgethttp://cn2.php.net/distributions/php-5.5.30.tar.bz2tarjxfphp-5.5.30.tar.bz2cdphp-5.5.30./configure--prefix=/usr/local/php5.5.30--with-mysql=/usr/local/mysql5.6.27--with-iconv-dir=/usr/local/libconv1.14--enable-fpm--enable-sockets--enable-sysvsem--enable-mbstring--enable-pcntl--enable-gd-native-ttf--enable-zip--enable-shmop--enable-inline-optimization--enable-bcmath--enable-ftp--with-freetype-dir--with-jpeg-dir--with-png-dir--with-zlib-dir--with-openssl--with-mhash--with-mcrypt--with-config-file-path=/etc--with-config-file-scan-dir=/etc/php.d--with-bz2--with-xmlrpc--with-curl--with-xsl--with-fpm-user=nginx--with-fpm-group=nginxln-s/usr/local/mysql5.6.27/lib/libmysqlclient.so.18/usr/libmake&&makeinstall


错误2、./configure错误及解决方案:

configure:error:libmcryptversion2.5.6orgreaterrequired解决方法:rpm-ivh"http://mirrors.ustc.edu.cn/epel/6Server/x86_64/epel-release-6-8.noarch.rpm"yuminstall-ylibmcrypt-devel


2.2、配置php参数:

cp/root/php-5.5.30/php.ini-production/usr/local/php5.5.30/lib/php.inicd/usr/local/php5.5.30/etccpphp-fpm.conf.defaultphp-fpm.confvimphp-fpm.conf#修改fastcgi的参数文件php-fpm.conf的相关选项值:pid=/usr/local/php5.5.30/var/run/php-fpm.pidpm.max_children=40pm.start_servers=3pm.min_spare_servers=3pm.max_spare_servers=8/usr/local/php5.5.30/sbin/php-fpm-t/usr/local/php5.5.30/sbin/php-fpmnetstat-tulnp|grep9000


2.3修改ngnix的配置文件nginx.conf(/usr/local/nginx-1.8.0/conf/nginx.conf)

在server标签的server_name下添加一行为(indexindex.php)的配置代码

listen80;server_namewww.fnw.com;indexindex.php;

把server中的以下内容注释掉:

#location/{#roothtml;#indexindex.htmlindex.htm;#}

在server中添加以下内容

location~\.php${roothtml;fastcgi_pass127.0.0.1:9000;fastcgi_indexindex.php;fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;#fastcgi_paramSCRIPT_FILENAME/usr/local/nginx1.8/html/$fastcgi_script_name;includefastcgi_params;}


如果nginx没有启动则执行:/usr/local/nginx-1.8.0/sbin/nginx

若nginx服务器已经启动则执行:/usr/local/nginx-1.8.0/sbin/nginx -s reload


3、测试nginx,php,mysql是否成功:

3.1、测试php,ngnix是否配置成功

[root@fnwhtml]#cat>>index.php<<EOF<?phpphpinfo();?>EOF

[root@fnwhtml]#netstat-tulnp|egrep"80|3306|9000"tcp000.0.0.0:800.0.0.0:*LISTEN47013/nginxtcp00127.0.0.1:90000.0.0.0:*LISTEN43900/php-fpmtcp00:::3306:::*LISTEN1394/mysqld


在网页浏览器中输入 http://192.168.1.168


3.2、测试php和mysql是否可以连接成功:

给高级管理员root用户管理MySQL 中所有数据库的权限。192.168.1.168被管理主机的ip地址。

grantallon*.*toroot@’192.168.1.168’

修改root用户密码

updatemysql.usersetpassword=PASSWORD('123456')wherehost='192.168.1.168'anduser='root';


在index.php文件中输入

<?php$mysql_conn=mysql_connect('192.168.1.168','root','123456')ordie();if($mysql_conn){echo"Successful";}else{echo"Failure";}mysql_close($mysql_conn);?>


4、配置fpm服务文件

4.1 修改php-fpm的配置文件

cpphp-5.5.30/sapi/fpm/init.d.php-fpm.in/etc/init.d/php-fpm

修改/etc/init.d/php-fpm 文件中13到18行的内容为:

13prefix=/usr/local/php5.5.30#php5.5.30的安装路径14exec_prefix=${prefix}#php5.5.30的命令执行路径(和安装路径一样)1516php_fpm_BIN=${exec_prefix}/sbin/php-fpm#fastcgiphp-fpm执行命名17php_fpm_CONF=${prefix}/etc/php-fpm.conf#php-fpm的配置文件18php_fpm_PID=${prefix}/var/run/php-fpm.pid#php-fpm的进程号(pid



编辑好之后用vim查看结果:

vim/etc/init.d/php-fpm#!/bin/sh###BEGININITINFO#Provides:php-fpm#Required-Start:$remote_fs$network#Required-Stop:$remote_fs$network#Default-Start:2345#Default-Stop:016#Short-Description:startsphp-fpm#Description:startsthePHPFastCGIProcessManagerdaemon###ENDINITINFO#Sourcefunctionlibrary../etc/rc.d/init.d/functionsprefix=/usr/local/php5.5.30exec_prefix=${prefix}php_fpm_BIN=${exec_prefix}/sbin/php-fpmphp_fpm_CONF=${prefix}/etc/php-fpm.confphp_fpm_PID=${prefix}/var/run/php-fpm.pidphp_opts="--fpm-config$php_fpm_CONF--pid$php_fpm_PID"wait_for_pid(){try=0whiletest$try-lt35;docase"$1"in'created')if[-f"$2"];thentry=''breakfi;;'removed')if[!-f"$2"];thentry=''breakfi;;esacecho-n.try=`expr$try+1`sleep1done}case"$1"instart)echo-n"Startingphp-fpm"$php_fpm_BIN--daemonize$php_optsif["$?"!=0];thenecho"failed"exit1fiwait_for_pidcreated$php_fpm_PIDif[-n"$try"];thenecho"failed"exit1elseecho"done"fi;;stop)echo-n"Gracefullyshuttingdownphp-fpm"if[!-r$php_fpm_PID];thenecho"warning,nopidfilefound-php-fpmisnotrunning?"exit1fikill-QUIT`cat$php_fpm_PID`wait_for_pidremoved$php_fpm_PIDif[-n"$try"];thenecho"failed.Useforce-quit"exit1elseecho"done"fi;;status)if[!-r$php_fpm_PID];thenecho"php-fpmisstopped"exit0fiPID=`cat$php_fpm_PID`ifps-p$PID|grep-q$PID;thenecho"php-fpm(pid$PID)isrunning..."elseecho"php-fpmdeadbutpidfileexists"fi;;force-quit)echo-n"Terminatingphp-fpm"if[!-r$php_fpm_PID];thenecho"warning,nopidfilefound-php-fpmisnotrunning?"exit1fikill-TERM`cat$php_fpm_PID`wait_for_pidremoved$php_fpm_PIDif[-n"$try"];thenecho"failed"exit1elseecho"done"fi;;restart)$0stop$0start;;reload)echo-n"Reloadservicephp-fpm"if[!-r$php_fpm_PID];thenecho"warning,nopidfilefound-php-fpmisnotrunning?"exit1fikill-USR2`cat$php_fpm_PID`echo"done";;*)echo"Usage:$0{start|stop|force-quit|restart|reload|status}"exit1;;esac


4.2、给php-fpm添加到只启动服务里

#给php-fpm加执行权限

chmod+x/etc/init.d/php-fpm


#添加php-fpm服务。chkconfig确保每个运行级有一项启动(S)或者杀死(K)入口。如有缺少,则会从缺省的init脚本自动建立

chkconfig--addphp-fpm


#设置php-fpm在开启时候的运行级别的状态,默认级别为2、3、4、5

chkconfigphp-fpmon


#检查php-fpm的启动级别

chkconfig--listphp-fpmphp-fpm0:off1:off2:on3:on4:on5:on6:off


4.3测试php-fpm的启动服务:

4.3.1、启动php-fpm服务

[root@fnwrun]#servicephp-fpmstartStartingphp-fpmdone


4.3.2、重启php-fpm服务

[root@fnwrun]#servicephp-fpmrestartGracefullyshuttingdownphp-fpm.doneStartingphp-fpmdone


4.3.3、平滑重启php-fpm服务

[root@fnwrun]#servicephp-fpmreloadReloadservicephp-fpmdone


4.3.4、查看php-fpm运行状态

[root@fnwrun]#servicephp-fpmstatusphp-fpm(pid49776)isrunning...


4.3.5、停止php-fpm运行状态以后再看。

[root@fnwrun]#servicephp-fpmstopGracefullyshuttingdownphp-fpm.done[root@fnwrun]#servicephp-fpmstatusphp-fpmisstopped