PHP在docker上的配置

参考:


配置PHP

添加php目录及文件

mkdir /var/www/php
cd /var/www/php

vi info.php

<?php
phpinfo();

php启动:

cd /var/www/php
docker run --rm -it \
  --name my-phpfpm \
  --network network_mysql \
  --network network_mynginx \
  -v $PWD:/myphp \
  bitnami/php-fpm

配置nginx

添加php-fpm.conf

server {
    listen       80;
    server_name  localhost;

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

    location ~ \.php$ {
        root /myphp;
        fastcgi_pass my-phpfpm:9000;
        fastcgi_index index.php;

        # 这里的/myphp是php容器里的php文件的目录
        fastcgi_param  SCRIPT_FILENAME $document_root/$fastcgi_script_name; 
        # fastcgi_param  SCRIPT_FILENAME /myphp/$fastcgi_script_name; 
        include fastcgi_params;
    }
}

启动nginx

docker run --rm -p 80:80 \
    --name mynginx \
    --network network_mynginx \
    --hostname=wodedata.com \
    --add-host=app.wodedata.com:127.0.0.1 \
    -v $PWD/conf/conf.d:/etc/nginx/conf.d \
    -v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf \
    -v $PWD/log:/var/log/nginx \
    -v $PWD/www:/usr/share/nginx \
    nginx

版权所有,转载请注明出处 luowei.github.io.