LNMP 中的 php7.2.4 源码包安装

发布于 2018-04-08  685 次阅读


编译安装 PHP7.2.4

下载源码包并解压

[root@LZWP:/usr/local/src#] wget http://cn2.php.net/distributions/php-7.2.4.tar.gz

--2018-04-07 15:25:01--  http://cn2.php.net/distributions/php-7.2.4.tar.gz

Resolving cn2.php.net (cn2.php.net)... 123.125.23.171, 123.125.23.172, 123.125.23.168, ...

Connecting to cn2.php.net (cn2.php.net)|123.125.23.171|:80... connected.

HTTP request sent, awaiting response... 200 OK

Length: 18305325 (17M) [application/x-gzip]

Saving to: ‘php-7.2.4.tar.gz’



100%[===========================================================================================>] 18,305,325  2.28MB/s   in 6.9s  



2018-04-07 15:25:08 (2.54 MB/s) - ‘php-7.2.4.tar.gz’ saved [18305325/18305325]

[root@LZWP:/usr/local/src#] tar xvf php-7.2.4.tar.gz

创建用户 php-fpm,然后./configure

[root@LZWP:/usr/local/src#] cd php-7.2.4/

[root@LZWP:/usr/local/src/php-7.2.4#] useradd -s /sbin/nologin php-fpm

[root@LZWP:/usr/local/src/php-7.2.4#] ./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-pear --with-curl  --with-openssl

错误解决

这里会遇到好几个错误提示

configure: error: no acceptable C compiler found in $PATH

[root@LZWP:/usr/local/src/php-7.2.4#] yum -y install gcc



configure: error: libxml2 not found. Please check your libxml2 installation.

[root@LZWP:/usr/local/src/php-7.2.4#] yum -y install libxml2-devel.x86_64



configure: error: Cannot find OpenSSL's <evp.h>

[root@LZWP:/usr/local/src/php-7.2.4#] yum -y install openssl-devel.x86_64



checking for cURL 7.10.5 or greater... configure: error: cURL version 7.10.5 or later is required to compile php with cURL support

[root@LZWP:/usr/local/src/php-7.2.4#] yum -y install libcurl-devel



configure: error: jpeglib.h not found.

[root@LZWP:/usr/local/src/php-7.2.4#] yum -y install libjpeg-turbo-devel.x86_64



configure: error: png.h not found.

[root@LZWP:/usr/local/src/php-7.2.4#] yum -y install libpng-devel.x86_64



configure: error: freetype-config not found.

[root@LZWP:/usr/local/src/php-7.2.4#] yum -y install freetype-devel.x86_64

到此,没错误提示了,开始 make

[root@LZWP:/usr/local/src/php-7.2.4#] make

提示错误,这是因为我的服务器内存只有 1G,意思是说内存不足

make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1

重新编译,加上--disable-fileinfo,记得先 make clean,把之前的 make 操作清空

[root@LZWP:/usr/local/src/php-7.2.4#] make clean

find . -name \*.gcno -o -name \*.gcda | xargs rm -f

find . -name \*.lo -o -name \*.o | xargs rm -f

find . -name \*.la -o -name \*.a | xargs rm -f

find . -name \*.so | xargs rm -f

find . -name .libs -a -type d|xargs rm -rf

rm -f libphp7.la sapi/cli/php sapi/cgi/php-cgi   sapi/fpm/php-fpm  modules/* libs/*

[root@LZWP:/usr/local/src/php-7.2.4#] ./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-pear --with-curl=  --with-openssl --disable-fileinfo

[root@LZWP:/usr/local/src/php-7.2.4#] make

[root@LZWP:/usr/local/src/php-7.2.4#] make install

把 php-fpm 命令添加到环境变量,修改 php-fpm 配置文件,启动 php-fpm

[root@LZWP:/usr/local/src/php-7.2.4#] cd /usr/local/php-fpm/sbin/

[root@LZWP:/usr/local/php-fpm/sbin#] pwd

/usr/local/php-fpm/sbin

[root@LZWP:/usr/local/php-fpm/sbin#] vim /etc/profile

  export PATH=$PATH:/usr/local/php-fpm/sbin

[root@LZWP:/usr/local/php-fpm/sbin#] source /etc/profile

[root@LZWP:/usr/local/php-fpm/sbin#] php-fpm -v

PHP 7.2.4 (fpm-fcgi) (built: Apr  7 2018 16:12:07)

Copyright (c) 1997-2018 The PHP Group

Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

[root@LZWP:/usr/local/php-fpm/sbin#] cd /usr/local/src/php-7.2.4/

[root@LZWP:/usr/local/src/php-7.2.4#] cp php.ini-production /usr/local/php-fpm/etc/php.ini

[root@LZWP:/usr/local/src/php-7.2.4#] cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

[root@LZWP:/usr/local/src/php-7.2.4#]  vim /usr/local/php-fpm/etc/php-fpm.conf

  [global]

  pid = /usr/local/php-fpm/var/run/php-fpm.pid

  error_log = /usr/local/php-fpm/var/log/php-fpm.log

  [www]

  listen = /tmp/php-fcgi.sock

  listen.mode = 666

  user = php-fpm

  group = php-fpm

  pm = dynamic

  pm.max_children = 50

  pm.start_servers = 20

  pm.min_spare_servers = 5

  pm.max_spare_servers = 35

  pm.max_requests = 500

  rlimit_files = 1024

[root@LZWP:/usr/local/src/php-7.2.4#] chmod 755 /etc/init.d/php-fpm

[root@LZWP:/usr/local/src/php-7.2.4#] chkconfig --add php-fpm

[root@LZWP:/usr/local/src/php-7.2.4#] chkconfig php-fpm on

[root@LZWP:/usr/local/src/php-7.2.4#] service php-fpm start

Starting php-fpm  done

[root@LZWP:/usr/local/src/php-7.2.4#] ps -aux | grep php

root     11517  0.0  0.6 119672  6240 ?        Ss   16:41   0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf)

php-fpm  11518  0.0  0.6 121888  6372 ?        S    16:41   0:00 php-fpm: pool www

php-fpm  11519  0.0  0.6 121888  6372 ?        S    16:41   0:00 php-fpm: pool www

php-fpm  11520  0.0  0.6 121888  6372 ?        S    16:41   0:00 php-fpm: pool www

php-fpm  11521  0.0  0.6 121888  6372 ?        S    16:41   0:00 php-fpm: pool www

php-fpm  11522  0.0  0.6 121888  6376 ?        S    16:41   0:00 php-fpm: pool www

php-fpm  11523  0.0  0.6 121888  6380 ?        S    16:41   0:00 php-fpm: pool www

php-fpm  11524  0.0  0.6 121888  6380 ?        S    16:41   0:00 php-fpm: pool www

php-fpm  11525  0.0  0.6 121888  6380 ?        S    16:41   0:00 php-fpm: pool www

php-fpm  11526  0.0  0.6 121892  6380 ?        S    16:41   0:00 php-fpm: pool www

php-fpm  11527  0.0  0.6 121892  6380 ?        S    16:41   0:00 php-fpm: pool www

php-fpm  11528  0.0  0.6 121892  6380 ?        S    16:41   0:00 php-fpm: pool www

php-fpm  11529  0.0  0.6 121892  6380 ?        S    16:41   0:00 php-fpm: pool www

php-fpm  11530  0.0  0.6 121892  6380 ?        S    16:41   0:00 php-fpm: pool www

php-fpm  11531  0.0  0.6 121892  6380 ?        S    16:41   0:00 php-fpm: pool www

php-fpm  11532  0.0  0.6 121892  6380 ?        S    16:41   0:00 php-fpm: pool www

php-fpm  11533  0.0  0.6 121892  6380 ?        S    16:41   0:00 php-fpm: pool www

php-fpm  11534  0.0  0.6 121888  6380 ?        S    16:41   0:00 php-fpm: pool www

php-fpm  11535  0.0  0.6 121888  6380 ?        S    16:41   0:00 php-fpm: pool www

php-fpm  11536  0.0  0.6 121888  6380 ?        S    16:41   0:00 php-fpm: pool www

php-fpm  11537  0.0  0.6 121888  6380 ?        S    16:41   0:00 php-fpm: pool www

root     11541  0.0  0.0 112652   960 pts/0    R+   16:41   0:00 grep --color=auto php

到此,php7.2.4 源码包安装完成!