天天看点

CentOS_7.9_x64编译安装php_8.1.12

1.安装系统包

# yum install -y gcc gcc-c++ autoconf libtool bzip2 bzip-devel make python3 python3-devel
           

2.安装扩展依赖包

2.1 安装Openssl-1.1.1s

下载地址:https://www.openssl.org/source/openssl-1.1.1s.tar.gz

# tar zxvf openssl-1.1.1s.tar.gz
# cd openssl-1.1.1s
# ./config --prefix=/usr/local/openssl
# make
# make install
# cd ..

# openssl version
OpenSSL 1.0.2k-fips  26 Jan 2017

# mv /usr/bin/openssl /usr/bin/openssl.bak
# ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
# echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
# echo "/usr/local/lib64" >> /etc/ld.so.conf
# echo "/usr/local/lib" >> /etc/ld.so.conf
# ldconfig -v

# openssl version 
OpenSSL 1.1.1s  1 Nov 2022

           

2.2 安装perl-5.36.0

下载地址:https://www.cpan.org/src/5.0/perl-5.36.0.tar.gz

# tar zxvf perl-5.36.0.tar.gz
# cd perl-5.36.0
# ./Configure -des -Dprefix=/usr/local/perl
# make
# make install
# cd ..

# perl -v
This is perl 5, version 16, subversion 3 (v5.16.3) built for x86_64-linux-thread-multi
(with 44 registered patches, see perl -V for more detail)

Copyright 1987-2012, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

# mv /usr/bin/perl /usr/bin/perl.bak
# ln -s /usr/local/perl/bin/perl /usr/bin/perl
# perl -v
This is perl 5, version 36, subversion 0 (v5.36.0) built for x86_64-linux

Copyright 1987-2022, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at https://www.perl.org/, the Perl Home Page.
           

2.3 安装zlib-1.2.13

下载地址:http://www.zlib.net/zlib-1.2.13.tar.gz

# tar zxvf zlib-1.2.13.tar.gz 
# cd zlib-1.2.13
# ./configure --enable-shared
# make
# make install
           

2.4 安装libpng-1.6.39

下载:https://nchc.dl.sourceforge.net/project/libpng/libpng16/1.6.39/libpng-1.6.39.tar.gz

# tar zxvf libpng-1.6.39.tar.gz
# cd libpng-1.6.39
# ./configure --prefix=/usr/local/libpng --enable-shared
# make
# make install
           

2.5 安装jpeg-v9e

下载地址:http://www.ijg.org/files/jpegsrc.v9e.tar.gz

# tar zxvf jpegsrc.v9e.tar.gz
# cd jpeg-9e
# ./configure --prefix=/usr/local/jpeg-9e --enable-shared
# make 
# make install
# cd ..
           

2.6 安装xz-5.4.1

下载:https://nchc.dl.sourceforge.net/project/lzmautils/xz-5.4.1.tar.gz

# tar zxvf xz-5.4.1.tar.gz
# cd xz-5.4.1
# ./configure --prefix=/usr/local/xz --enable-shared
# make
# make install
# cd ..
           

2.7 安装libxml2-2.9.12

下载:http://xmlsoft.org/sources/libxml2-2.9.12.tar.gz

# tar zxvf libxml2-2.9.12.tar.gz
# cd libxml2-2.9.12
# ./configure --prefix=/usr/local/libxml2 --with-zlib --with-lzma=/usr/local/zx
# make
# make install
# cd ..
           

2.8 安装libxslt-1.1.34

下载: http://xmlsoft.org/sources/libxslt-1.1.34.tar.gz

# tar zxvf libxslt-1.1.34.tar.gz 
# cd libxslt-1.1.34
# ./configure LD_LIBRARY_PATH=/usr/local/libxml2/lib PKG_CONFIG_PATH=/usr/local/libxml2/lib/pkgconfig --prefix=/usr/local/libxslt

# make 
# make install
# cd ..
           

2.9 安装freetype-2.12.1

下载:http://ftp.twaren.net/Unix/NonGNU/freetype/freetype-2.12.1.tar.gz

https://freedesktop.org/software/fontconfig/release/fontconfig-2.14.2.tar.gz

https://github.com/libgd/libgd/releases/download/gd-2.3.3/libgd-2.3.3.tar.gz

http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.17.tar.gz

https://github.com/curl/curl/releases/download/curl-7_83_1/curl-7.83.1.tar.gz

https://github.com/libexpat/libexpat/releases/download/R_2_4_9/expat-2.4.9.tar.gz

https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/o/oniguruma-6.8.2-2.el7.x86_64.rpm

https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/o/oniguruma-devel-6.8.2-2.el7.x86_64.rpm

3. 安装Php-8.1.12

# yum -y install gcc gcc-c++ autoconf libtool perl-devel libpng-devel libjpeg-devel libcurl-devel openldap-devel  freetype-devel libxml2-devel sqlite-devel zlib-devel curl-devel pcre-devel gd-devel expat-devel libicu-devel bzip2 bzip2-devel python3 python3-devel libiconv libiconv-devel libwebp-devel

