准备编译环境
yum -y install gcc automake autoconf libtool make gcc-c++ glibc
安装php依赖项
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
下载php安装包
cd /home/soft wget -O php-5.6.14.tar.gz http://cn2.php.net/get/php-5.6.14.tar.gz/from/this/mirror
解压php安装包
tar zxvf php-5.6.14.tar.gz
安装php
cd php-5.6.14 ./configure --enable-fpm \--enable-mbstring --disable-pdo --with-curl --disable-debug --disable-rpath \--enable-inline-ptimization --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 出现Thank for You using PHP字样说明php配置成功。 make && make install 安装php
安装成功之后创建用户和用户组
创建用户组:groupadd user-php 创建用户:useradd -g user-php user-php
配置php-fpm
cd /use/local/etc cp php-fpm.conf.default php-fpm.conf vim php-fpm.conf 修改(149行): user = user-php; group = user-php; 修改(164行),配置所有IP都可链接使用php-fpm; listen = [::]:9000;
讲php-fpm配置成service
修改php-fpm.conf文件,设置pid文件存放路径: pid = /var/run/php-fpm.pid 创建服务脚本: vim /etc/init.d/php-fpm 写入php-fpm服务脚本代码。 设置服务脚本的执行权限 chmod +x /etc/init.d/php-fpm 设置php-fpm服务开机自启动 chkconfig php-fpm on
#! /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