怎样编译安装PHP7.3.*

2018年12月20日 | 分类: 【技术】

快速安装:https://amon.org/php73

参考:https://github.com/gitKearney/php7-from-scratch

【依赖】

安装次序:1. aspell/pspell > 2. Libmcrypt > 3. mhash > 4. mcrypt

1. 编译安装aspell/pspell

PHP5可以跳过这个文件,直接把configure命令中的 –with-pspell 参数去掉即可。

这两个扩展会识别单词的拼法是否正确并给出意见。

如果需要在编译PHP时添加pspell支持,必须安装aspell库。

编译php时加上 ./configure –with-pspell=/usr 如果是phpize 编译 –with-pspell=/usr

2/3/4. 编译安装mcrypt:

参考:https://amon.org/mcrypt

编译安装GD库及依赖包:1. zlib > 2. libpng > 3. freetype > 4. jpeg > 5. libxpm > 6. libgd

1. 编译安装zlib:

参考:https://amon.org/zlib

2. 编译安装libpng:

参考:https://amon.org/libpng

3. 编译安装freetype

参考:https://amon.org/freetype

4. 编译安装jpeg

参考:https://amon.org/jpeg

5. yum 安装libxpm:

yum install libXpm libXpm-devel

6. 编译安装libgd:

参考:https://amon.org/libgd

其他依赖

yum 安装 gmp:

yum install gmp gmp-devel

yum 安装 libc-client:

yum install libc-client libc-client-devel

创建软连接:

ln -s /usr/lib64/libc-client.so /usr/lib/libc-client.so
ln -s /usr/lib64/libldap* /usr/lib/

必须创建软连接,不然在编译PHP的时候,会报错找不到文件。

编译安装 libicu :

参考:https://amon.org/icu

如果已编译安装nghttp2,此步骤已完成。

如果没有安装libicu的话,在编译PHP的时候,会报错:

configure: error: Unable to detect ICU prefix or no failed. Please verify ICU install prefix and make sure icu-config works.

编译安装 libzip:

参考:https://amon.org/libzip

编译安装 liconv:

参考:https://amon.org/libiconv

如果没安装,会在编译时报错:

/usr/bin/ld: cannot find -liconv
collect2: error: ld returned 1 exit status
make: *** [libphp7.la] Error 1

【安装】

下载:http://php.net/downloads.php

wget https://us2.php.net/distributions/php-7.3.23.tar.xz --no-check-certificate && tar -xvf php-7.3.23.tar.xz && cd php-7.3.23

Apache 服务器环境:

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=apache --with-fpm-group=apache --disable-debug --with-curl --with-iconv --with-pcre-regex --with-zlib --enable-bcmath --enable-ftp --enable-sockets --enable-mbstring --enable-mbregex --enable-soap --with-xsl --with-openssl --enable-opcache --with-mysqli --with-mysql-sock --with-pdo-mysql --enable-mysqlnd --disable-fileinfo --with-gd=/usr/local/gd --enable-gd-jis-conv --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/png --with-freetype-dir=/usr/local/freetype --with-libzip=/usr/local/lib64 --enable-zip --with-iconv-dir=/usr/local/lib --with-readline --with-apxs2=/usr/local/apache2/bin/apxs LDFLAGS="-L/usr/lib -lz"
make ZEND_EXTRA_LIBS='-liconv'
make install

Nginx 服务器环境:

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --disable-debug --with-curl --with-iconv --with-pcre-regex --with-zlib --enable-bcmath --enable-ftp --enable-sockets --enable-mbstring --enable-mbregex --enable-soap --with-xsl --with-openssl --enable-opcache --with-mysqli --with-mysql-sock --with-pdo-mysql --enable-mysqlnd --disable-fileinfo --with-gd=/usr/local/gd --enable-gd-jis-conv --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/png --with-freetype-dir=/usr/local/freetype --with-libzip=/usr/local/lib64 --enable-zip --with-iconv-dir=/usr/local/lib --with-readline LDFLAGS="-L/usr/lib -lz"
make ZEND_EXTRA_LIBS='-liconv'
make install

