centos 编译安装 php 5.5,基于CentOS6.5环境之下的LNMP之编译安装PHP5.5.30

基于CentOS6.5环境之下的LNMP之编译安装PHP5.5.30

发布时间:2020-04-26 21:34:55

来源:51CTO

阅读:459

作者:arliang785

LNMP之编译安装PHP5.5.30

1、编译前操作:1.1、netstat -tulnp | egrep "80|3306"

tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      25392/nginx

tcp        0      0 :::3306                     :::*                        LISTEN      53278/mysqld

1.2、yum install zlib libxml libjpeg libjpeg-devel freetype-devel libpng libpng-devel curl curl-devel libiconv zlib-devel libxml2-devel -y

#国际化本地化字符集转换软件包1.3、wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz

tar xf libiconv-1.14.tar.gz

cd libiconv-1.14

./configure --prefix=/usr/local/libconv1.14

make && make install1.4、wget http://ncu.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz

tar xf libmcrypt-2.5.8.tar.gz

cd libmcrypt-2.5.8

./configure --prefix=/usr/local/libmcrypt2.5.8

make && make install

/sbin/ldconfig

cd libltdl/

./configure --enable-ltdl-install

make && make install1.5、wget http://nchc.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz

tar xf mhash-0.9.9.9.tar.gz

cd mhash-0.9.9.9

./configure --prefix=/usr/local/mhash0.9.9.9

make && make install1.6、

ln -s /usr/local/libmcrypt2.5.8/lib/libmcrypt.la  /usr/lib/libmcrypt.la

ln -s /usr/local/libmcrypt2.5.8/lib/libmcrypt.so  /usr/lib/libmcrypt.so

ln -s /usr/local/libmcrypt2.5.8/lib/libmcrypt.so.4  /usr/lib/libmcrypt.so.4

ln -s /usr/local/libmcrypt2.5.8/lib/libmcrypt.so.4.4.8  /usr/lib/libmcrypt.so.4.4.8

ln -s /usr/local/mhash0.9.9.9/lib/libmhash.a /usr/lib/libmhash.a

ln -s /usr/local/mhash0.9.9.9/lib/libmhash.la /usr/lib/libmhash.la

ln -s /usr/local/mhash0.9.9.9/lib/libmhash.so /usr/lib/libmhash.so

ln -s /usr/local/mhash0.9.9.9/lib/libmhash.so.2 /usr/lib/libmhash.so.2

ln -s /usr/local/mhash0.9.9.9/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1

ln -s /usr/local/libmcrypt2.5.8/bin/libmcrypt-config /usr/bin/libmcrypt-config

ln -s /usr/local/libmcrypt2.5.8/include/mcrypt.h /usr/local/include/mcrypt.h1.7、wget http://nchc.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz

tar xf mcrypt-2.6.8.tar.gz

cd mcrypt-2.6.8

/sbin/ldconfig

export LD_LIBRARY_PATH=/usr/local/libmcrypt2.5.8/lib:/usr/local/lib:/usr/local/mhash0.9.9.9/lib

export LDFLAGS="-L/usr/local/libmcrypt2.5.8/lib -I/usr/local/mhash0.9.9.9/include/"

export CFLAGS="-I/usr/local/mhash0.9.9.9/include/"

./configure --prefix=/usr/local/mcrypt2.6.8 --with-libmcrypt-prefix=/usr/local/libmcrypt2.5.8

make && make install

错误1、./configure错误及解决方案*** Could not run libmcrypt test program, checking why...

*** The test program compiled, but did not run. This usually means

*** that the run-time linker is not finding LIBMCRYPT or finding the wrong

*** version of LIBMCRYPT. If it is not finding LIBMCRYPT, you'll need to set your

*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point

*** to the installed location  Also, make sure you have run ldconfig if that

*** is required on your system

***

*** If you have an old version installed, it is best to remove it, although

*** you may also be able to get things to work by modifying LD_LIBRARY_PATH

***

configure: error: *** libmcrypt was not found

解决方法:

export LD_LIBRARY_PATH=/usr/local/libmcrypt2.5.8/lib:/usr/local/lib:/usr/local/mhash0.9.9.9/lib

export LDFLAGS="-L/usr/local/libmcrypt2.5.8/lib -I/usr/local/mhash0.9.9.9/include/"

export CFLAGS="-I/usr/local/mhash0.9.9.9/include/"

2编译安装及配置php

2.1安装编译php5.5.30wget http://cn2.php.net/distributions/php-5.5.30.tar.bz2

tar jxf php-5.5.30.tar.bz2

cd php-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=nginx

ln -s /usr/local/mysql5.6.27/lib/libmysqlclient.so.18 /usr/lib

make && make install

错误2、./configure错误及解决方案:configure: error: libmcrypt version 2.5.6 or greater required

解决方法:

rpm -ivh "http://mirrors.ustc.edu.cn/epel/6Server/x86_64/epel-release-6-8.noarch.rpm"

yum install -y  libmcrypt-devel

2.2、配置php参数:cp /root/php-5.5.30/php.ini-production /usr/local/php5.5.30/lib/php.ini

cd /usr/local/php5.5.30/etc

cp php-fpm.conf.default php-fpm.conf

vim php-fpm.conf

#修改fastcgi的参数文件php-fpm.conf的相关选项值:

pid = /usr/local/php5.5.30/var/run/php-fpm.pid

pm.max_children = 40

pm.start_servers = 3

pm.min_spare_servers = 3

pm.max_spare_servers = 8

/usr/local/php5.5.30/sbin/php-fpm -t

