centos如何编译安装php-fpm

centos编译安装php-fpm的方法:首先通过“yum install wget vim”安装依赖软件;然后安装php依赖;接着拷贝“php.ini-producti2 V | @ c p ) von”到编译时指定的配置文件目录;最后检查PHP版本即可。

推荐:《PHP视频教程》

CentOS7下编译安装PHP5.4.45并编译php-fpm

系统环境

un| o I zame -a
Linux localhosw / I h l v 5t.local[ T / O Z 6domain 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:43 b 3 c T 8 N p L1 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
date
Fri Feb 2 22:12:58 CST 2018

所需文件

源码

PHP : http://sg2.php.net/distributions/php-5.4.45.tar.gz

编译环境

gcc

依赖3 + 7 8 O O J 1 6:cpp、glibc-devel、glibc-headers、kernel-headers、libmpc、mpfr

伴随升级:glibc、glibc-U W d b ` % p scommon、libgcc、libgomp

gcc-c++

依赖:libstdc++-devel

伴随升级:libstdc++

yum install gcc gcc-c++

依赖软件

yum install wget vim

wget用于下载,vim方便编辑文件

编译安装需要对应功能的头文件,头文件的获得方式有两个方式,一个是通过yum安装对应的devel包D j , 2 9 3 O x ],里面就包含了编译过9 r v 1 ?程中所需y , C要文件;另外一种方式就是下载需要的源码包,并且解压缩,然后在configue中指定v r o a H 6 m 0源文件位置即可。

开始安装

安装p) , k h Ahp依赖

这里使用yum进安装,当然,也可以u c A S } (选择使用源码包。使用源码时,最好选择与yum相对J a ( g 1 B &应的版本,否则可能会不现兼容性问v 题。

源码下载位置:http://va* r D I E J C Nult.centos.org/centos/7/os/Source/SPackages/

yum install libxml2-devel    #2.9.] b F 5 | n W1
yum install openssl openss1 T s Jl-devel   #1.0.2k
yum install bzf V z +ip2 bzip2-devel   #1.0.6
yum in9 ? mstall curl curl-develf 0 r g # 6 N y   #7.29.0
y$ R pum install libjpegR e _ b $ U libjpeg-devel   #libjpeg-turbo-1.2.90
yum install libpng libpng-devel  #1.5.13
yum in6 r + T v  @ V 9stall libxslt libxslt-develq s } # Z  $ U `  #1.1.28
yum install freetype freen I ,  Ctypez F 8 @ 1 D-devel   #2.4.11
yum installO B N ? T G r gmp gD # C k I A Ump-devel   #6.0.0
yum inz . g &stall icu libicu-devel   #50.1e 2 9 a n 9.2
yum install -y epel-rele7 j  ` = ] { ` Rase && yum install% g + -y lib!  K 6 jmcrypt libmcrypt-devel   #2.5.I h + k V Y8该包CentOS默认源中没有,所以使用epel的源
yum install unixODBC unixODBC-devel #2.3.1

下面这些会依赖安装,如不确定也可手动再安装一次

gettext   #0.18.2.1
zlib   #1.2.7
pcre   #8.32
libpng   #1; & { J f.5.h ` 0 = d E L13

@ D R 0 R e a使I o s + m & ] 9 r用源码方式,为保证功能完整性,需安装以下包:

yum install libxml2 openssl bzip2 curX M H g 0l libjpeg freetype gmp icu libicu libmcrypt unixODBC gettext zlib pcre libpng

安装php

php:

