Setting Up an LNMP Development Environment with Docker on Windows

Installing Docker Desktop on Windows

Download Docker Desktop from the offiical website. Verify system compatibility before installation as prerequisites are critical.

Note: Enabling Hyper-V may conflict with VMware. Use the following commands to manage Hyper-V, requiring a system restart:

:: Disable Hyper-V
bcdedit /set hypervisorlaunchtype off

:: Enable Hyper-V
bcdedit /set hypervisorlaunchtype auto

Pulling Required Docker Images

Obtain the latest images for Nginx, PHP, MySQL, and Redis:

docker pull nginx:latest
docker pull php:8.1-fpm
docker pull mysql:8.0
docker pull redis:latest

Preparing Configuration Files

Organize host directories for container configurations. Example structure:

E:\docker\etc
├── mysql
├── nginx
└── php

Nginx Configuration:

docker run --name temp-nginx -d nginx
docker cp temp-nginx:/etc/nginx E:\docker\etc\nginx
docker rm -f temp-nginx

PHP Configuration:

docker run --name temp-php -d php:8.1-fpm
docker cp temp-php:/usr/local/etc E:\docker\etc\php
docker rm -f temp-php

MySQL Directory Setup:

cd E:\docker\etc\mysql
mkdir conf logs data

Launching Containers with Dependencies

Start containers in order due to dependency links:

  1. MySQL
  2. Redis
  3. PHP-FPM
  4. Nginx

MySQL Container:

docker run --name mysql-server -p 33060:3306 \
-e MYSQL_ROOT_PASSWORD=root \
-v E:\docker\etc\mysql\conf:/etc/mysql/conf.d \
-v E:\docker\etc\mysql\logs:/logs \
-v E:\docker\etc\mysql\data:/var/lib/mysql \
-d mysql:8.0

Redis Container:

docker run --name redis-server -p 6379:6379 -d redis:latest

PHP-FPM Container:

docker run --name php-fpm \
-v E:\project:/var/www/html \
-v E:\docker\etc\php:/usr/local/etc \
-v E:\docker\log\php:/var/log/php \
--link redis-server:redis \
--link mysql-server:mysql \
-d php:8.1-fpm

Nginx Container:

docker run --name nginx-server -p 8080:80 \
-v E:\project:/usr/share/nginx/html \
-v E:\docker\etc\nginx:/etc/nginx \
-v E:\docker\log\nginx:/var/log/nginx \
--link php-fpm:php \
-d nginx:latest

Testing the Deployment

Modify default.conf in E:\docker\etc\nginx\conf.d:

server {
    listen 80;
    server_name localhost;

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

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        root html;
        fastcgi_pass php:9000; # Matches linked PHP container alias
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /var/www/html/LaravelAdmin/public$fastcgi_script_name;
        include fastcgi_params;
    }
}

Resolve "Primary script unknown" errors by ensuring SCRIPT_FILENAME points to the correct public directory within the PHP container's filesystem.

Tags: docker Windows LNMP nginx PHP

Posted on Fri, 30 Oct 2026 16:09:17 +0000 by jtacon