CentOS离线/内网/无网络安装PHP环境

10 篇文章 1 订阅

准备rpm包,安装依赖(CentOS7演示)

  1. 使用当前CentOS的ISO镜像文件,使用压缩工具打开,把包中的Packages文件下的rpm文件复制到一个文件中。
    在这里插入图片描述

  2. 在网站https://pkgs.org/搜索下载所需要的依赖包,根据使用的系统选择不同版本,CentOS7使用的el7,下载完毕和系统复制出来的文件放在一起.,CentOS7可以下载这里 链接:https://pan.baidu.com/s/1FfmJSHXRrApD23AdPjo6yA 提取码:o2e9
    在这里插入图片描述

  3. FTP登入服务器,把文件夹中的rpm文件放到服务器中的文件中,如/data/rpm文件夹(新建)。

  4. 进入/data/rpm中,安装依赖,中间没有ERROR错误只是警告的话无需理会,安装到100%。

执行 rpm -Uvh /data/rpm/*.rpm --nodeps --force 安装依赖
注:–nodeps就是安装时不检查依赖关系,。–force就是强制安装
在这里插入图片描述
在这里插入图片描述

安装PHP

  1. 下载PHP包,以5.4版本为例,在data中新建文件夹php,把压缩包上传到文件夹中:

cd /data/php #进入php文件夹
tar -zxvf php-5.4.9.tar.gz #解压文件

  1. 在/data/php中新建文件夹info,安装php

执行 cd php-5.4.9
执行下面语句安装php环境
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip
在这里插入图片描述

  1. 看到执行上面的结果表示安装成功,执行下面指令:

执行 make (如果看到Don’t forget to run ‘make test’ 编译成功)
再执行 make install

  1. 进入/data/php/info/etc文件夹,复制php-fpm.conf.default文件并重命名为php-fpm.conf

cd /data/php/info/sbin
./php-fpm #启动fpm

  1. 查看是否启动 ps -ef|grep php 或者 netstat -tunlp
    在这里插入图片描述

配置nginx测试是否成功

为了测试直接在线安装了,可以参考这篇文章:https://blog.csdn.net/t8116189520/article/details/81909574
主要配置nginx.conf(本地测试是防火墙问题导致无法访问,可以使用下面命令放开80端口)

firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --reload

修改了nginx.conf后需重启nginx,下面是需修改的配置

server {
        listen       80;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        
        location ~ \.php$ {
            root /data/php/info/var/www;  #网站根目录,不存在新建文件夹即可
            # 设置监听端口
            fastcgi_pass   127.0.0.1:9000;
            # 设置nginx的默认首页文件
            fastcgi_index  index.php;
            # 设置脚本文件请求的路径
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            # 引入fastcgi的配置文件
            include        fastcgi_params;
        }
    }

在/data/php/info/var/www文件夹中新建index.php,内容

<?php
phpinfo();

在这里插入图片描述

  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

梦里藍天

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值