centos7离线安装PHP7
环境
centos7.9
PHP7.4.30
准备工作
在编译PHP时会提示一些包版本不够或者缺少某些包,一般选择yum来安装缺少的包,但因为是离线安装,所以可以手动配置本地yum源。先看一下系统版本
[root@xcc ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
下载系统对应的iso镜像文件CentOS-7.9-x86_64-Everything-2009.iso,传到服务器上并配置本地yum源。配置方法可以参考:https://www.cnblogs.com/haolb123/p/16553119.html
安装完下面这些,可以减少在编译PHP时提示的缺包问题。
yum install -y gcc gcc-c++ make cmake bison autoconf wget lrzsz
yum install -y libtool libtool-ltdl-devel
yum install -y freetype-devel libjpeg.x86_64 libjpeg-devel libpng-devel gd-devel
yum install -y python-devel patch sudo
yum install -y openssl* openssl openssl-devel ncurses-devel
yum install -y bzip* bzip2 unzip zlib-devel
yum install -y libevent*
yum install -y libxml* libxml2-devel
yum install -y libcurl* curl-devel
yum install -y readline-devel
yum install -y sqlite-devel.x86_64
附1:如果没有系统iso镜像文件,可以直接编译安装,提示缺少什么,就从https://pkgs.org/下载系统对应的包,然后手动rpm -i安装即可。有些包可能需要编译安装。
附2:单独下载rpm包安装时,会提示缺少依赖项等。而yum安装时会自动安装这个包的依赖项,所以还是建议配置本地yum源来装。
附3:安装完上面这些,如果是最小化安装PHP7.4.30则可以正常通过编译,可以直接make && make install安装PHP。
下载PHP
下载地址:https://www.php.net/downloads.php
安装
安装时,如果此时不指定./configure后面的扩展,后期也可以手动加上。
附:指定的扩展越多,编译时可能会遇到的问题越多,不要盲目的添加很多用不上的扩展,如果可以,建议选择默认(最小化)安装。
附:根据实际的web服务器开启适当的扩展,Nginx使用--enable-fpm,Apache使用--with-apxs2
tar zxvf php-7.4.30.tar.gz
cd php-7.4.30
./configure --prefix=/usr/local/php --with-config-file-scan-dir=/usr/local/php/etc/ --enable-inline-optimization --enable-opcache --enable-fpm --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gettext --enable-mbregex --enable-mbstring --with-iconv --with-mhash --with-openssl --enable-bcmath --enable-soap --with-xmlrpc --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-zip --with-bz2 --enable-gd --with-jpeg --with-readline --with-freetype --disable-fileinfo
#最小化安装-适合nginx平台
./configure --prefix=/usr/local/php --with-config-file-scan-dir=/usr/local/php/etc/ --enable-fpm
#最小化安装-适合apache平台(先安装httpd,--with-apxs2指定httpd安装位置)
./configure --prefix=/usr/local/php --with-config-file-scan-dir=/usr/local/php/etc/ --with-apxs2=/usr/sbin/apxs
PHP7的编译扩展有些更新,参考:https://www.php.net/manual/zh/migration74.other-changes.php
编译时遇到的一些问题
oniguruma
因为扩展指定了--enable-mbstring需要用到oniguruma包,如果用不到可以禁用这个扩展--disable-mbregex
下载地址:https://pkgs.org/download/oniguruma 和 https://pkgs.org/download/oniguruma-devel

安装
rpm -i oniguruma-devel-6.8.2-2.el7.x86_64.rpm
rpm -i oniguruma-6.8.2-2.el7.x86_64.rpm
libzip
继续编译PHP,提示libzip >= 0.11因为系统镜像里的版本是0.10,需要单独安装,这里下载1.2.0,因为高版本需要cmake。
下载地址:https://libzip.org/download/libzip-1.2.0.tar.gz

安装
tar xvf libzip-1.2.0.tar.gz
cd libzip-1.2.0
./configure
make && make install
执行完后并没有被系统识别,相当于Windows系统的环境变量一样,让系统识别还需要配置PKG_CONFIG_PATH,用pkg-config查看libzip.pc,发现没有输出,find查找一下,默认位置在/usr/local/lib/pkgconfig/libzip.pc然后建立链接。
[root@xcc ~]# pkg-config --list-all|grep libzip
[root@xcc ~]# find / -name libzip.pc
/root/libzip-1.2.0/libzip.pc
/usr/local/lib/pkgconfig/libzip.pc
[root@xcc ~]# ln -sf /usr/local/lib/pkgconfig/libzip.pc /usr/lib64/pkgconfig/
[root@xcc ~]# pkg-config --list-all|grep libzip
libzip libzip - library for handling zip archives
继续编译PHP,这里已经可以正常编译通过。

继续安装
make

make install

配置文件
从安装包里把配置文件拷贝到安装目录并重命名,配置文件有两个:生产环境php.ini-production和开发环境php.ini-development
[root@xcc php-7.4.30]# cp php.ini-* /usr/local/php/etc/
[root@xcc php-7.4.30]# cd /usr/local/php/etc/
[root@xcc etc]# cp php.ini-development php.ini
[root@xcc etc]# ls
php-fpm.conf.default php-fpm.d php.ini php.ini-development php.ini-production
配置系统环境变量
编辑文件vi /etc/profile在末尾添加
PATH=/usr/local/php/bin:$PATH
export PATH
使其立即生效source /etc/profile
查看版本
[root@xcc ~]# php -v
PHP 7.4.30 (cli) (built: Nov 2 2022 17:32:45) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
查看扩展
[root@xcc ~]# php -m
[PHP Modules]
bcmath
bz2
Core
ctype
curl
date
dom
filter
gd
gettext
hash
iconv
json
libxml
mbstring
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
readline
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
sqlite3
standard
sysvmsg
sysvsem
sysvshm
tokenizer
xml
xmlreader
xmlrpc
xmlwriter
zip
[Zend Modules]
end。
centos7离线安装PHP7的更多相关文章
- Centos7 离线安装 php7
问题:因内部管控,机器无法连接公有yum源安装php. 正常安装php7可以参考CentOS7.2 安装 PHP7.2 下面的代码也是一种方法 yum -y install libmcrypt lib ...
- CentOS7离线安装mysql5.7
下载mysql5.7,系统选择redhat,版本选择RHEL7,下载RPM Bundle后得到一个tar文件.这里得到文件mysql-5.7.25-1.el7.x86_64.rpm-bundle.ta ...
- CentOS7 离线安装mysql-5.7.16
CentOS7 离线安装mysql-5.7.16 1 . 安装新版mysql前,需将系统自带的mariadb-lib卸载 [root@slave mytmp]# rpm -qa|grep mariad ...
- CentOS7离线安装Nginx(详细安装过程)
CentOS7离线安装Nginx(详细安装过程) 1.安装gcc.g++ 下载好所需的文件后上传至服务器(下载地址:https://download.csdn.net/download/a729360 ...
- Centos7 编译安装PHP7
Centos7 编译安装PHP7 编译安装的方式可以让组件等设置更加合理,但需要你对PHP的代码及各种配置非常的熟悉,以下为大致的安装流程,大家可以参考 1.下载编译工具 yum groupinsta ...
- CentOS7离线安装MySQL8.0
CentOS7离线安装MySQL8.0 卸载软件 rpm -e --nodeps 要卸载的软件包 root@jacky zookeeper]# rpm -e --nodeps java-1.6.0-o ...
- Binlog2sql+CentOS7 离线安装
Binlog2sql+CentOS7 离线安装 目录 Binlog2sql+CentOS7 离线安装 1. 环境 2. 下载 3.1 Pip 安装 3.2 PyMySQL/mysql-replicat ...
- CentOS7编译安装php7.1配置教程详解
这篇文章主要介绍CentOS7编译安装php7.1的过程和配置详解,亲测 ,需要的朋友可以参考. 1.首先安装依赖包: yum install libxml2 libxml2-devel openss ...
- centos7.3安装php7.0
需求:在Centos7.3下搭建LNMP环境 文章转载自:http://blog.csdn.net/wszll_alex/article/details/76285324 作者:狂热森林 . 关闭防火 ...
随机推荐
- PHP为任意页面设访问密码
使用方法 把下面的代码存为php文件,下面的整段代码是验证过程,然后在你入口页进行调用例如命名为MkEncrypt.php,那么在入口页进行 require_once('MkEncrypt ...
- 【java】学习路径26-泛型,集合使用自定义的类型
接着上一节的内容,上一节我们使用到了ArrayList.Vector.LinkedList三个集合类型. 但是目前我们有一个问题:如果集合中存储的是Integer类型的数据(int的引用类型),那我们 ...
- django_day06
django_day06 内容回顾 事务 try: with transaction.atomic(): #事务 #一系列的操作 pass except Exception as e: print(e ...
- centos7使用tar包安装mysql5.7
特别注意: 文档中涉及到密码的都是用的是弱密码,是存在安全风险的,一定要根据自己的情况修改为复杂度更高的密码! centos 7.6 mysql 5.7.31 基础目录: /srv/{app,data ...
- KingbaseES R6 集群禁用 root ssh 后需要修改集群为es_server 案例
案例说明: 在生产环境下,由于安全需要,主机间不允许建立root用户的ssh信任连接,这样导致KingbaseES R6 repmgr集群,通过sys_monitor.sh脚本启动集群时,节点之间不能 ...
- Python 第五次实验
[1] (程序设计)编写程序,将二维列表数据写入 CSV文件(命名为"out.csv"),用逗号隔开.二维列表如下:[['Name','Age','Gender'], ['Bob' ...
- 2021年3月-第02阶段-前端基础-Flex 伸缩布局-移动WEB开发_flex布局
移动web开发--flex布局 1.0 传统布局和flex布局对比 1.1 传统布局 兼容性好 布局繁琐 局限性,不能再移动端很好的布局 1.2 flex布局 操作方便,布局极其简单,移动端使用比较广 ...
- DirectPV-----文章内容有待进一步实践完善
GitHub文档地址:https://github.com/minio/directpv DirectPV是用于直连存储的CSI驱动程序.从更简单的意义上讲,它是一个分布式持久卷管理器,而不是像SAN ...
- filebeat测试output连通性
在默认的情况下,直接运行filebeat的话,它选择的默认的配置文件是当前目录下的filebeat.yml文件. filebeat.yml文件内容 filebeat.inputs: - type: l ...
- 《3-D Deep Learning Approach for Remote Sensing Image Classification》论文笔记
论文题目<3-D Deep Learning Approach for Remote Sensing Image Classification> 论文作者:Amina Ben Hamida ...