Docker 快速搭建 Ubuntu + Nginx + PHP 镜像(环境)

4 篇文章 1 订阅
1 篇文章 0 订阅
  • Ubuntu : 22.04
  • Nginx : 1.18
  • PHP : 7.4
  1. 拉取 Ubuntu 镜像 (默认是最新):

    docker pull ubuntu
    

    或者

    docker pull ubuntu:latest(版本号)
    
  2. 查看本地镜像:

    docker images
    
  3. 运行容器,并进入容器:

    docker run -it -p 8081:80 --name=ubnxphp ubuntu(镜像ID)
    

    退出容器:

    exit
    

    查看所有容器:

    docker ps -a
    

    启动一个已停止的容器:

    docker start b750bbbcfd88 (镜像ID)
    

    进入容器:

    docker attach b750bbbcfd88 (镜像ID)
    

    或者

    docker exec -it b750bbbcfd88 /bin/bash
    
  4. 更新-apt (安装软件前请更新 apt-源,可能会出现找不到安装包

    apt-get update
    
  5. 安装 Nginx

    apt install -y nginx
    

    nginx-命令

    # 关闭
    service nginx stop
    # 开启
    service nginx start
    # 状态
    service nginx status
    # 重启
    service nginx restart
    
  6. 安装 PHP

    apt-get install -y software-properties-common
    
    add-apt-repository ppa:ondrej/php
    # 出现暂停,按回车键[ENTER]
    
    apt-get update
    
    apt-get install -y php7.4-fpm
    

    php7.4-fpm-命令

    # 关闭
    service php7.4-fpm stop
    # 开启
    service php7.4-fpm start
    # 状态
    service php7.4-fpm status
    # 重启
    service php7.4-fpm restart
    
  7. 安装编译工具

    apt install -y vim
    
  8. 修改 nginx 配置文件

    vi /etc/nginx/sites-available/default
    

    在这里插入图片描述

  9. 启动服务

    # 检查 nginx 配置文件
    nginx -t
    # 重启 nginx
    service nginx restart 
    # 启动 php7.4-fpm
    service php7.4-fpm start 
    
    
  10. 查看服务

    # 查看当前进程
    ps -aux
    # 查看 nginx 状态
    service nginx status 
    # 查看 php7.4-fpm 状态
    service php7.4-fpm status 
    
    
  11. 在本地浏览器测试-nginx
    在这里插入图片描述

  12. 执行-php

    vi /var/www/html/phpinfo.php
    
    <?php
    phpinfo();
    
    

    在这里插入图片描述

  13. 生成新的镜像

    docker commit -m="ubuntu+nginx+php" -a="ybaog" 74804c6cfdca ubnxphp:v1
    

大家在使用的过程中可以先跑通nginx后在弄php。
在常规使用中可以根据自己的需求安装PHP其他的拓展。

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值