PHP8编译安装
- 创业
- 2025-07-22 19:36:01

CentOS8编译安装PHP8
PHP,全称Hypertext Preprocessor(超文本预处理器),是一种通用开源脚本语言。它特别适合于web开发,并能嵌入HTML中。现在主要用于PHP网站中实现动态网站功能,常规我们使用nginx、apache部署的是html静态网页,可以通过.php编写动态页面实现。
一、下载 # 创建文件夹用来安装phpmkdir /www/php80# 官网下载然后上传到服务器或者wget下载到对应文件夹wget https://www.php.net/distributions/php-8.1.7.tar.gz# 解压文件tar -zxvf php-8.1.7.tar.gz# 修改文件夹用户和组,防止没有权限执行chown -R root php-8.1.7chgrp -R root php-8.1.7cd php-8.1.7 二、安装配置 # 和nginx编译安装类似,使用.configure进行配置# --prefix:php.ini文件路径位置# --with-config-file-path : 配置文件./configure --prefix=/www/php8 --with-config-file-path=/www/php8/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-sockets --enable-sysvsem --enable-xml --enable-sysvsem --enable-cli --enable-opcache --enable-intl --enable-calendar --enable-static --enable-mysqlnd报错处理:
1.libxml
问题:Package 'libxml-2.0', required by 'virtual:world', not found解决方法:yum install libxml2-devel2.sqlite3
问题:Package 'sqlite3', required by 'virtual:world', not found解决方法:yum install sqlite-devel3.Bzip2
问题:configure: error: Please reinstall the BZip2 distribution解决方法:yum -y install bzip2-devel4.libcurl
问题:Package 'libcurl', required by 'virtual:world', not found解决方法:yum install libcurl-devel5.libpng
问题:Package 'libpng', required by 'virtual:world', not found解决方法:yum install libpng libpng-devel6.libjpeg
问题:Package 'libjpeg', required by 'virtual:world', not found解决方法:yum install libjpeg-devel7.freetype2
问题:Package 'freetype2', required by 'virtual:world', not found解决方法:yum install freetype-devel8.icu
问题:Package 'icu-uc', required by 'virtual:world', not foundPackage 'icu-io', required by 'virtual:world', not foundPackage 'icu-i18n', required by 'virtual:world', not found解决方法:yum install -y libicu-devel.x86_649.oniguruma
问题:Package 'oniguruma', required by 'virtual:world', not found解决方法:1.下载安装包wget https://github.com/kkos/oniguruma/archive/v6.9.4.tar.gz -O oniguruma-6.9.4.tar.gz 2.解压tar -zxvf oniguruma-6.9.4.tar.gz 3.进入文件夹进行编译安装cd oniguruma-6.9.44.安装依赖yum install autoconf automake libtool5.编译到/usr目录下./autogen.sh && ./configure --prefix=/usr6.安装make && make install10.libxslt
问题:Package 'libxslt', required by 'virtual:world', not found解决方法:yum -y install libxslt-devel11.libzip
问题:Package 'libzip', required by 'virtual:world', not foundPackage 'libzip', required by 'virtual:world', not foundPackage 'libzip', required by 'virtual:world', not found解决方法:yum install libzip-devel终于完成了,出现下面的提示:
Generating filesconfigure: patching main/php_config.h.inconfigure: creating ./config.statuscreating main/internal_functions.ccreating main/internal_functions_cli.cconfig.status: creating main/build-defs.hconfig.status: creating scripts/phpizeconfig.status: creating scripts/man1/phpize.1config.status: creating scripts/php-configconfig.status: creating scripts/man1/php-config.1config.status: creating sapi/cli/php.1config.status: creating sapi/fpm/php-fpm.confconfig.status: creating sapi/fpm/www.confconfig.status: creating sapi/fpm/init.d.php-fpmconfig.status: creating sapi/fpm/php-fpm.serviceconfig.status: creating sapi/fpm/php-fpm.8config.status: creating sapi/fpm/status.htmlconfig.status: creating sapi/phpdbg/phpdbg.1config.status: creating sapi/cgi/php-cgi.1config.status: creating ext/phar/phar.1config.status: creating ext/phar/phar.phar.1config.status: creating main/php_config.hconfig.status: executing default commands+--------------------------------------------------------------------+| 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 && make install完成:Don't forget to run 'make test'.Installing shared extensions: /www/php8/lib/php/extensions/no-debug-non-zts-20210902/Installing PHP CLI binary: /www/php8/bin/Installing PHP CLI man page: /www/php8/php/man/man1/Installing PHP FPM binary: /www/php8/sbin/Installing PHP FPM defconfig: /www/php8/etc/Installing PHP FPM man page: /www/php8/php/man/man8/Installing PHP FPM status page: /www/php8/php/php/fpm/Installing phpdbg binary: /www/php8/bin/Installing phpdbg man page: /www/php8/php/man/man1/Installing PHP CGI binary: /www/php8/bin/Installing PHP CGI man page: /www/php8/php/man/man1/Installing build environment: /www/php8/lib/php/build/Installing header files: /www/php8/include/php/Installing helper programs: /www/php8/bin/ program: phpize program: php-configInstalling man pages: /www/php8/php/man/man1/ page: phpize.1 page: php-config.1Installing PEAR environment: /www/php8/lib/php/[PEAR] Archive_Tar - installed: 1.4.14[PEAR] Console_Getopt - installed: 1.4.3[PEAR] Structures_Graph- installed: 1.1.1[PEAR] XML_Util - installed: 1.4.5warning: pear/PEAR dependency package "pear/Archive_Tar" installed version 1.4.14 is not the recommended version 1.4.4[PEAR] PEAR - installed: 1.10.13Wrote PEAR system config file at: /www/php8/etc/pear.confYou may want to add: /www/php8/lib/php to your php.ini include_path/www/php-8.1.7/build/shtool install -c ext/phar/phar.phar /www/php8/bin/phar.pharln -s -f phar.phar /www/php8/bin/pharInstalling PDO headers: /www/php8/include/php/ext/pdo/ 三、文件设置1.php-ini,将源码目录下的php.ini-production复制到自己的目录下
cp php.ini-production /www/php8/etc/php.ini2.生成www配置文件,将目录下的模板文件重命名
cd /www/php8/etc/php-fpm.d/cp www.conf.default www.conf3.生成php-fpm配置文件
cd /www/php8/etc/cp php-fpm.conf.default php-fpm.conf4.生成php-fpm可执行文件
# 创建存放配置文件的目录mkdir php-fpm# 从源码中复制一份fpm可执行脚本cp /www/php-8.1.7/sapi/fpm/init.d.php-fpm /www/php8/etc/php-fpm/php-fpm# 修改可执行文件的权限chmod 740 php-fpm 四、进程启用管理 # 使用可执行文件进行启动cd /www/php8/etc/php-fpm/./php-fpm start# 正常启动:Starting php-fpm done# ps查看进程是否启动ps -aux | grep php-fpm# 查看php-fpm进程占用的端口,正常应该是9000netstat -nltp# 查看php版本cd /www/php8/bin/./php -v使用systemctl管理服务
# 修改/php/etc/php-fpm.conf[global]; Pid file; Note: the default prefix is /www/php8/var; Default Value: none; pid = run/php-fpm.pid # 将前面分号删除vim /usr/lib/systemd/system/php-fpm.service# 添加下面内容,目录要配置自己的对应目录[Unit]Description=The PHP FastCGI Process ManagerAfter=syslog.target network.target[Service]Type=forkingPIDFile=/var/run/php-fpm.pidExecStart=/usr/local/php/sbin/php-fpmExecReload=/bin/kill -USR2 $MAINPIDPrivateTmp=true[Install]WantedBy=multi-user.target# 保存文件# 使用systemctl管理systemctl daemon-reload # 刷新systemctlsystemctl start php-fpm # 启动进程systemctl stop php-fpm # 结束进程systemctl enable php-fpm# 开机启动 五、模块功能更新1.进入源码目录进行编译安装
# php -m输出php的功能模块,在源码包的ext里面可以看到相应的模块,这些是自带的模块cd /www/php-8.1.7/ext/# 查看模块ls# 测试exifcd exif# 进入文件夹,使用phpize生成configure文件进行编译安装cd /www/php8/bin/phpize# 编译时指定配置文件./configure --with-php-config=/www/php8/bin/php-config# 安装make && make install# 安装完成之后会出现一个目录,里面包含了exif.so文件# 修改php.ini,在最后添加上添加模块的路径vim /www/php8/etc/php.iniextension=/www/php8/lib/php/extensions/no-debug-non-zts-20210902/exif.so# 保存,重启php-fpm进程# 通过php -m 查看模块功能已经添加本文由 mdnice 多平台发布
下一篇
MySQL索引、事务、储存引擎