PHP安装
安装PHP7.4.33
系统:CentOS Linux release 7.9.2009 (Core),内核:3.10.0-1127.el7.x86_64
安装过程
1. 通过源码包编译安装, 先下载php-7.4.33
2. 通过yum提前处理各项依赖:
[root@2207013 ~]# yum install -y gcc gcc-c++ epel-release make zlib-devel libxml2-devel libjpeg-devel libpng-devel libwebp-devel \
libXpm-devel freetype-devel libmcrypt-devel openssl-devel libcurl-devel libzip-devel libxslt-devel perl-ExtUtils-MakeMaker autoconf \
sqlite-devel libicu-devel cmake3 automake libtool
可以把yum源修改成国内的镜像地址,参考这篇的小建议。
3. 进行安装
[root@2207013 data]# tar -zxvf php-7.4.33.tar.gz
[root@2207013 data]# cd php-7.4.33
[root@2207013 php-7.4.33]# groupadd www
[root@2207013 php-7.4.33]# useradd -g www -M -s /sbin/nologin www # 创建一个不能登录,但可以执行一些系统命令和程序的www用户。如果设置的是/bin/false,表示www用户不能登录系统,也不能执行任何命令和程序
[root@2207013 php-7.4.33]# ./configure --prefix=/usr/local/php-7.4.33 --with-config-file-path=/usr/local/php-7.4.33/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www \
--with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-gd --with-jpeg --with-webp --with-xpm --with-freetype --with-openssl --with-curl --with-zip --with-xsl --enable-sockets \
--enable-mbstring --with-zip --with-zlib --enable-bcmath --enable-opcache --with-gettext --enable-maintainer-zts --enable-xml --with-libxml --enable-xmlreader --enable-xmlwriter \
--enable-mysqlnd --enable-pcntl --enable-mbregex --enable-intl --with-tsrm-pthreads --with-pic --enable-exif --with-external-pcre
[root@2207013 php-7.4.33]# make && make install
执行configure脚本的个别参数说明,--enable-fpm:启用 PHP-FPM(FastCGI Process Manager)模式,用于php-fpm进程管理,如nginx作为web服务器,配置的fastcgi_pass 127.0.0.1:9000,这里的9000端口通常对应的就是php-fpm进程;--with-zlib:启用 zlib 扩展,该扩展提供了对 zlib 数据压缩和解压缩的支持,通常composer场景需要用到zlib库;--with-openssl:启用 OpenSSL 扩展,该扩展提供了对 OpenSSL 加密和解密功能的支持。通常https场景用到;--enable-pcntl:启用PCNTL扩展,这个扩展允许 PHP 脚本创建子进程、向进程发送信号以及处理进程退出等操作,用于多进程场景。
执行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.
则表示通过环境检查,可以执行make进行编译。
否则要处理提示的错误。
错误处理
执行configure脚本报错处理:
- configure: error: Package requirements (oniguruma) were not met:
No package 'oniguruma' found
[root@2207013 data]# wget https://github.com/kkos/oniguruma/releases/download/v6.9.7/onig-6.9.7.tar.gz
[root@2207013 data]# tar -zxvf onig-6.9.7.tar.gz
[root@2207013 data]# cd onig-6.9.7
[root@2207013 onig-6.9.7]# ./configure
[root@2207013 onig-6.9.7]# make && make install # 注意它安装到哪个目录,这里安装到了/usr/local/lib下
[root@2207013 onig-6.9.7]# export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
[root@2207013 onig-6.9.7]# pkg-config --modversion oniguruma # 此时可查看安装的oniguruma版本
[root@2207013 onig-6.9.7]# pkg-config --variable pcfiledir oniguruma # 查看安装的oniguruma位置
- checking for libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0... no
configure: error: Package requirements (libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0) were not met:
Requested 'libzip >= 0.11' but version of libzip is 0.10.1
[root@2207013 data]# wget https://libzip.org/download/libzip-1.7.3.tar.gz
[root@2207013 data]# tar -zxvf libzip-1.7.3.tar.gz
[root@2207013 data]# cd libzip-1.7.3
[root@2207013 libzip-1.7.3]# mkdir build
[root@2207013 libzip-1.7.3]# cd build
[root@2207013 build]# cmake3 ..
[root@2207013 build]# make && make install
[root@2207013 build]# export PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:$PKG_CONFIG_PATH
[root@2207013 build]# pkg-config --modversion libzip # 查看libzip版本
- configure: error: Package requirements (libpcre2-8 >= 10.30) were not met:
No package 'libpcre2-8' found
[root@2207013 data]# wget https://github.com/PCRE2Project/pcre2/archive/refs/tags/pcre2-10.33.tar.gz
[root@2207013 data]# tar -zxvf pcre2-pcre2-10.33.tar.gz
[root@2207013 data]# cd pcre2-pcre2-10.33
[root@2207013 pcre2-pcre2-10.33]# ./autogen.sh # 执行这个脚本才会出现configure脚本
[root@2207013 pcre2-pcre2-10.33]# ./configure
[root@2207013 pcre2-pcre2-10.33]# make && make install # 也要注意它安装到哪个目录,这里安装到了/usr/local/lib下
[root@2207013 pcre2-pcre2-10.33]# export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
[root@2207013 pcre2-pcre2-10.33]# pkg-config --modversion libpcre2-8
本文作者:笑笑霸
本文链接:https://www.cnblogs.com/xiaoxiaobug/p/17254741.html
期待你的关注、收藏、评论,欢迎转载,请指明原文链接
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步