编辑 最后修改时间 2023/07/21 14:00
php8.1.1编译安装
https://www.php.net/downloads.php
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 --enable-fpm --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
Can't locate IPC/Cmd.pm in @INC (@INC contains:
// 报错原因:缺少IPC/Cmd.pm模块
// 安装perl-CPAN
$ yum install -y perl-CPAN
// 进入CPAN的shell模式,首次进入需要配置shell,按照提示操作即可(本人perl小白,全部选择默认配置,高手请根据提示自行选择)
$ perl -MCPAN -e shell
// 在shell中安装缺少的模块
$ install IPC/Cmd.pm
#安装成功后,重新编译OpenSSL即可
configure: error: No supported shared memory caching support was found when configuring opcache. Check config.log for any errors or missing dependencies.
https://stackoverflow.com/questions/67550602/no-supported-shared-memory-caching-support-was-found-when-configuring-opcache
// 禁用 OPCache 模块 扩展可以绕开此问题,具体原因未知.
$ ./configure --disable-opcache
/root/php-8.1.9/sapi/cli/php: error while loading shared libraries: libssl.so.3: cannot open shared object file: No such file or directory
make: *** [ext/phar/phar.php] 错误 127
$ ln -s /usr/local/openssl-3.0.1/lib64/lib* /usr/lib64/
windows:PHP Warning: 'C:\WINDOWS\SYSTEM32\VCRUNTIME140.dll' 14.0 is not compatible with this PHP build linked with 14.29 in Unknown on line 0
修复 vcruntime140.dll 错误
下载并安装 Microsoft Visual C++ Redistributable for Visual Studio
![]()