centos如何编译安装php-fpm


本文摘自PHP中文网,作者藏色散人,侵删。

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

推荐:《PHP视频教程》

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

系统环境

1

2

3

4

5

6

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++

依赖软件

1

yum install wget vim

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

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

开始安装

安装php依赖

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

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

1

2

3

4

5

6

7

8

9

10

11

12

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

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

1

2

3

4

gettext   #0.18.2.1

zlib   #1.2.7

pcre   #8.32

libpng   #1.5.13

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

1

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

安装php

php:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

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到编译时指定的配置文件目录

1

2

3

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版本

1

2

3

4

/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配置

1

2

3

4

5

6

7

8

9

10

11

12

13

14

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

日志轮换

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

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的详细内容,更多文章请关注木庄网络博客

相关阅读 >>

CentOS系统如何解压zip文件

ssh连接不上CentOS怎么办?

CentOS无法使用yum命令进行更新

CentOS怎么连接wifi?

CentOS如何安装ssh?

linux下怎么安装php-fpm

CentOS使用localhost无法连接数据库

CentOS怎么进入单用户模式

CentOS下无法启动httpd怎么办

linux和CentOS的区别

更多相关阅读请进入《CentOS》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...