- 此处准备安装laravel5.7 版本,所以配置nginx +php7.2+mysql5.7。在前面的博客已经写过,就不再详述,此处仅作一个笔记。
1,拉取php 7.2 fpm镜像
docker search php
搜索镜像,此处选择拉取phpdockerio/php72-fpm
docker pull phpdockerio/php72-fpm
拉取成功后查看所有镜像
docker images

2,配置laravel运行容器
首先创建php7.2+mysql容器
docker run -d -v /docker/php72/conf:/usr/local/etc/php -v /docker/www/laravel57:/var/www/html -p 9001:9000 --link mysql5.7:mysql5.7 --name php72-mysql phpdockerio/php72-fpm
创建nginx+php7.2+mysql容器
docker run -d -p 80:80 --name nginx-php72-mysql -v /docker/nginx-laravel/conf.d/default.conf:/etc/nginx/conf.d/default.conf -v /docker/nginx-laravel/logs:/var/log/nginx --link php72-mysql:php72-mysql --privileged=true nginx
对应的nginx配置文件为
server {
listen 80;
listen [::]:80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /var/www/html;
index index.php 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 /var/www/html;
fastcgi_pass php72-mysql:9000; # 很重要, 这里需要改到链接的php-fpm的映射名字和端口
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name; # $document_root 可能不生效,手动改下
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
此处需要注意:在php7.2+mysql容器中我们将 php-fpm 工作目录 /var/www/html(这个/var/www/html目录可以是任意目录) 使用 v /docker/www/laravel57:/var/www/html 映射到了外部目录。
然后在nginx+php7.2+mysql容器中 并没有做工作目录映射,是因为我做了nginx配置文件映射后,在配置文件修改了 root 的目录,将默认的 /usr/share/nginx/html 改为了 /var/www/html ,即改为了php-fpm的工作目录,这样就不需要再次做映射了。也可以这样
不修改nginx配置默认目录,在容器启动的时候做映射处理
docker run -d -p 80:80 --name nginx-php72-mysql -v /docker/nginx-laravel/conf.d/default.conf:/etc/nginx/conf.d/default.conf -v /docker/nginx-laravel/logs:/var/log/nginx -v /docker/www/laravel57:/usr/share/nginx/html --link php72-mysql:php72-mysql --privileged=true nginx
对应配置文件为
server {
listen 80;
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;
}
#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$ {
fastcgi_pass php72-mysql:9000; # 很重要, 这里需要改到链接的php-fpm的映射名字和端口
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name; # $document_root 可能不生效,手动改下
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
版权声明:本文为sang521jia原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。