Docker 安装Nginx + PHP-FPM 7.2 + Reids等扩展 + Composer

1. 安装Nginx
参考 https://www.runoob.com/docker/docker-install-nginx.html
- 拉取Nginx镜像
docker pull nginx
- 新增目录
mkdir -p ~/nginx/html ~/nginx/logs ~/nginx/conf ~/nginx/conf.d
- 创建容器
docker run -v /root/nginx/html:/usr/share/nginx/html -v /root/nginx/conf.d:/etc/nginx/conf.d -v /root/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -p 80:80 -p 8888:8888  --privileged=true --name nginx -d nginx

2. 安装PHP-fpm 7.2
参考 https://www.runoob.com/docker/docker-install-php.html
- 创建目录
mkdir ~/php/conf.d
- 拉取Nginx镜像
docker pull php:7.2-fpm
- 创建容器
docker run -w /var/www/html -v /root/nginx/html:/var/www/html -v /root/php:/usr/local/etc/php --privileged=true -p 80:80 --name php-fpm -d php:7.2-fpm

3. 新增~nginx/conf/nginx.conf文件

user  nginx;	
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}
http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;
    client_max_body_size 50m;
    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;
    include /etc/nginx/conf.d/*.conf;
}

4. 新增~/nginx/conf.d/www.conf 文件

#fastcgi_pass 根据下一步的FPM 地址定义 ,通过过 docker inspect php-fpm查看fpm容器ip地址

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.php index.html index.htm;
        try_files $uri $uri/ /index.php?$query_string;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html/Carbonuni-PHP;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php {
        root           /usr/share/nginx/html;
        fastcgi_pass   172.17.0.5:9000;
        fastcgi_index  index.php;
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_param   PATH_INFO $fastcgi_path_info;
        fastcgi_param   SCRIPT_FILENAME  /var/www/html/$fastcgi_script_name;
        include        fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

5. 修改Nginx配置重启容器
docker restart nginx

6. 安装Redis

进入php-fpm 容器
docker exec -it php-fpm bash

curl -L -o /tmp/redis.tar.gz https://github.com/phpredis/phpredis/archive/3.1.6.tar.gz

tar xfz /tmp/redis.tar.gz

rm -r /tmp/redis.tar.gz

mkdir -p /usr/src/php/ext

mv phpredis-3.1.6 /usr/src/php/ext/redis

docker-php-ext-install redis

7. 安装一些扩展 可以通过 docker-php-ext-install

例如安装mysqli
docker-php-ext-install mysqli

8. 安装GD库

#更新软件源
apt update
#安装各种库
apt install -y libwebp-dev libjpeg-dev libpng-dev libfreetype6-dev
#解压源码
docker-php-source extract
#gd源码文件夹
cd /usr/src/php/ext/gd
#准备编译
docker-php-ext-configure gd --with-webp-dir=/usr/include/webp --with-jpeg-dir=/usr/include --with-png-dir=/usr/include --with-freetype-dir=/usr/include/freetype2
创建目录
mkdir /usr/local/etc/php/conf.d/
#编译安装
docker-php-ext-install gd
#查看安装进度
php -m | grep gd
#重启容器
docker restart php
 

9. 增加composer
拉取composer
docker pull composer
进入XXX这项目 里面必须包含composer.json
docker run -it --name composer -v /root/nginx/html/XXX:/app --privileged=true composer composer install --ignore-platform-reqs

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

戴国进

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

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

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

打赏作者

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

抵扣说明:

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

余额充值