热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

CentOS8.4安装PHP7.4.25

1、下载官网:https:www.php.netdownloads#cdmydata#wgethttps:www.php.netdistributionsphp

1、下载

官网:https://www.php.net/downloads

# cd /mydata/
# wget https://www.php.net/distributions/php-7.4.25.tar.xz

2、解压

# cd /mydata/
# .tar.xz格式
# xz -dev php-7.4.25.tar.xz
# tar -xvf php-7.4.25.tar# 如果是.tar.gz格式
# tar -zxvf php-7.4.25.tar.gz

3、安装依赖

# yum -y install libzip-devel libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel krb5-devel sqlite-devel

4、安装

注意几个重点配置项:
--prefix=/usr/local/php7      //定义PHP安装目录
-with-config-file-path= /usr/local/php7/etc   //指定php.ini文件的放置路径,也可以是/etc目录下
--enable-fpm     //开启php-fpm    必须,
--with-fpm-user=www                  注意与你的nginx用户保持一致
--with-fpm-group=www                注意与你的nginx用户组保持一致
--disable-fileinfo        //当服务器内存为1G时,此项很有必要

# cd /mydata/php-7.4.24/
# ./configure --prefix=/usr/local/php7 --with-fpm-user=www --with-fpm-group=www --with-config-file-path=/usr/local/php7/etc --with-curl --with-freetype --enable-gd --with-jpeg --with-gettext --with-iconv-dir=/usr/local --with-kerberos --with-libdir=lib64 --with-libxml --with-mysqli --with-openssl --with-pdo-mysql --with-pdo-sqlite --with-pear --with-mhash --with-ldap-sasl --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-xml --with-zip --with-bz2 --enable-inline-optimization --enable-sysvsem

4-1、报错oniguruma的处理

# 报错如下:
configure: error: Package requirements (oniguruma) were not met:
Package 'oniguruma', required by 'virtual:world', not found

需要安装“” 扩展 ,可以去 https://pkgs.org/  里搜索 ,也可以使用
wget https://github.com/kkos/oniguruma/archive/v6.9.4.tar.gz -O oniguruma-6.9.4.tar.gz 进行下载

下载后,

# tar -zxvf oniguruma-6.9.4.tar.gz
# cd oniguruma-6.9.4/
# yum -y install autoconf automake libtool 先安装这几个命令
# ./autogen.sh
# ./configure --prefix=/usr --libdir=/lib64 //64位的系统一定要标识 --libdir=/lib64 否则还是不行
# make
# make install

然后再次执行 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
大约20分钟 出现
...
clicommand.inc
pharcommand.inc
directorygraphiterator.inc
phar.inc
Build complete.
Don't forget to run 'make test'.OK 继续
# make install

如果 make 没有成功,而是出现了如:报错collect2: error: ld returned 1 exit status 
make: *** [sapi/cli/php] Error 1
collect2: error: ld returned 1 exit status
make: *** [Makefile:290: sapi/cli/php] Error 1
解决
vim Makefile
大约 113行 ,找到 EXTRA_LIBS  最后加上 -liconv   (有的是 -llber 根据实际情况)然后 #  make clean   再执行 make  即可。

 make install 最后出现

[root@qinser php-7.4.25]# make install
Installing shared extensions: /usr/local/php7/lib/php/extensions/no-debug-non-zts-20190902/
Installing PHP CLI binary: /usr/local/php7/bin/
Installing PHP CLI man page: /usr/local/php7/php/man/man1/
Installing PHP FPM binary: /usr/local/php7/sbin/
Installing PHP FPM defconfig: /usr/local/php7/etc/
Installing PHP FPM man page: /usr/local/php7/php/man/man8/
Installing PHP FPM status page: /usr/local/php7/php/php/fpm/
Installing phpdbg binary: /usr/local/php7/bin/
Installing phpdbg man page: /usr/local/php7/php/man/man1/
Installing PHP CGI binary: /usr/local/php7/bin/
Installing PHP CGI man page: /usr/local/php7/php/man/man1/
Installing build environment: /usr/local/php7/lib/php/build/
Installing header files: /usr/local/php7/include/php/
Installing helper programs: /usr/local/php7/bin/program: phpizeprogram: php-config
Installing man pages: /usr/local/php7/php/man/man1/page: phpize.1page: php-config.1
Installing PEAR environment: /usr/local/php7/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: /usr/local/php7/etc/pear.conf
You may want to add: /usr/local/php7/lib/php to your php.ini include_path
/mydata/php-7.4.25/build/shtool install -c ext/phar/phar.phar /usr/local/php7/bin/phar.phar
ln -s -f phar.phar /usr/local/php7/bin/phar
Installing PDO headers: /usr/local/php7/include/php/ext/pdo/

OK 安装成功


5、创建php环境变量

# vim /etc/profile
# 把这一行“/usr/local/php7/bin”追加到之前配置的mysql配置后,用英文冒号隔开
# 如: export PATH="$PATH:/usr/local/mysql8/bin:/usr/local/php7/bin"# source /etc/profile 使配置立即生效
# php -v 查看PHP版本

6、设置启动文件并开机自动启动