运行:

libtool --finish /root/php-7.3.23/libs

添加/usr/local/php/lib/php to your php.ini include_path:

/root/php-7.3.23/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin
ln -s -f phar.phar /usr/local/php/bin/phar

编译安装完成。

创建软连接:

ln -s /usr/local/php/bin/php /usr/local/bin/
ln -s /usr/local/php/bin/phpize /usr/local/bin/
ln -s /usr/local/php/bin/php-config /usr/local/bin/

php 配置文件:

cp /root/php-7.3.23/php.ini-production /usr/local/php/etc/php.ini

php-fpm 配置文件:

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

查看版本:

php -v

输出:

PHP 7.3.23 (cli) (built: Dec 20 2018 03:48:25) ( ZTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.0-dev, Copyright (c) 1998-2018 Zend Technologies

重启Apache:

service httpd stop
service httpd start

Apache正常启动。

【排错】

报错:off_t undefined; check your library configuration

参考:http://bubuko.com/infodetail-3015374.html
参考:https://stackoverflow.com/questions/44941513/php-compile-off-t-undefined
参考:https://stackoverflow.com/questions/44941513/php-compile-off-t-undefined
参考:http://ju.outofmemory.cn/entry/319609

off_t 类型是在 头文件 unistd.h中定义的,在32位系统 编程成 long int ,64位系统则编译成 long long int 。
在进行编译的时候 是默认查找64位的动态链接库,但是默认情况下 centos 的动态链接库配置文件/etc/ld.so.conf里并没有加入搜索路径,这个时候需要将 /usr/local/lib64 /usr/lib64 这些针对64位的库文件路径加进去。

echo '/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64'>>/etc/ld.so.conf&&ldconfig -v

报错:gd.so: undefined symbol: gdImageCreateFromGdCtx

编译PHP时先不用指定 libgd,删除 –with-gd=/usr/local/gd ;然后等安装PHP完成后通过安装PHP的扩展模式安装:

参考:https://amon.org/php-gd

如果make 时报错:undefined reference to symbol ‘ber_scanf’

参考:http://www.oschina.net/question/56833_128548?sort=time

/usr/bin/ld: ext/ldap/.libs/ldap.o: undefined reference to symbol 'ber_scanf'
/usr/bin/ld: note: 'ber_scanf' is defined in DSO /lib64/liblber-2.4.so.2 so try adding it to the linker command line
/lib64/liblber-2.4.so.2: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status
make: *** [sapi/cli/php] Error 1

编辑MakeFile,找到 117行 开头是 ‘EXTRA_LIBS’ 这一行 在结尾加上 ‘-llber’ :

EXTRA_LIBS = ... -llber

重新make(注意不能make clean,因为这样的话MakeFile会还原),输出:

...
Build complete.
Don't forget to run 'make test'

报错:configure: error: Unable to detect ICU prefix or no failed. Please verify ICU install prefix and make sure icu-config works.

yum install libicu-devel

参考:https://amon.org/icu

报错:configure: error: Cannot find ldap libraries in /usr/lib.

cp -frp /usr/lib64/libldap* /usr/lib/

报错:checking for libzip… not found

yum install libzip libzip-devel

报错:checking for libzip… configure: error: system libzip must be upgraded to version >= 0.11

参考:https://amon.org/libzip

ln -s -f /usr/include/zipconf.h /usr/local/include/zipconf.h

报错:cannot find -liconv

make 时报错:cannot find -liconv

参考:https://amon.org/libiconv

报错:/root/php-7.3.23/ext/curl/multi.c:512: undefined reference to `curl_pushheader_bynum’

make 时报错,可能因为 cURL升级导致。

参考:https://www.oschina.net/question/248756_2247202

yum remove curl-devel

然鹅启动httpd报错。

参考:https://curl.haxx.se/changes.html

Fixed in 7.44.0 – August 12 2015
Changes:
http2: added curl_pushheader_byname() and curl_pushheader_bynum()

可以考虑将curl升级到7.43.0?然鹅那个和http2关联啊。

所以问题的症结是,当初就别编译升级curl。