centos如何编译安装php-fpm

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

创新互联建站专业为企业提供德清网站建设、德清做网站、德清网站设计、德清网站制作等企业网站建设、网页设计与制作、德清企业网站模板建站服务,十年德清做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

推荐:《PHP视频教程》

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

系统环境

uname -a
Linux localhost.localdomain 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 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

依赖:cpp、glibc-devel、glibc-headers、kernel-headers、libmpc、mpfr

伴随升级:glibc、glibc-common、libgcc、libgomp

gcc-c++

依赖:libstdc++-devel

伴随升级:libstdc++

yum install gcc gcc-c++

依赖软件

yum install wget vim

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

编译安装需要对应功能的头文件,头文件的获得方式有两个方式,一个是通过yum安装对应的devel包,里面就包含了编译过程中所需要文件;另外一种方式就是下载需要的源码包,并且解压缩,然后在configue中指定源文件位置即可。

开始安装

安装php依赖

这里使用yum进行安装,当然,也可以选择使用源码包。使用源码时,最好选择与yum相对应的版本,否则可能会不现兼容性问题。

源码下载位置:http://vault.centos.org/centos/7/os/Source/SPackages/

yum install libxml2-devel    #2.9.1
yum install openssl openssl-devel   #1.0.2k
yum install bzip2 bzip2-devel   #1.0.6
yum install curl curl-devel   #7.29.0
yum install libjpeg libjpeg-devel   #libjpeg-turbo-1.2.90
yum install libpng libpng-devel  #1.5.13
yum install libxslt libxslt-devel  #1.1.28
yum install freetype freetype-devel   #2.4.11
yum install gmp gmp-devel   #6.0.0
yum install icu libicu-devel   #50.1.2
yum install -y epel-release && yum install -y libmcrypt libmcrypt-devel   #2.5.8该包CentOS默认源中没有,所以使用epel的源
yum install unixODBC unixODBC-devel #2.3.1

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

gettext   #0.18.2.1
zlib   #1.2.7
pcre   #8.32
libpng   #1.5.13

若使用源码方式,为保证功能完整性,需安装以下包:

yum install libxml2 openssl bzip2 curl libjpeg freetype gmp icu libicu libmcrypt unixODBC gettext zlib pcre libpng

安装php

php:

wget http://sg2.php.net/distributions/php-5.4.45.tar.gz
tar zxvf php-5.4.45.tar.gz
cd php-5.4.45
./configure \\
--prefix=/opt/web_engine/php \\
--with-config-file-path=/opt/web_engine/php/etc \\
--with-gettext \\
--with-gmp \\
--with-mysql \\
--with-openssl \\
--with-pdo-mysql \\
--with-bz2 \\
--with-curl \\
--with-mcrypt \\
--with-mhash \\
--with-freetype-dir \\
--with-unixODBC=/usr/ \\
--with-pdo-odbc=unixODBC,/usr/ \\
--with-libxml-dir \\
--with-zlib \\
--with-pcre-dir \\
--with-gd \\
--with-jpeg-dir \\
--with-png-dir \\
--with-xmlrpc \\
--with-libxml-dir \\
--with-xsl \\
--enable-soap \\
--enable-sysvmsg \\
--enable-wddx \\
--enable-zip \\
--enable-exif \\
--enable-intl \\
--enable-bcmath \\
--enable-calendar \\
--enable-mbstring \\
--enable-shmop \\
--enable-fpm \\
--enable-sockets
make && make install
Installing PHP CLI binary: /opt/web_engine/php/bin/
Installing PHP CLI man page: /opt/web_engine/php/php/man/man1/
Installing PHP FPM binary: /opt/web_engine/php/sbin/
Installing PHP FPM config: /opt/web_engine/php/etc/
Installing PHP FPM man page: /opt/web_engine/php/php/man/man8/
Installing PHP FPM status page: /opt/web_engine/php/php/fpm/
Installing PHP CGI binary: /opt/web_engine/php/bin/
Installing PHP CGI man page: /opt/web_engine/php/php/man/man1/
Installing build environment: /opt/web_engine/php/lib/php/build/
Installing header files: /opt/web_engine/php/include/php/
Installing helper programs: /opt/web_engine/php/bin/
program: phpize
program: php-config
Installing man pages: /opt/web_engine/php/php/man/man1/
page: phpize.1
page: php-config.1
Installing PEAR environment: /opt/web_engine/php/lib/php/
[PEAR] Archive_Tar - installed: 1.3.12
[PEAR] Console_Getopt - installed: 1.3.1
[PEAR] Structures_Graph- installed: 1.0.4
[PEAR] XML_Util - installed: 1.2.3
[PEAR] PEAR - installed: 1.9.5
Wrote PEAR system config file at: /opt/web_engine/php/etc/pear.conf
You may want to add: /opt/web_engine/php/lib/php to your php.ini include_path
/root/php-5.4.45/build/shtool install -c ext/phar/phar.phar /opt/web_engine/php/bin
ln -s -f /opt/web_engine/php/bin/phar.phar /opt/web_engine/php/bin/phar
Installing PDO headers: /opt/web_engine/php/include/php/ext/pdo/

后续工作

拷贝源码目录下的php.ini-production到编译时指定的配置文件目录

cp /root/php-5.4.45/php.ini-production /opt/web_engine/php/etc
cd /opt/web_engine/php/etc && cp php.ini-production php.ini
cd /opt/web_engine/php/etc && cp php-fpm.conf.default php-fpm.conf

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

检查PHP版本

/opt/web_engine/php/bin/php -v
PHP 5.4.45 (cli) (built: Feb 2 2018 15:44:07)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies

查看详细信息

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

...

systemd配置

vim /usr/lib/systemd/system/php-fpm.service
 
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
 
[Service]
Type=simple
PIDFile=/opt/web_engine/php/var/run/php-fpm.pid
ExecStart=/opt/web_engine/php/sbin/php-fpm --nodaemonize --fpm-config /opt/web_engine/php/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPIDe
 
[Install]
WantedBy=multi-user.target

日志轮换

vim /etc/logrotate.d/php-fpm
/var/log/php-fpm/*.log {
    su root root
    daily
    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>/dev/null` 2>/dev/null || true
    endscript
}

当前名称:centos如何编译安装php-fpm
URL标题:http://hbruida.cn/article/cpppei.html