1000  
查询码:00000095
Centos7下编译安装php-7.0.17(PHP-FPM)
作者: wyasw 于 2020年03月29日 发布在分类 / Linux / 服务安装 下,并于 2020年03月29日 编辑
php

Centos7下编译安装php-7.0.17(PHP-FPM)

1.1 安装所需依赖


yum install -y gcc gcc-c++ make cmake bison autoconf wget lrzsz

yum install -y libtool libtool-ltdl-devel

yum install -y freetype-devel libjpeg.x86_64 libjpeg-devel libpng-devel gd-devel

yum install -y python-devel  patch  sudo

yum install -y openssl* openssl openssl-devel ncurses-devel

yum install -y bzip* bzip2 unzip zlib-devel

yum install -y libevent*

yum install -y libxml* libxml2-devel

yum install -y libcurl* curl-devel

yum install -y readline-devel

yum install  -y  libmcrypt libmcrypt-devel mcrypt mhash

如果无法安装libiconv,请手动下载安装

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

make && make install

如果出现如下问题,说明你系统版本较高。

./stdio.h:1010:1: 错误: gets 未声明(不在函数内)

cd srclib/

sed -i -e '/gets is a security/d' ./stdio.in.h

cd ../

make && make install

如果安装libmcrypt-develmhashmcrypt出错,则重新配置yum源。

http://mirrors.aliyun.com/help/centos

1.2 下载php7源码包

http://php.net/downloads.php

如:php-7.0.17.tar.gz

wget http://cn2.php.net/distributions/php-7.0.17.tar.gz

1.3 编译PHP

创建账号

useradd -s /sbin/nologin -M www

tar xf php-7.0.17.tar.gz

cd php-7.0.17

./configure \

--prefix=/usr/local/php7 \

--with-config-file-path=/usr/local/php7/etc \

--with-config-file-scan-dir=/usr/local/php7/etc/php.d \

--with-mcrypt=/usr/include \

--enable-mysqlnd \

--with-mysqli \

--with-pdo-mysql \

--enable-fpm \

--with-fpm-user=www \

--with-fpm-group=www \

--with-gd \

--with-iconv \

--with-zlib \

--enable-xml \

--enable-shmop \

--enable-sysvsem \

--enable-inline-optimization \

--enable-mbregex \

--enable-mbstring \

--enable-ftp \

--enable-gd-native-ttf \

--with-openssl \

--enable-pcntl \

--enable-sockets \

--with-xmlrpc \

--enable-zip \

--enable-soap \

--without-pear \

--with-gettext \

--enable-session \

--with-curl \

--with-jpeg-dir \

--with-freetype-dir \

--enable-opcache

1.4 编译安装

make && make install

1.5 配置文件

ln -s /usr/local/php7/ /usr/local/php

cd php-7.0.17/

cp php.ini-production /usr/local/php7/etc/php.ini

1.5.1  php.ini

php.ini中文手册:

http://www.jinbuguo.com/php/php52-ini.html

vim /usr/local/php7/etc/php.ini

[php]

expose_php=Off

max_file_uploads=30

post_max_size=30M

[opcache]

zend_extension=opcache.so

opcache.enable=1

opcache.memory_consumption=128

opcache.max_accelerated_files=4000

opcache.revalidate_freq=60

[date]

date.timezone=Asia/Shanghai

[session]

session.sid_length=40

1.5.2  php-fpm.conf

cd /usr/local/php7/etc/

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

vim /usr/local/php7/etc/php-fpm.conf

[global]

pid = run/php-fpm.pid

error_log = log/php-fpm.log

daemonize = yes

include=/usr/local/php7/etc/php-fpm.d/*.conf

1.5.3  www.conf

cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf

vim /usr/local/php7/etc/php-fpm.d/www.conf

[www]

user = www

group = www

listen = /dev/shm/php-cgi.sock

listen.owner = www

listen.group = www

listen.mode = 0660

listen.allowed_clients = 127.0.0.1

pm = static

pm.max_children = 120 # 根据服务器内存配置 40/1GB

pm.start_servers = 30

pm.min_spare_servers = 20

pm.max_spare_servers = 40

pm.max_requests = 500

request_terminate_timeout = 300

1.6 添加环境变量

echo 'export PATH=/usr/local/php7/bin:/usr/local/php7/sbin:$PATH' >> /etc/profile

source /etc/profile

1.7  Php-fpm加入系统服务

cp sapi/fpm/init.d.php-fpm.in /etc/init.d/php7-fpm

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

###########################################################

vim /etc/init.d/php-fpm7

#! /bin/sh

# Comments to support chkconfig on CentOS

# chkconfig: 2345 65 37

#

set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

DESC="php-fpm7 daemon"

NAME=php-fpm

DAEMON=/usr/local/php7/sbin/$NAME

CONFIGFILE=/usr/local/php7/etc/php-fpm.conf

PIDFILE=/usr/local/php7/var/run/$NAME.pid

SCRIPTNAME=/etc/init.d/$NAME

# Gracefully exit if the package has been removed.

test -x $DAEMON || exit 0

d_start() {

$DAEMON -y $CONFIGFILE || echo -n " already running"

}

d_stop() {

kill -QUIT `cat $PIDFILE` || echo -n " not running"

}

d_reload() {

kill -HUP `cat $PIDFILE` || echo -n " can't reload"

}

case "$1" in

start)

echo -n "Starting $DESC is success"

d_start

echo "."

;;

stop)

echo -n "Stopping $DESC is success"

d_stop

echo "."

;;

reload)

echo -n "Reloading $DESC configuration..."

d_reload

echo "reloaded."

;;

restart)

echo -n "Restarting $DESC is success"

d_stop

sleep 1

d_start

echo "."

;;

*)

echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2

exit 3

;;

esac

chmod 755 /etc/init.d/php-fpm7

1.8 添加自启动

chkconfig --add php-fpm7

chkconfig php-fpm7 on

chkconfig --list php-fpm7

1.9 启动服务

使用service php-fpm7 start启动服务了

关闭

kill -INT `cat /usr/local/php7/var/run/php-fpm.pid`

重启

kill -USR2 `cat /usr/local/php7/var/run/php-fpm.pid`



 推荐知识

 历史版本

修改日期 修改人 备注
2020-03-29 14:48:17[当前版本] wyasw 创建版本

  目录
    文艺知识分享平台 -V 4.9.5 -wcp
    京公网安备100012199188号 京ICP备2021030911号