安装PHP
安装依赖包
yum install gcc make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel �y
安装epel源
wget -O /etc/yum.repos.d/epel.repohttp://mirrors.aliyun.com/repo/epel-6.repo
yum -y install libmcrypt-devel mcytpt mhash libxslt-devel
安装libiconv
tar -zxvf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure �prefix=/usr/lcoal/libiconv
Make && make install
解压安装包
tar -zxvf PHP-5.6.20.tar.gz
配置编译安装
cd PHP-5.6.20
./configure\
�prefix=/usr/local/PHP-5.6.20 \
�with-config-file-path=/usr/local/PHP-5.6.20/etc \
�with-fpm-user=Nginx \
�with-fpm-group=Nginx \
�with-bz2 \
�with-curl \
�with-gd \
�with-mcrypt \
�with-openssl \
�with-mhash \
�with-jpeg-dir \
�with-png-dir \
�with-freetype-dir \
�with-iconv-dir=/usr/local/libiconv\
�with-gettext \
�with-libxml-dir=/usr/local \
�with-zlib \
�with-xsl \
�with-libdir=lib64 \
�enable-dom \
�enable-xml \
�enable-fpm \
�enable-bcmath \
�enable-ftp \
�enable-sockets \
�disable-ipv6 \
�enable-mbregex \
�enable-mbstring \
�enable-calendar \
�enable-gd-native-ttf \
�enable-static \
make
make install
cp PHP.ini-production /usr/local/PHP/lib/PHP.ini
cp /usr/local/PHP/etc/PHP-fpm.conf.default/usr/local/PHP/etc/PHP-fpm.conf
cd /usr/local/PHP/
mkdir log
编辑配置文件
pid = /var/log/PHP-fpm.pid
error_log = log/PHP-fpm.log
log_level = error
rlimit_files = 32768
events.mechanism = epoll
[www]
user = Nginx
group = Nginx
listen = 127.0.0.1:9000
pm = dynamic
pm.max_children = 1024
pm.start_servers = 16
pm.min_spare_servers = 5
pm.max_spare_servers = 20
pm.process_idle_timeout = 15s;
pm.max_requests = 2048
slowlog = log/$pool.log.slow
request_slowlog_timeout = 10
创建启动停止脚本:
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
prefix=/usr/local/PHP
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
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
else
echo ” done”
;;
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 ?”
kill -QUIT `cat $PHP_fpm_PID`
wait_for_pid removed $PHP_fpm_PID
echo ” Failed. Use force-quit”
status)
echo “PHP-fpm is stopped”
exit 0
PID=`cat $PHP_fpm_PID`
if ps -p $PID | grep -q $PID; then
echo “PHP-fpm (pid $PID) is running…”
echo “PHP-fpm dead but pid file exists”
force-quit)
echo -n “Terminating PHP-fpm “
kill -TERM `cat $PHP_fpm_PID`
restart)
$0 stop
$0 start
reload)
echo -n “Reload service PHP-fpm “
kill -USR2 `cat $PHP_fpm_PID`
echo ” done”
configtest)
$PHP_fpm_BIN -t
*)
echo “Usage: $0 {start|stop|force-quit|restart|reload|status|configtest}”
exit 1
esac
赋予权限
chmod +x /etc/init.d/PHP-fpm
启动
[root@zabbix-server PHP-5.6.20]# service PHP-fpm start
Starting PHP-fpmdone
[root@zabbix-server PHP-5.6.20]# netstat -anpt |grep PHP-fpm
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 16070/PHP-fpm
打开配置文件在server区块加入下面内容(这里是虚拟主机,网站根目录也在cj下面)
server {
listen 80;
server_namewww.cj.comcj.com;
charset utf-8;
#access_log logs/access_cj.log main;
access_loglogs/access_cj.log;
location / {
root html/cj;
indexindex.html index.htm;
}
error_page 500 502 503 504/50x.html;
location = /50x.html {
root html;
}
location ~ \.PHP$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_indexindex.PHP;
fastcgi_param SCRIPT_FILENAME /usr/local/Nginx/html/cj$fastcgi_script_name;
include fastcgi_params;
}
}
原文链接:https://www.f2er.com/centos/380959.html