PHP环境搭建

  • Post author:
  • Post category:php


1.安装编译环境

yum -y install gcc automake autoconf libtool make gcc-c++ glibc

2.安装依赖包(按需安装)

yum -y install libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel openssl openssl-devel

3.安装PHP

wget -O php-5.6.14.tar.gz http://cn2.php.net/get/php-5.6.14.tar.gz/from/this/mirror

tar zxvf php-5.6.14.tar.gz

cd php-5.6.14

./configure –enable-fpm \

–enable-mbstring –disable-pdo –with-curl –disable-debug  –disable-rpath \

–enable-inline-optimization –with-bz2  –with-zlib –enable-sockets \

–enable-sysvsem –enable-sysvshm –enable-pcntl –enable-mbregex \

–enable-zip –with-pcre-regex –with-mysql –with-mysqli \

–with-gd –with-jpeg-dir

make

make install

4.给php创建专有的用户和组www-data

groupadd www-data

useradd -g www-data www-data

5.生成修改php-fpm的默认配置,并使php-fpm以www-data用户的身份运行

cd /usr/local/etc/

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

vi php-fpm.conf

找到并修改为以下行(149行)

user = www-data

group = www-data

找到并修改以下行(164行)(为了支持使用任意IP访问,为后面负载均衡做准备):

listen = [::]:9000

以上修改成功后,php-fpm是可以直接提供服务了

6.将php-fpm注册将为系统服务


首先,修改php-fpm的配置文件,设置pid文件存放路径:


vi /usr/local/etc/php-fpm.conf


找到并修改如下内容(25行):


pid = /var/run/php-fpm.pid


在/etc/init.d/中我们创建一个服务脚本php-fpm


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



prefix=/usr


exec_prefix=/usr



php_fpm_BIN=/usr/local/sbin/php-fpm


php_fpm_CONF=/usr/local/etc/php-fpm.conf


php_fpm_PID=/var/run/php-fpm.pid




php_opts=”–fpm-config $php_fpm_CONF”




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 $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


;;



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}”


exit 1


;;



esac


给该脚本赋予执行权限:


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


注册为服务并随系统启动:


chkconfig php-fpm on



版权声明:本文为heloveguozi原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。