# rpm -ivh oniguruma-6.8.2-2.el7.x86_64.rpm
# rpm -ivh oniguruma-devel-6.8.2-2.el7.x86_64.rpm
# yum install epel-release
# yum install -y libzstd-devel


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

# groupadd nginx
# useradd -g nginx nginx -s /sbin/nologin -M

# tar zxvf php-8.1.12.tar.gz
# cd php-8.1.12
# ./configure --prefix=/usr/local/php8.1 --with-config-file-path=/usr/local/php8.1/etc  --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx  --with-openssl --with-mysqli --with-pdo-mysql --enable-mysqlnd --enable-mysqlnd-compression-support --enable-gd --enable-gd-jis-conv --with-freetype --with-jpeg --with-xpm --with-webp --with-zlib --with-zip --with-bz2 --with-libxml --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --with-curl --with-iconv --enable-mbregex --enable-mbstring --enable-intl --enable-ftp --with-mhash --enable-pcntl --enable-opcache --enable-sockets --enable-soap --with-gettext --disable-fileinfo --disable-rpath --enable-debug --with-pear --with-ldap --with-expat --enable-phpdbg --enable-php-debug
# make

..............

Generating phar.php
Generating phar.phar
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
directorytreeiterator.inc
clicommand.inc
directorygraphiterator.inc
phar.inc
invertedregexiterator.inc
pharcommand.inc

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

# make install

Installing shared extensions:     /usr/local/php8.1/lib/php/extensions/debug-non-zts-20210902/
Installing PHP CLI binary:        /usr/local/php8.1/bin/
Installing PHP CLI man page:      /usr/local/php8.1/php/man/man1/
Installing PHP FPM binary:        /usr/local/php8.1/sbin/
Installing PHP FPM defconfig:     /usr/local/php8.1/etc/
Installing PHP FPM man page:      /usr/local/php8.1/php/man/man8/
Installing PHP FPM status page:   /usr/local/php8.1/php/php/fpm/
Installing phpdbg binary:         /usr/local/php8.1/bin/
Installing phpdbg man page:       /usr/local/php8.1/php/man/man1/
Installing PHP CGI binary:        /usr/local/php8.1/bin/
Installing PHP CGI man page:      /usr/local/php8.1/php/man/man1/
Installing build environment:     /usr/local/php8.1/lib/php/build/
Installing header files:          /usr/local/php8.1/include/php/
Installing helper programs:       /usr/local/php8.1/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/php8.1/php/man/man1/
  page: phpize.1
  page: php-config.1
Installing PEAR environment:      /usr/local/php8.1/lib/php/
[PEAR] Archive_Tar    - installed: 1.4.14
[PEAR] Console_Getopt - installed: 1.4.3
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util       - installed: 1.4.5
warning: pear/PEAR dependency package "pear/Archive_Tar" installed version 1.4.14 is not the recommended version 1.4.4
[PEAR] PEAR           - installed: 1.10.13
Wrote PEAR system config file at: /usr/local/php8.1/etc/pear.conf
You may want to add: /usr/local/php8.1/lib/php to your php.ini include_path
/usr/local/src/php-8.1.12/build/shtool install -c ext/phar/phar.phar /usr/local/php8.1/bin/phar.phar
ln -s -f phar.phar /usr/local/php8.1/bin/phar
Installing PDO headers:           /usr/local/php8.1/include/php/ext/pdo/

# cp php.ini-development /usr/local/php8.1/etc/php.ini
# cd /usr/local/php8.1/etc/
# cp php-fpm.conf.default php-fpm.conf
# cd php-fpm.d/
# cp www.conf.default www.conf
# cd ../../sbin
# ./php-fpm
# ps -ef|grep php
root     101463      1  0 23:52 ?        00:00:00 php-fpm: master process (/usr/local/php8.1/etc/php-fpm.conf)
nginx    101464 101463  0 23:52 ?        00:00:00 php-fpm: pool www
nginx    101465 101463  0 23:52 ?        00:00:00 php-fpm: pool www
root     101467   1497  0 23:52 pts/0    00:00:00 grep --color=auto php
           

4.问题解决记录

4.1 安装libxml2,make时报错

libxml.c:15:20: 致命错误:Python.h:没有那个文件或目录

 #include <Python.h>

                    ^

编译中断。

make[4]: *** [libxml.lo] 错误 1

安装python3

# yum install -y python3 python3-devel
           

继续make 通过

遇到错误
/usr/bin/ld: ext/ldap/.libs/ldap.o: undefined reference to symbol 'ber_strdup' 
//usr/lib64/liblber-2.4.so.2: error adding symbols: DSO missing from command line 
collect2: error: ld returned 1 exit status 
make: *** [sapi/cli/php] Error 1
解决方案:
在PHP源码目录下 vi Makefile 找到 EXTRA_LIBS 行,在行末添加 ‘ -llber ‘ 保存退出再次make即可