wget http://J V Q 7 sg2.php.net/distribuE - G n M ; c Htions/php-5.Z i v B b 1 , I K4.45.tar.gz
tar zxvf php-5.4.45.tar.gz
cd php-5.4.45
./configure \
--prefix=/opt/web_engine/php \
--with-cR M }onfig-fil$  $ P D  ke-path=/ov ) e `pt/web_engine/php/etc \
--w+ U } Z G : 2ith-gettext \
--with-gmp \
--with-. 7 x Y f T ^ c Qmysql \
--with-openssl \
--with-pdo-mysql \
--with-bz2 \
--with-i [ } 4curl \
--with-mcrypt \
--with-mhash \
--with-freetype-dir \
--with-unixODBM , y Z & ? bC=/usr/ \
--with-pdo-odbc=unixODBC,/usr/ \
--with-libxml-dir \
--with-zlib \? i B $ /
--with-pcre-dir \
--with-gd \y : s | d ^ l
--with-jpeg-dir \
--with-png-dir \
--with-xmlrpc \
--with-libxml-dir \
--with-xsl \
--enable-soap \P ) $ ) | x D *
--enable-sysvmsg \
--enable-wddx \
--enable-zip \
--enable-exif \
--enable-intl \
--enable-bcmath \
--enable-calendar \
--enable-mbstring \
--enable-shmop \
--enable-fpm \
--enable-socket} B }s
make && make install
Installing PHP CLI binary: /opt/wi w Ieb_engine/php/bin/
Installing PHP CLd X 2 M a H ? kI man page: /opt/w L Keb_engine/php/php/man/man1/
Installing PHP FPM binary:7 F f [ c } ( /opt/web_engine/php/Z  | r P _ V Asbin/
Installinh s ! 3g PHP FPM config: /optk Q 5 9 X 2 R @/web_engine/php/etc/- n B M Y k 2 e ~
Installing PHP FPM man page: /opt/wY v 0eb_engine/php/php/man/man8/
Installing PHP FPM status page: /opt/web_engine/php/php/fpm/
InstallQ j U d ; 2 k =ing PHP CGI binary: /opt/web_engi] z % M 6  $ S Tne/S O h Mphp/bin/
Installing PHP CGI man page: /opt/web_engine/php/php/man/man1/
Installing build environment: /opt/web_enginL B W & T i f = 1e/php/lib/php/build/
Installing hek F @ 1 n M xader files: /opt/wZ  K [eb_engu G M n u k ) e ,ine/php/include/php/
Installing helper programs: /opt/web_engine/T | z ; 2 (php/bin/
program: phpize
program: php-config
Installing man pages: /opt/web_engine/php/php/man/ma% | I ^n1/
page: phpize.1
page: php-config.1
Installing PEAR environment: /opt/web_engine/php/lib] n u/php/
[PEAR] Archive_Tar - installed: 1` c {.3.12
[PEAR] Console_Getopt - installed: 1.3.1
[PEAR] Structures_Graph- installed: 1.0.4
[PEAR] XMLs u c {_Util - installed: 1? ^ l ? n *.2.3
[P ? x A ` } iPEAR] PEAR - installed: 1.9.5
Wr~ i T cote PEAR system config file at: /opt/web_engine/php/etc/pear.conf
You may wan) O t y  q s Ut to add: /opt/web_engine/php/l, ` u 9 ` 0 s Mib/php to your php.ini include_path
/root/php-5.4.45/build/X # : n m Dshtool inH & a U  # p % zstall -c ext/pha. ? 2   cr/phar.phar /opt/web_engiI . 4 Y Lne/php/= Y L @ J ! n Kbin
ln -s -f /opt/web_engine/php/bin/phar.phar /o l ? t A R k N +opt/web_engine/php/bin/phar
Inj A ! ; _ ~stalling PDO headers: /opt/webs h a N_engine/php/include/php/ext/pdo/

后续工作

拷贝源码目录下的php.ini-pr~ h M 0 Yoduction到编译时指定的配置文件目录

cp /root/php-5.4.45/php.ini-production /optT O U U H i/web_engine/php/etc
cd /opt/web_engine/php/etc && cp phps l | r.ini-production php.ini
cd /opt/web_engine/php/etc && cp php-fpm.conf.default php-fpm.conf

另外,若有知定义php扩展,则安装扩展

检查PHP版本

/opt/web_engi? # 9 Rne/phpp , = ?/bin/php -v
PHP 5.4.45 (cli) (built: Feb 2 2018 15:44:07)
Copyright (c) 1997-2014 The PHP GR N d _roup
Zend Engine v2.4.0, Copyrigb 9 # C = I 2 `ht (c) 1998-201Y k h  q X W }4 Zend Technologies

查看详细信息

/opt/web_engine/php/bin/php -i

...

systec t s . i l v Smd配u Z * }

vim /usr/lib/systemd/system/php-fpm.service
[Unit]
DescriptiZ d D x |on=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=simple
PIDFilE Q Ue=/opt/webo ( ` z ;_engine/ph= ; ` % ? vp/var/ruH v + ` 2 S ]n/php-fpm.pid
ExecStart=/opt/wm ; Neb_engine/php/sbin/php-fpm --nodaemonizE 2 ; } H |e --P } Cfpm-config /opt/web_engine/php/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $Mx - /AINPIDe
[InstallK s / o]
WantedBy=multi-user.target

日志轮换G ] ? 8 ) 4 E D *

vim /etc/logrotate.d/php-fpm
/var/log/php-fpm/*.log {
su root root
d_ . 1 e % B Gaily
missingok
rotate 52
compress
delaycompress
notifempty
olddir /var/log/php-fpm/archive
#create 640 nginx adm
sharedscripts
postrotate
/bin/kill -SIGUSR1 `cat /opt/web_engine/php/var/run/php-fpm.pid 2&gh o bt;/dev/null` 2>/dev/null || true
endscript
}

以上就是centos如何编译安装php-fpm的详细内容。