php8.1.1编译安装

PHP各版本下载地址https://www.php.net/downloads.php

PHP8.1.1下载地址https://www.php.net/distributions/php-8.1.1.tar.gz

安装

wget https://www.php.net/distributions/php-8.1.1.tar.gz
tar -zxvf ./php-8.1.1.tar.gz
cd php-8.1.1
# 编译
./configure --prefix=/usr/local/php81 --with-config-file-path=/usr/local/php81/etc --with-config-file-scan-dir=/usr/local/php81/conf.d --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv=/usr/local --with-freetype=/usr/local/freetype --with-jpeg --with-zlib --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --with-curl --enable-mbregex --enable-mbstring --enable-intl --enable-pcntl --enable-ftp --enable-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-zip --enable-soap --with-gettext --enable-opcache --with-xsl --with-pear

make
sudo make install

# 配置
sudo mkdir -p /usr/local/php81/{etc,conf.d}
sudo cp ./php.ini-production /usr/local/php81/etc/php.ini
sudo sed -i 's/post_max_size =.*/post_max_size = 50M/g' /usr/local/php81/etc/php.ini
sudo sed -i 's/upload_max_filesize =.*/upload_max_filesize = 50M/g' /usr/local/php81/etc/php.ini
sudo sed -i 's/;date.timezone =.*/date.timezone = PRC/g' /usr/local/php81/etc/php.ini
sudo sed -i 's/short_open_tag =.*/short_open_tag = On/g' /usr/local/php81/etc/php.ini
sudo sed -i 's/;cgi.fix_pathinfo=.*/cgi.fix_pathinfo=0/g' /usr/local/php81/etc/php.ini
sudo sed -i 's/max_execution_time =.*/max_execution_time = 300/g' /usr/local/php81/etc/php.ini
sudo sed -i 's/disable_functions =.*/disable_functions = passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server/g' /usr/local/php81/etc/php.ini
sudo /usr/local/php81/bin/pear config-set php_ini /usr/local/php81/etc/php.ini
sudo /usr/local/php81/bin/pecl config-set php_ini /usr/local/php81/etc/php.ini

cat >/usr/local/php81/etc/php-fpm.conf<<EOF
[global]
pid = /usr/local/php81/var/run/php-fpm.pid
error_log = /usr/local/php81/var/log/php-fpm.log
log_level = notice

[www]
listen = /tmp/php-cgi-81.sock
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 10
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 6
pm.max_requests = 1024
pm.process_idle_timeout = 10s
request_terminate_timeout = 100
request_slowlog_timeout = 0
slowlog = var/log/slow.log
EOF

# 搞定
sudo ln -s /usr/local/php81/bin/php /usr/bin/php81
php81 -v
PHP 8.1.1 (cli) (built: Dec 28 2021 12:01:25) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.1, Copyright (c) Zend Technologies
configure: error: Package requirements (libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0) were not met:

#下载源一.访问 https://soft.vpser.net 按照目录层级选择 libzip-1.3.2.tar.xz 下载即可
wget http://175.6.32.4:88/soft/lib/libzip/libzip-1.3.2.tar.xz

# 下载源二
wget https://libzip.org/download/libzip-1.8.0.tar.xz

#解压 & 编译及安装
tar xJf libzip-1.3.2.tar.xz
cd libzip-1.3.2/
./configure --prefix=/usr/local/libzip-1.3.2
make
sudo make install
export PKG_CONFIG_PATH='/usr/local/libzip-1.3.2/lib/pkgconfig'

#指定参数 --with-zip=/usr/local/libzip-1.3.2 ,重新configure
configure: error: iconv does not support errno
# 安装 libiconv-1.16
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.16.tar.gz
tar -zxvf libiconv-1.16.tar.gz
./configure --prefix=/usr/local/libiconv
make
sudo make install

# 添加 --with-iconv=/usr/local/libiconv 编译参数,重新 configure
collect2: error: ld returned 1 exit status

make: * [sapi/cli/php] 错误 1
# 此问题原因比较多,具体情况需要具体分析,下面是本次案例思路
ext/openssl/openssl.o: In function `zm_startup_openssl':
/data/install/php-8.1.1/ext/openssl/openssl.c:1161: undefined reference to `OPENSSL_init_ssl'
ext/openssl/openssl.o: In function `php_openssl_asn1_time_to_time_t':
/data/install/php-8.1.1/ext/openssl/openssl.c:639: undefined reference to `ASN1_STRING_get0_data'
/data/install/php-8.1.1/ext/openssl/openssl.c:654: undefined reference to `ASN1_STRING_get0_data'
/data/install/php-8.1.1/ext/openssl/openssl.c:654: undefined reference to `ASN1_STRING_get0_data'
...
/data/install/php-8.1.1/ext/openssl/xp_ssl.c:422: undefined reference to `OPENSSL_sk_num'
/data/install/php-8.1.1/ext/openssl/xp_ssl.c:425: undefined reference to `OPENSSL_sk_value'
/data/install/php-8.1.1/ext/openssl/xp_ssl.c:457: undefined reference to `OPENSSL_sk_pop_free'
/data/install/php-8.1.1/ext/openssl/xp_ssl.c:469: undefined reference to `OPENSSL_sk_pop_free'
/data/install/php-8.1.1/ext/openssl/xp_ssl.c:443: undefined reference to `OPENSSL_sk_pop_free'
ext/ftp/ftp.o: In function `ftp_login':
/data/install/php-8.1.1/ext/ftp/ftp.c:271: undefined reference to `TLS_client_method'
/data/install/php-8.1.1/ext/ftp/ftp.c:280: undefined reference to `SSL_CTX_set_options'
collect2: error: ld returned 1 exit status
make: *** [sapi/cli/php] 错误 1

# OpenSSL版本太低,升级OpenSSL,这里我直接把它升级为最新版本
wget https://www.openssl.org/source/openssl-3.0.1.tar.gz
tar -zxf openssl-3.0.1.tar.gz
cd openssl-3.0.1/
./config -fPIC --prefix=/usr/local/openssl-3.0.1 --openssldir=/usr/local/openssl-3.0.1
make depend
make install
# 重新编译
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/openssl-3.0.1/lib64/pkgconfig
# 添加 --with-openssl-dir=/usr/local/openssl-3.0.1/bin 编译参数,重新 configure

评论

暂无评论