1、生成php配置文件php.ini
# cd /mydata/php-7.4.25/
# cp php.ini-production /usr/local/php7/etc/php.ini2、生成www配置文件
# cd /usr/local/php7/etc/php-fpm.d/
# cp www.conf.default www.conf3、生成php-fpm配置文件
# cd /usr/local/php7/etc
# cp php-fpm.conf.default php-fpm.conf4 生成php-fpm服务启动文件
# cp /mydata/php-7.4.25/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm //设置PHP启动文件
# chmod +x /etc/init.d/php-fpm //为其添加可执行权限5、添加到环境系统启动项
# chkconfig --add php-fpm //添加到开机重启
# chkconfig php-fpm on //启动php-fpm6、查看是否添加成功
# chkconfig --list
......
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off
php-fpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off --- php-fpm 添加成功7、启动 php-fpm
# /etc/init.d/php-fpm start
出现 Starting php-fpm done OK 启动成功
# /etc/init.d/php-fpm status
php-fpm (pid 2306) is running... 检测开机自启动是否设置成功?
# shutdown -r now 重启服务器
# netstat -ntlp
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 156525/php-fpm: mas
出现了9000端口号说明可以开机自启动了

7、配置nginx支持php

# vim /usr/local/nginx/conf/nginx.conf 大约45行起

修改内容下图:

然后释放如下图

在 /usr/local/nginx/html/目录创建 index.php 文件

# 重启nginx
# systemctl restart nginx.service

 再次访问站点:

OK ,nginx站点支持PHP了


 附录:PHP重要文件目录 和常用命令

/usr/local/php7/ 安装目录
/usr/local/php7/bin/ 可执行目录, php 环境变量位于此目录
/usr/local/php7/bin/phpize 可执行目录
/usr/local/php7/etc/php.ini PHP配置文件
/etc/init.d/php-fpm php-fpm启动文件/etc/init.d/php-fpm start 开启服务
/etc/init.d/php-fpm stop 停止服务
/etc/init.d/php-fpm status 查看状态
/etc/init.d/php-fpm restart 重启服务
/etc/init.d/php-fpm reload 平滑重启加入系统服务以后可以使用
service php-fpm start/stop/status/restart/reload


推荐阅读
  • MySQL缓存机制深度解析
    本文详细探讨了MySQL的缓存机制,包括主从复制、读写分离以及缓存同步策略等内容。通过理解这些概念和技术,读者可以更好地优化数据库性能。 ... [详细]
  • MySQL 数据库迁移指南:从本地到远程及磁盘间迁移
    本文详细介绍了如何在不同场景下进行 MySQL 数据库的迁移,包括从一个硬盘迁移到另一个硬盘、从一台计算机迁移到另一台计算机,以及解决迁移过程中可能遇到的问题。 ... [详细]
  • 1:有如下一段程序:packagea.b.c;publicclassTest{privatestaticinti0;publicintgetNext(){return ... [详细]
  • PHP 5.2.5 安装与配置指南
    本文详细介绍了 PHP 5.2.5 的安装和配置步骤,帮助开发者解决常见的环境配置问题,特别是上传图片时遇到的错误。通过本教程,您可以顺利搭建并优化 PHP 运行环境。 ... [详细]
  • 深入理解 SQL 视图、存储过程与事务
    本文详细介绍了SQL中的视图、存储过程和事务的概念及应用。视图为用户提供了一种灵活的数据查询方式,存储过程则封装了复杂的SQL逻辑,而事务确保了数据库操作的完整性和一致性。 ... [详细]
  • 本文深入探讨 MyBatis 中动态 SQL 的使用方法,包括 if/where、trim 自定义字符串截取规则、choose 分支选择、封装查询和修改条件的 where/set 标签、批量处理的 foreach 标签以及内置参数和 bind 的用法。 ... [详细]
  • Hadoop入门与核心组件详解
    本文详细介绍了Hadoop的基础知识及其核心组件,包括HDFS、MapReduce和YARN。通过本文,读者可以全面了解Hadoop的生态系统及应用场景。 ... [详细]
  • 本文详细介绍了 MySQL 中 LAST_INSERT_ID() 函数的使用方法及其工作原理,包括如何获取最后一个插入记录的自增 ID、多行插入时的行为以及在不同客户端环境下的表现。 ... [详细]
  • 本文详细介绍如何利用已搭建的LAMP(Linux、Apache、MySQL、PHP)环境,快速创建一个基于WordPress的内容管理系统(CMS)。WordPress是一款流行的开源博客平台,适用于个人或小型团队使用。 ... [详细]
  • 深入解析Redis内存对象模型
    本文详细介绍了Redis内存对象模型的关键知识点,包括内存统计、内存分配、数据存储细节及优化策略。通过实际案例和专业分析,帮助读者全面理解Redis内存管理机制。 ... [详细]
  • Windows 7 64位系统下Redis的安装与PHP Redis扩展配置
    本文详细介绍了在Windows 7 64位操作系统中安装Redis以及配置PHP Redis扩展的方法,包括下载、安装和基本使用步骤。适合对Redis和PHP集成感兴趣的开发人员参考。 ... [详细]
  • 本文详细介绍了IBM DB2数据库在大型应用系统中的应用,强调其卓越的可扩展性和多环境支持能力。文章深入分析了DB2在数据利用性、完整性、安全性和恢复性方面的优势,并提供了优化建议以提升其在不同规模应用程序中的表现。 ... [详细]
  • 本文详细介绍了如何通过多种编程语言(如PHP、JSP)实现网站与MySQL数据库的连接,包括创建数据库、表的基本操作,以及数据的读取和写入方法。 ... [详细]
  • 随着网络安全威胁的不断演变,电子邮件系统成为攻击者频繁利用的目标。本文详细探讨了电子邮件系统中的常见漏洞及其潜在风险,并提供了专业的防护建议。 ... [详细]
  • 本次考试于2016年10月25日上午7:50至11:15举行,主要涉及数学专题,特别是斐波那契数列的性质及其在编程中的应用。本文将详细解析考试中的题目,并提供解题思路和代码实现。 ... [详细]
author-avatar
手机用户2502936007
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有