Laravel

docker部署lmnp环境

docker-compose:

version: '3.2'
services:
  nginx:
    image: nginx
    volumes:
     - /Users/xcy/docker/nginx/templates:/etc/nginx/templates
     - /Users/xcy/docker/nginx/conf.d:/etc/nginx/conf.d
     - /Users/xcy/docker/nginx/html:/usr/share/nginx/html
     - /Users/xcy/docker/nginx/logs:/var/log/nginx
    ports:
     - 8080:80
     
  php7:
    image: php:7.4-fpm
    volumes:
     - /Users/xcy/docker/nginx/html:/usr/share/nginx/html
    stdin_open: true
    tty: true
  php8:
    image: php:8.0-fpm
    volumes:
     - /Users/xcy/docker/nginx/html:/usr/share/nginx/html
    stdin_open: true
    tty: true
  mariadb:
    image: mariadb:10.9.2
    ports:
     - 3306:3306
    environment:
     - MYSQL_ROOT_PASSWORD='123456'
    volumes:
     - /Users/xcy/docker/mysql/db:/var/lib/mysql

默认docker的php-fpm没有pdo_mysql,需要进入容器内运行

docker-php-ext-install pdo-mysql

nginx的配置中php转发可参考

server {
    listen 80;
    listen [::]:80;
    server_name localhost;
    root /usr/share/nginx/html/laravel/public;

    add_header X-Frame-Options "localhost";
    add_header X-Content-Type-Options "nosniff";

    index index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        try_files      $uri =404;
        fastcgi_pass php7:9000;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

留言