ECS里Centos7.2下编译安装PHP-7.2.11(PHP-FPM)

centos7下编译安装php-7.2.11(PHP-FPM)

一、下载php7源码包

1

http://php.net/downloads.php

如:php-7.2.11.tar.gz

二、安装所需依赖

> yum -y install gd-devel zlib-devel libjpeg-devel libpng-devel libiconv-devel freetype-devel libxml2 libxml2-devel openssl openssl-devel curl-devel libxslt-devel libmcrypt-devel mhash mcrypt


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

1

http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz

1

2

3

4

> tar xf libiconv-1.14.tar.gz

> cd libiconv-1.14

> ./configure --prefix=/usr/local/libiconv

> make && make install

如果出现如下问题,说明你系统版本较高。
./stdio.h:1010:1: 错误:‘gets’未声明(不在函数内)

1

2

3

4

> cd srclib/

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

> cd ../

> make && make install

如果安装libmcrypt-devel、mhash、mcrypt出错,则重新配置yum源。

1

2

http://mirrors.163.com/.help/centos.html

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

 
三、编译PHP
创建账号

> useradd -s /sbin/nologin -M nginx
> cd /usr/local/src
> wet http://tw2.php.net/get/php-7.2.11.tar.gz/from/this/mirror
> tar xf php-7.2.11.tar.gz
> cd /usr/local/src/php-7.2.11
> ./configure --prefix=/usr/local/php \
--with-openssl \
--with-pcre-regex \
--with-kerberos \
--with-libdir=lib \
--with-libxml-dir \
--with-mysqli=shared,mysqlnd \
--with-pdo-mysql=shared,mysqlnd \
--with-pdo-sqlite \
--with-gd \
--with-iconv \
--with-zlib \
--with-xmlrpc \
--with-xsl \
--with-pear \
--with-gettext \
--with-curl \
--with-png-dir \
--with-jpeg-dir \
--with-freetype-dir \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-mysqlnd \
--enable-zip \
--enable-inline-optimization \
--enable-shared \
--enable-libxml \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-mbregex \
--enable-mbstring \
--enable-ftp \
--enable-gd-native-ttf \
--enable-pcntl \
--enable-sockets \
--enable-soap \
--enable-session \
--enable-opcache \
--enable-fpm \
--enable-maintainer-zts \
--enable-fileinfo \

 

 

1

> make && make install

四、make && make install

五、配置文件
     PHP 源文件路径: /usr/local/src/php-7.2.11/
     PHP 安装路径: /usr/local/php/

1

2

3

4

> cp /usr/local/src/php-7.2.11/php.ini-development /usr/local/php/lib/php.ini

> cp -R /usr/local/src/php-7.2.11/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

> cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

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

六、修改php.ini

1

2

mkdir /usr/local/php/tmp

chmod 766 /usr/local/php/tmp

1

2

3

extension_dir = "/usr/local/php/lib/php/extensions/no-debug-zts-20151012/"

session.save_path = "/usr/local/php/tmp"

date.timezone = PRC

七、添加环境变量及PHP-FPM 配置文件

//创建 php-fpm.service
[root@aerchi~]# cd /usr/lib/systemd/system
[root@aerchi system]# vim php-fpm.service
[Unit]
Description=php-fpm
After=syslog.target network.target

[Service]
Type=forking
PIDFile=/var/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID ExecStop=/bin/kill −INT $MAINPID
PrivateTmp=true

[Install]
antedBy=multi-user.target

PID 路径 :   /usr/local/php/etc/php-fpm.conf   

php-fpm的pid文件默认在php安装目录下var/run/php-fpm.pid

当然这是可以更改的,在 /usr/local/php/etc/php-fpm.conf 文件中 或者:   /etc/init.d/php-fpm 文件中

 [global]
; Pid file
; Note: the default prefix is /usr/local/php/var
; Default Value: none
pid = /run/php-fpm.pid

 

 

1. 添加环境变量

1

2

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

> source /etc/profile

2. PHP-FPM 配置文件

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

 

Ngnix 下反向代理自启动设置,如下 

在Linux中将php-fpm配置成服务的方法
1.配置php-fpm.conf
vim /usr/local/php/etc/php-fpm.conf
php-fpm.pid 目录必须指向:/usr/local/php/var/run/php-fpm.pid

/usr/local/php/etc/php-fpm.d/www.conf 通常配置nginx 端口及用户名帐号


2.拷贝php-fpm脚本至/etc/init.d目录
cp /home/soft/php-5.3.15/sapi/fpm/init.d.php-fpm   /etc/init.d/php-fpm
 

3.设置权限并启动php-fpm:

chmod 755 /etc/init.d/php-fpm
/etc/init.d/php-fpm start
chkconfig –add php-fpm


php-fpm以服务的方式启动、停止和重启:

service php-fpm start
service php-fpm stop
service php-fpm reload

八、添加自启动

1

2

3

> chkconfig --add php-fpm

> chkconfig php-fpm on

> chkconfig --list php-fpm

九、启动服务

1

2

3

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

> service php-fpm start

> ps -ef|grep php-fpm

十、php-fpm重启


关闭

kill -INT `cat /run/php-fpm.pid`
//or 
pkill -9 php-cgi
pkill -9 php-fpm

检测配置文件

/usr/local/php/sbin/php-fpm -t

重启

service php-fpm start
或
/etc/init.d/php-fpm start


乐意黎

你可能感兴趣的:(Centos+Unix)