爱快docker安装PHP和Nginx

本文章参考连接:Docker 安装 PHP | 菜鸟教程

安装PHP 

1、搜索并下载PHP镜像

 

搜索一个带-fpm的php镜像并下载

 2、创建PHP容器

 

 安装Nginx

1、下载Nginx镜像

 

 2、创建Nginx容器

 配置Nginx

1、配置default.conf

进入存有default.conf的目录

root@nginx:/# cd /etc/nginx/conf.d/
root@nginx:/etc/nginx/conf.d# ls
default.conf
root@nginx:/etc/nginx/conf.d# 

备份原有配置

root@nginx:/etc/nginx/conf.d# cp default.conf default.conf.bak
root@nginx:/etc/nginx/conf.d# 

查看原有配置

root@nginx:/etc/nginx/conf.d# cat default.conf
server {
    listen       80;
    listen  [::]:80;
    server_name  localhost;

    #access_log  /var/log/nginx/host.access.log  main;

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

    #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;
    }

    # 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           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$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;
    #}
}

root@nginx:/etc/nginx/conf.d# 

将配置内容复制到本地并修改 

将修改好的文件上传到本地址映射文件夹

 root@nginx:/etc/nginx/conf.d# cd /usr/share/nginx/html
root@nginx:/usr/share/nginx/html# ls
default.conf  hosts  index.css  index.html  index.php

将 default.conf 文件复制到原来的位置

root@nginx:/usr/share/nginx/html# cp ./default.conf /etc/nginx/conf.d/
root@nginx:/usr/share/nginx/html# cd /etc/nginx/conf.d/
root@nginx:/etc/nginx/conf.d# ls
default.conf  default.conf.bak
root@nginx:/etc/nginx/conf.d# cat default.conf
server {
    listen       80;
    listen  [::]:80;
    server_name  localhost;

    #access_log  /var/log/nginx/host.access.log  main;

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

    #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;
    }

    # 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           html;
        fastcgi_pass   192.168.8.3:9000;
        fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        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;
    #}
}

root@nginx:/etc/nginx/conf.d# 

2、配置hosts

找到对应目录

root@nginx:/etc/nginx/conf.d# cd /etc/     
root@nginx:/etc# ls
adduser.conf            ca-certificates.conf  deluser.conf  gai.conf  host.conf  issue.net      localtime    netconfig      pam.d      rc1.d  rcS.d        shadow-  systemd
alternatives            cron.d                dpkg          group     hostname   kernel         login.defs   nginx          passwd     rc2.d  resolv.conf  shells   terminfo
apt                     cron.daily            e2scrub.conf  group-    
hosts      ld.so.cache    logrotate.d  nsswitch.conf  passwd-    rc3.d  rmt          skel     timezone
bash.bashrc             debconf.conf          environment   gshadow   init.d     ld.so.conf     mke2fs.conf  opt            profile    rc4.d  security     ssl      ucf.conf
bindresvport.blacklist  debian_version        fonts         gshadow-  inputrc    ld.so.conf.d   motd         os-release     profile.d  rc5.d  selinux      subgid   update-motd.d
ca-certificates         default               fstab         gss       issue      libaudit.conf  mtab         pam.conf       rc0.d      rc6.d  shadow       subuid   xattr.conf
root@nginx:/etc# 

将hosts配置复制到本地进行修改

root@nginx:/etc# cat hosts
127.0.0.1       localhost
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
192.168.8.2     nginx
root@nginx:/etc# 

将修改的hosts复制到它容器中原来的位置

root@nginx:/etc# ls
adduser.conf            ca-certificates.conf  deluser.conf  gai.conf  host.conf  issue.net      localtime    netconfig      pam.d      rc1.d  rcS.d        shadow-  systemd
alternatives            cron.d                dpkg          group     hostname   kernel         login.defs   nginx          passwd     rc2.d  resolv.conf  shells   terminfo
apt                     cron.daily            e2scrub.conf  group-    hosts      ld.so.cache    logrotate.d  nsswitch.conf  passwd-    rc3.d  rmt          skel     timezone
bash.bashrc             debconf.conf          environment   gshadow   init.d     ld.so.conf     mke2fs.conf  opt            profile    rc4.d  security     ssl      ucf.conf
bindresvport.blacklist  debian_version        fonts         gshadow-  inputrc    ld.so.conf.d   motd         os-release     profile.d  rc5.d  selinux      subgid   update-motd.d
ca-certificates         default               fstab         gss       issue      libaudit.conf  mtab         pam.conf       rc0.d      rc6.d  shadow       subuid   xattr.conf
root@nginx:/etc# cp /usr/share/nginx/html/hosts ./
root@nginx:/etc# cat hosts
127.0.0.1       localhost
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
192.168.8.3     php

root@nginx:/etc# 

测试

创建php文件

放到本地挂载的目录中

得到

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值