rocky linux: 编译安装php 8.2.5(Rocky Linux 9.1)
一,官网地址:
https://www.php.net/
如图:
二,下载并解压:
下载:
[root@img php]# wget https://www.php.net/distributions/php-8.2.5.tar.gz
解压:
[root@img php]# tar -zxvf php-8.2.5.tar.gz
说明:刘宏缔的架构森林是一个专注架构的博客,
网站:https://blog.imgtouch.com
原文: https://blog.imgtouch.com/index.php/2023/06/06/rocky-linux-bian-yi-an-zhuang-php-8-2-5-rocky-linux-9-1/
对应的源码可以访问这里获取: https://github.com/liuhongdi/
或: https://gitee.com/liuhongdi
说明:作者:刘宏缔 邮箱: 371125307@qq.com
三,配置/编译/安装:
1,configure
[root@img php]# cd php-8.2.5/
[root@img php-8.2.5]# ./configure --prefix=/usr/local/soft/php8.2.5 --with-config-file-path=/usr/local/soft/php8.2.5/etc
--with-curl --with-freetype --enable-gd --with-jpeg --with-gettext --with-kerberos --with-libdir=lib64
--with-libxml --with-mysqli --with-openssl --with-pdo-mysql --with-pdo-sqlite --with-pear --enable-sockets
--with-mhash --with-ldap-sasl --with-xsl --with-zlib --with-zip -with-bz2 --with-iconv --enable-fpm
--enable-pdo --enable-bcmath --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl
--enable-shmop --enable-soap --enable-ftp --with-xpm --enable-xml --enable-sysvsem --enable-cli --enable-intl
--enable-calendar --enable-static --enable-ctype --enable-mysqlnd --enable-session
configure成功后的提示
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
Thank you for using PHP.
编译
[root@img php]# make
安装:
[root@img php]# make install
四,报错及解决:
1,报错:
configure: error: Package requirements (libxml-2.0 >= 2.9.0) were not met:
Package 'libxml-2.0', required by 'virtual:world', not found
解决:
[root@img php-8.2.5]# dnf install libxml2-devel
2,报错:
configure: error: Package requirements (krb5-gssapi krb5) were not met:
Package 'krb5-gssapi', required by 'virtual:world', not found
Package 'krb5', required by 'virtual:world', not found
解决:
[root@img php-8.2.5]# dnf install krb5-devel
3,报错:
configure: error: Package requirements (sqlite3 >= 3.7.7) were not met:
Package 'sqlite3', required by 'virtual:world', not found
解决:
[root@img php-8.2.5]# dnf install sqlite-devel
4,报错:
checking for BZip2 in default path... not found
configure: error: Please reinstall the BZip2 distribution
解决:
[root@img php-8.2.5]# dnf install bzip2-devel
5,报错:
configure: error: Package requirements (libcurl >= 7.29.0) were not met:
Package 'libcurl', required by 'virtual:world', not found
解决:
[root@img php-8.2.5]# dnf install libcurl-devel
6,报错:
configure: error: Package requirements (libpng) were not met:
Package 'libpng', required by 'virtual:world', not found
解决:
[root@img php-8.2.5]# dnf install libpng-devel
7,报错:
configure: error: Package requirements (libjpeg) were not met:
Package 'libjpeg', required by 'virtual:world', not found
解决:
[root@img php-8.2.5]# dnf install libjpeg-devel
8,报错:
configure: error: Package requirements (xpm) were not met:
Package 'xpm', required by 'virtual:world', not found
解决:
[root@img php-8.2.5]# dnf install libXpm-devel
9,报错:
configure: error: Package requirements (freetype2) were not met:
Package 'freetype2', required by 'virtual:world', not found
解决:
[root@img php-8.2.5]# dnf install freetype-devel
10,报错:
configure: error: in `/usr/local/source/php/php-8.2.5':
configure: error: C++ preprocessor "/lib/cpp" fails sanity check
解决:
[root@img php-8.2.5]# dnf install glibc-headers gcc-c++
11,报错:
configure: error: Package requirements (oniguruma) were not met:
Package 'oniguruma', required by 'virtual:world', not found
解决:
[root@img php-8.2.5]# rpm -ivh https://rpms.remirepo.net/enterprise/9/remi/x86_64/oniguruma5php-devel-6.9.7.1-1.el9.remi.x86_64.rpm
Retrieving https://rpms.remirepo.net/enterprise/9/remi/x86_64/oniguruma5php-devel-6.9.7.1-1.el9.remi.x86_64.rpm
warning: /var/tmp/rpm-tmp.GMG1ln: Header V4 RSA/SHA256 Signature, key ID 478f8947: NOKEY
error: Failed dependencies:
libonig.so.105()(64bit) is needed by oniguruma5php-devel-6.9.7.1-1.el9.remi.x86_64
oniguruma5php = 6.9.7.1-1.el9.remi is needed by oniguruma5php-devel-6.9.7.1-1.el9.remi.x86_64
[root@img php-8.2.5]# rpm -ivh https://rpms.remirepo.net/enterprise/9/remi/x86_64/oniguruma5php-6.9.7.1-1.el9.remi.x86_64.rpm
Retrieving https://rpms.remirepo.net/enterprise/9/remi/x86_64/oniguruma5php-6.9.7.1-1.el9.remi.x86_64.rpm
warning: /var/tmp/rpm-tmp.ok00BI: Header V4 RSA/SHA256 Signature, key ID 478f8947: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:oniguruma5php-6.9.7.1-1.el9.remi ################################# [100%]
[root@img php-8.2.5]# rpm -ivh https://rpms.remirepo.net/enterprise/9/remi/x86_64/oniguruma5php-devel-6.9.7.1-1.el9.remi.x86_64.rpm
Retrieving https://rpms.remirepo.net/enterprise/9/remi/x86_64/oniguruma5php-devel-6.9.7.1-1.el9.remi.x86_64.rpm
warning: /var/tmp/rpm-tmp.np3ytb: Header V4 RSA/SHA256 Signature, key ID 478f8947: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:oniguruma5php-devel-6.9.7.1-1.el9################################# [100%]
12,报错:
configure: error: Package requirements (libxslt >= 1.1.0) were not met:
Package 'libxslt', required by 'virtual:world', not found
解决:
[root@img php-8.2.5]# dnf install libxslt-devel
13,报错:
configure: error: Package requirements (libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0) were not met:
Package 'libzip', required by 'virtual:world', not found
Package 'libzip', required by 'virtual:world', not found
Package 'libzip', required by 'virtual:world', not found
解决:
[root@img php-8.2.5]# yum install libzip-devel
五,生成配置文件:
1,用源码目录下的php.ini-production生成配置文件
[root@img php-8.2.5]# cp php.ini-production /usr/local/soft/php8.2.5/etc/php.ini
2, 生成www.conf
[root@img php-8.2.5]# cd /usr/local/soft/php8.2.5/etc/php-fpm.d/
[root@img php-fpm.d]# cp www.conf.default www.conf
3, 生成php-fpm配置文件
[root@img php-fpm.d]# cd /usr/local/soft/php8.2.5/etc/
[root@img etc]# cp php-fpm.conf.default php-fpm.conf
六,用systemctl管理php-fpm服务
1,配置pid文件路径:
[root@img etc]# vi php-fpm.conf
增加如下一行:
;pid = run/php-fpm.pid
pid = /var/run/php-fpm.pid
2,生成service文件
[root@img etc]# vi /usr/lib/systemd/system/php-fpm.service
文件内容:
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=forking
PIDFile=/var/run/php-fpm.pid
ExecStart=/usr/local/soft/php8.2.5/sbin/php-fpm
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
重新加载服务文件
[root@img etc]# systemctl daemon-reload
启动服务
[root@img etc]# systemctl start php-fpm.service
查看进程:
七,查看已安装php的版本:
[root@img php-fpm.d]# /usr/local/soft/php8.2.5/bin/php --version
PHP 8.2.5 (cli) (built: May 10 2023 14:51:39) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.5, Copyright (c) Zend Technologies
八,查看linux的版本:
[root@blog ~]# cat /etc/redhat-release
Rocky Linux release 9.1 (Blue Onyx)