栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

docker构建nginx+php8

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

docker构建nginx+php8

拉取官方php8.0镜像

docker pull php:8.0-fpm
// --name php8 将php的容器命名为php8
// ~/Desktop/wwwroot/:/www 本地~/Desktop/wwwroot/目录映射至容器/www目录
// -d 后台运行
docker run --name php8 -v ~/Desktop/wwwroot/:/www -d php:8.0-fpm

拉取官方最新nginx镜像

docker pull nginx:latest

创建本地nginx配置目录 

~/Desktop/workspacce/docker/nginx/conf

在上面配置目录里创建demo.conf 

server {
    listen       8801;
    server_name  localhost;

    location / {
        root   /usr/share/nginx/html/demo;
        index  index.html index.htm index.php;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    location ~ .php$ {
        fastcgi_pass   php:9000;
        fastcgi_index  index.php;
        fastcgi_param  script_FILENAME  /www/demo/$fastcgi_script_name;
        include        fastcgi_params;
    }
}
// -p 8801:8801: 端口映射,把 nginx 中的 8801 映射到本地的 8801 端口。前面是本地端口
// ~/Desktop/wwwroot: 是本地www的存储目录,/usr/share/nginx/html 是容器内 html 文件的存储目录。
// ~/Desktop/workspacce/docker/nginx/conf: 是上面创建的本地 nginx 配置文件的存储目录,/etc/nginx/conf.d 是容器内 nginx 配置文件的存储目录。
// --link php8:php: 把 php8 的网络并入 nginx,并通过修改 nginx 的 /etc/hosts,把域名 php 映射成 127.0.0.1,让 nginx 通过 php:9000 访问 php-fpm。

docker run --name nginx-php8 -p 8801:8801 -d 
    -v ~/Desktop/wwwroot:/usr/share/nginx/html:ro 
    -v ~/Desktop/workspacce/docker/nginx/conf:/etc/nginx/conf.d:ro 
    --link php8:php 
    nginx
扩展: 安装composer

进入php8容器

docker exec -it php8 /bin/bash

安装composer

curl -sS https://getcomposer.org/installer | php

mv composer.phar /usr/local/bin/composer

composer install 可能会出现错误提示 ”Failed to download symfony/polyfill-mbstring from dist: The zip extension and unzip/7z commands are both missing, skipping.“

执行以下命令 或者 自行安装git

apt-get update
apt-get install zip unzip

安装php-redis扩展

打开官方php redis扩展页面,选择合适的redis源码扩展包

https://pecl.php.net/package/redis

curl -O https://pecl.php.net/get/redis-5.3.4.tgz
tar xfz redis-5.3.4.tgz
mv redis-5.3.4 /usr/src/php/ext/redis
docker-php-ext-install redis

使用php -m可查看redis扩展是否安装成功

装完扩展后需要重启php容器

docker restart php8

扩展:

docker容器内使用本机的mysql,redis等host为 host.docker.internal

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/333658.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号