Linux知识库
Linux基础知识!
Linux格式化硬盘以及格式化分区
linux基础常用知识
linux更换yum源
linux挂载windows SMB共享目录
linux开机启动级别
linux网卡配置
linux配置SMB服务
CentOS 8 firewalld配置
Linux软件管理:RPM软件包与YUM管理
Linux用户与组概念
Linux文件与目录权限基础
Linux计划任务管理
Linux中文本文件内容的查看
Linux基础-服务(service)和systemd管理服务
Vim编辑器基本操作
apt更换国内源
Linux程序服务!
Code-server在线编程服务器部署
Cloudreve网盘搭建
Emby多媒体影音系统搭建
chevereto图床搭建教程
Frp内网穿透服务器搭建
FTP服务器搭建
gitlab服务器搭建
Plex搭建
syncthing同步服务器搭建
Wordpress博客搭建
Typecho博客搭建
zabbix搭建(失败)
Aria2离线下载服务器搭建
KMS激活服务器搭建
CentOS搭建NTP服务
Grafana部署与Zabbix集成,部署开源IT系统监控平台
Linux应用环境搭建配置!
nginx编译安装
PHP8编译安装
Linux 关闭selinux
yum安装redis数据库
宝塔环境无法删除.user.ini
宝塔面板安装
mysql8.0.29编译安装
nginx安装(yum方式)
Linux系统基础知识
Linux命令行基础知识
使用Cerbot申请免费证书
ModSecurity 安装编译与连接nginx
Zabbix6.4.8安装部署
本文档使用 MrDoc 发布
-
+
首页
PHP8编译安装
## CentOS8编译安装PHP8 PHP,全称Hypertext Preprocessor(超文本预处理器),是一种通用开源脚本语言。它特别适合于web开发,并能嵌入HTML中。现在主要用于PHP网站中实现动态网站功能,常规我们使用nginx、apache部署的是html静态网页,可以通过.php编写动态页面实现。 ### 一、下载 ```shell # 创建文件夹用来安装php mkdir /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.7 chgrp -R root php-8.1.7 cd php-8.1.7 ``` ### 二、安装配置 ```shell # 和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 ```shell 问题: Package 'libxml-2.0', required by 'virtual:world', not found 解决方法: yum install libxml2-devel ``` 2.sqlite3 ```shell 问题: Package 'sqlite3', required by 'virtual:world', not found 解决方法: yum install sqlite-devel ``` 3.Bzip2 ```shell 问题: configure: error: Please reinstall the BZip2 distribution 解决方法: yum -y install bzip2-devel ``` 4.libcurl ```shell 问题: Package 'libcurl', required by 'virtual:world', not found 解决方法: yum install libcurl-devel ``` 5.libpng ```shell 问题: Package 'libpng', required by 'virtual:world', not found 解决方法: yum install libpng libpng-devel ``` 6.libjpeg ```shell 问题: Package 'libjpeg', required by 'virtual:world', not found 解决方法: yum install libjpeg-devel ``` 7.freetype2 ```shell 问题: Package 'freetype2', required by 'virtual:world', not found 解决方法: yum install freetype-devel ``` 8.icu ```shell 问题: Package 'icu-uc', required by 'virtual:world', not found Package 'icu-io', required by 'virtual:world', not found Package 'icu-i18n', required by 'virtual:world', not found 解决方法: yum install -y libicu-devel.x86_64 ``` 9.oniguruma ```shell 问题: 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.4 4.安装依赖 yum install autoconf automake libtool 5.编译到/usr目录下 ./autogen.sh && ./configure --prefix=/usr 6.安装 make && make install ``` 10.libxslt ```shell 问题: Package 'libxslt', required by 'virtual:world', not found 解决方法: yum -y install libxslt-devel ``` 11.libzip ```shell 问题: Package 'libzip', required by 'virtual:world', not found Package 'libzip', required by 'virtual:world', not found Package 'libzip', required by 'virtual:world', not found 解决方法: yum install libzip-devel ``` 终于完成了,出现下面的提示: ```shell Generating files configure: patching main/php_config.h.in configure: creating ./config.status creating main/internal_functions.c creating main/internal_functions_cli.c config.status: creating main/build-defs.h config.status: creating scripts/phpize config.status: creating scripts/man1/phpize.1 config.status: creating scripts/php-config config.status: creating scripts/man1/php-config.1 config.status: creating sapi/cli/php.1 config.status: creating sapi/fpm/php-fpm.conf config.status: creating sapi/fpm/www.conf config.status: creating sapi/fpm/init.d.php-fpm config.status: creating sapi/fpm/php-fpm.service config.status: creating sapi/fpm/php-fpm.8 config.status: creating sapi/fpm/status.html config.status: creating sapi/phpdbg/phpdbg.1 config.status: creating sapi/cgi/php-cgi.1 config.status: creating ext/phar/phar.1 config.status: creating ext/phar/phar.phar.1 config.status: creating main/php_config.h config.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. ``` 安装: ```shell 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-config Installing man pages: /www/php8/php/man/man1/ page: phpize.1 page: php-config.1 Installing 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.5 warning: 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.13 Wrote PEAR system config file at: /www/php8/etc/pear.conf You 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.phar ln -s -f phar.phar /www/php8/bin/phar Installing PDO headers: /www/php8/include/php/ext/pdo/ ``` ### 三、文件设置 1.php-ini,将源码目录下的php.ini-production复制到自己的目录下 ```shell cp php.ini-production /www/php8/etc/php.ini ``` 2.生成www配置文件,将目录下的模板文件重命名 ```shell cd /www/php8/etc/php-fpm.d/ cp www.conf.default www.conf ``` 3.生成php-fpm配置文件 ```shell cd /www/php8/etc/ cp php-fpm.conf.default php-fpm.conf ``` 4.生成php-fpm可执行文件 ```shell # 创建存放配置文件的目录 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 ``` ### 四、进程启用管理 ```shell # 使用可执行文件进行启动 cd /www/php8/etc/php-fpm/ ./php-fpm start # 正常启动: Starting php-fpm done # ps查看进程是否启动 ps -aux | grep php-fpm # 查看php-fpm进程占用的端口,正常应该是9000 netstat -nltp # 查看php版本 cd /www/php8/bin/ ./php -v ``` 使用systemctl管理服务 ```shell # 修改/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 Manager After=syslog.target network.target [Service] Type=forking PIDFile=/var/run/php-fpm.pid ExecStart=/usr/local/php/sbin/php-fpm ExecReload=/bin/kill -USR2 $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target # 保存文件 # 使用systemctl管理 systemctl daemon-reload # 刷新systemctl systemctl start php-fpm # 启动进程 systemctl stop php-fpm # 结束进程 systemctl enable php-fpm# 开机启动 ``` ### 五、模块功能更新 1.进入源码目录进行编译安装 ```shell # php -m输出php的功能模块,在源码包的ext里面可以看到相应的模块,这些是自带的模块 cd /www/php-8.1.7/ext/ # 查看模块 ls # 测试exif cd 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.ini extension=/www/php8/lib/php/extensions/no-debug-non-zts-20210902/exif.so # 保存,重启php-fpm进程 # 通过php -m 查看模块功能已经添加 ```
Chuck
2024年3月8日 15:52
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
Markdown文件
分享
链接
类型
密码
更新密码