编译安装php
- 准备编译环境
yum -y install gcc gcc-c++ make autoconf bzip2 bzip2-devel libpng libpng-devel freetype-devel gmp-devel readline-devel curl-devel libxml2-devel libjpeg-devel bison openssl-devel uw-imap-devel libc-client sqlite-devel libicu-devel libedit-devel libxslt-devel oniguruma oniguruma-devel libzip-devel
- 下载源码包
wget https://www.php.net/distributions/php-8.0.0.tar.xz
- 配置并构建 PHP。在此步骤您可以使用很多选项自定义 PHP,例如启用某些扩展等。 运行 ./configure –help 命令来获得完整的可用选项清单。 在本示例中,我们仅进行包含 PHP-FPM 和 MySQL 支持的简单配置。
./configure --prefix=/usr/local/php \ --sysconfdir=/etc/php \ --with-config-file-path=/etc/php \ --with-config-file-scan-dir=/etc/php/php.d \ --bindir=/usr/bin \ --docdir=/usr/share/doc \ --sbindir=/usr/sbin \ --libdir=/usr/lib64/php \ --with-libdir=/usr/lib64/php \ --libexecdir=/usr/libexec \ --localstatedir=/var \ --includedir=/usr/include \ --localedir=/usr/local \ --datarootdir=/usr/share \ --datadir=/usr/share/php \ --mandir=/usr/share/man \ --infodir=/usr/share/info \ --enable-fpm \ --with-fpm-user=www-data \ --with-fpm-group=www-data \ --enable-mysqlnd \ --enable-mysqlnd-compression-support \ --enable-json \ --with-openssl-dir \ --with-zlib-dir \ --with-freetype \ --enable-gd-jis-conv \ --enable-ftp \ --enable-filter \ --enable-fileinfo \ --with-curl \ --with-iconv \ --with-bz2 \ --with-zlib \ --with-zip \ --with-xsl \ --with-jpeg \ --with-webp \ --with-xpm \ --without-iconv \ --with-kerberos \ --with-imap-ssl \ --with-openssl \ --enable-dom \ --with-gettext \ --with-mysqli=mysqlnd \ --enable-pdo \ --with-pdo-mysql=mysqlnd \ --enable-simplexml \ --enable-session \ --enable-sysvsem \ --enable-sysvmsg \ --enable-sockets \ --with-pear \ --with-xmlrpc \ --with-mhash \ --enable-bcmath \ --with-cdb \ --enable-exif \ --with-gmp \ --enable-mbstring \ --enable-mbregex \ --with-readline \ --enable-shmop \ --enable-soap \ --enable-sockets \ --enable-pcntl \ --enable-intl \ --enable-re2c-cgoto \ --with-libedit
- 创建配置文件,并将其复制到正确的位置。
cp php.ini-production /etc/php/php.ini cp sapi/fpm/php-fpm.conf /etc/php/php-fpm.conf cp sapi/fpm/www.conf /etc/php/php-fpm.d/www.conf cp sapi/fpm/php-fpm.service /etc/systemd/system/php-fpm.service
- 需要着重提醒的是,如果文件不存在,则阻止 Nginx 将请求发送到后端的 PHP-FPM 模块, 以避免遭受恶意脚本注入的攻击。
将 php.ini 文件中的配置项 cgi.fix_pathinfo 设置为 0 。
cgi.fix_pathinfo=0
groupadd www-data useradd --group www-data -s /sbin/nologin --no-create-home www-data
systemctl start php-fpm
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律