/usr/local/php5.5.30/sbin/php-fpm

netstat -tulnp | grep 9000

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

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

server_name  www.fnw.com;

index   index.php;

把server中的以下内容注释掉:#location / {

#    root   html;

#    index  index.html index.htm;

#}

在server中添加以下内容location ~ \.php$ {

root           html;

fastcgi_pass   127.0.0.1:9000;

fastcgi_index  index.php;

fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;

#fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx1.8/html/$fastcgi_script_name;

include        fastcgi_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@fnw html]# cat >> index.php <

phpinfo();

?>

EOF[root@fnw html]# netstat -tulnp | egrep "80|3306|9000"

tcp        0      0 0.0.0.0:80               0.0.0.0:*                LISTEN      47013/nginx

tcp        0      0 127.0.0.1:9000           0.0.0.0:*                LISTEN      43900/php-fpm

tcp        0      0 :::3306                  :::*                     LISTEN      1394/mysqld

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

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

给高级管理员root用户管理MySQL 中所有数据库的权限。192.168.1.168被管理主机的ip地址。grant all on *.* to root@’192.168.1.168’

修改root用户密码update mysql.user set password=PASSWORD('123456') where host='192.168.1.168' and user='root';

在index.php文件中输入<?php

$mysql_conn=mysql_connect('192.168.1.168','root','123456') or die();

if($mysql_conn){

echo "Successful";

}else{

echo "Failure";

}

mysql_close($mysql_conn);

?>

4、配置fpm服务文件

4.1 修改php-fpm的配置文件cp php-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的命令执行路径(和安装路径一样)

15

16php_fpm_BIN=${exec_prefix}/sbin/php-fpm   #fastcgi php-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

### BEGIN INIT INFO

# Provides:          php-fpm

# Required-Start:    $remote_fs $network

# Required-Stop:     $remote_fs $network

# Default-Start:     2 3 4 5

# Default-Stop:      0 1 6

# Short-Description: starts php-fpm

# Description:       starts the PHP FastCGI Process Manager daemon

### END INIT INFO

# Source function library.

. /etc/rc.d/init.d/functions

prefix=/usr/local/php5.5.30

exec_prefix=${prefix}

php_fpm_BIN=${exec_prefix}/sbin/php-fpm

php_fpm_CONF=${prefix}/etc/php-fpm.conf

php_fpm_PID=${prefix}/var/run/php-fpm.pid

php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID"

wait_for_pid () {

try=0

while test $try -lt 35 ; do

case "$1" in

'created')

if [ -f "$2" ] ; then

try=''

break

fi

;;

'removed')

if [ ! -f "$2" ] ; then

try=''

break

fi

;;

esac

echo -n .

try=`expr $try + 1`

sleep 1

done

}

case "$1" in

start)

echo -n "Starting php-fpm "

$php_fpm_BIN --daemonize $php_opts

if [ "$?" != 0 ] ; then

echo " failed"

exit 1

fi

wait_for_pid created $php_fpm_PID

if [ -n "$try" ] ; then

echo " failed"

exit 1

else

echo " done"

fi

;;

stop)

echo -n "Gracefully shutting down php-fpm "

if [ ! -r $php_fpm_PID ] ; then

echo "warning, no pid file found - php-fpm is not running ?"

exit 1

fi

kill -QUIT `cat $php_fpm_PID`

wait_for_pid removed $php_fpm_PID

if [ -n "$try" ] ; then

echo " failed. Use force-quit"

exit 1

else

echo " done"

fi

;;

status)

if [ ! -r $php_fpm_PID ] ; then

echo "php-fpm is stopped"

exit 0

fi

PID=`cat $php_fpm_PID`

if ps -p $PID | grep -q $PID; then

echo "php-fpm (pid $PID) is running..."

else

echo "php-fpm dead but pid file exists"

fi

;;

force-quit)

echo -n "Terminating php-fpm "

if [ ! -r $php_fpm_PID ] ; then

echo "warning, no pid file found - php-fpm is not running ?"

exit 1

fi

kill -TERM `cat $php_fpm_PID`

wait_for_pid removed $php_fpm_PID

if [ -n "$try" ] ; then

echo " failed"

exit 1

else

echo " done"

fi

;;

restart)

$0 stop

$0 start

;;

reload)

echo -n "Reload service php-fpm "

if [ ! -r $php_fpm_PID ] ; then

echo "warning, no pid file found - php-fpm is not running ?"

exit 1

fi

kill -USR2 `cat $php_fpm_PID`

echo " done"

;;

*)

echo "Usage: $0 {start|stop|force-quit|restart|reload|status}"

exit 1

;;

esac

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

#给php-fpm加执行权限chmod +x /etc/init.d/php-fpm

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

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

#检查php-fpm的启动级别chkconfig --list php-fpm

php-fpm        0:off1:off2:on3:on4:on5:on6:off

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

4.3.1、启动php-fpm服务[root@fnw run]# service php-fpm start

Starting php-fpm  done

4.3.2、重启php-fpm服务[root@fnw run]# service php-fpm restart

Gracefully shutting down php-fpm . done

Starting php-fpm  done

4.3.3、平滑重启php-fpm服务[root@fnw run]# service php-fpm reload

Reload service php-fpm  done

4.3.4、查看php-fpm运行状态[root@fnw run]# service php-fpm status

php-fpm (pid 49776) is running...

4.3.5、停止php-fpm运行状态以后再看。[root@fnw run]# service php-fpm stop

Gracefully shutting down php-fpm . done

[root@fnw run]# service php-fpm status

php-fpm is stopped

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值