Ubuntu 编译 PHP 7.2.28

安装依赖软件

apt-get install libxml2-dev libjpeg-dev libpng-dev libfreetype6-dev libzip-dev libc-client2007e-dev libglib2.0-dev libpng12-dev libssl-dev  zlib1g-dev apt-get install libxtst-dev

编译 libiconv 组件

wget https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.16.tar.gz
tar xf libiconv-1.16.tar.gz  && cd libiconv-1.16
./configure --prefix=/usr/local ; echo $?
make  && make install
ldconfig

编译 PHP

wget https://www.php.net/distributions/php-7.2.28.tar.gz
tar xf php-7.2.28.tar.gz  && cd php-7.2.28
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/etc/conf.d  --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --enable-exif --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo --enable-maintainer-zts --disable-debug ; echo $?

make install ; echo $?
cp php.ini-development /usr/local/php/etc/php.ini  // 复制配置文件

报错 1

-- more -->llect2: error: ld returned 1 exit status
Makefile:291: recipe for target 'sapi/cli/php' failed
make: *** [sapi/cli/php] Error 1

解决:

ln -s /usr/local/lib/libiconv.so.2 /lib64/
make ZEND_EXTRA_LIBS='-liconv' -j 1 ; echo $?

报错2 (如果基于CentOS 7 make时报错)

缺少curl扩展包
cURL 7.10.5 or greater... configure: error: cURL version 7.10.5 or later is required to compile php with cURL support

解决:

yum -y install curl-devel
make

启动脚本

Ubuntu
vim /lib/systemd/system/php-fpm.service

CentOS
vim /usr/lib/systemd/system/php-fpm.service

[Unit]
Description=The PHP FastCGI Process Manager
Documentation=http://php.net/docs.php
After=network.target

[Service]
Type=simple
PIDFile=/usr/local/php/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
LimitNOFILE=1000000
LimitNPROC=1000000
LimitCORE=1000000

[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl start php-fpm
systemctl enable php-fpm