### Build and Start Docker Compose Production Environment Source: https://context7.com/dockersamples/laravel-docker-examples/llms.txt Builds and starts the production services using optimized images and multi-stage builds for minimal image sizes. Includes health checks and automatic restarts. ```bash docker compose -f compose.prod.yaml up -d --build ``` -------------------------------- ### Project Directory Structure Source: https://github.com/dockersamples/laravel-docker-examples/blob/main/README.md Illustrates the modular organization of the Laravel Docker Examples Project, separating shared configurations from environment-specific ones. ```bash project-root/ ├── app/ # Laravel app folder ├── ... # Other Laravel files and directories ├── docker/ │ ├── common/ # Shared configurations │ ├── development/ # Development-specific configurations │ ├── production/ # Production-specific configurations ├── compose.dev.yaml # Docker Compose for development ├── compose.prod.yaml # Docker Compose for production └── .env.example # Example environment configuration ``` -------------------------------- ### Clone and Setup Laravel Docker Project Source: https://context7.com/dockersamples/laravel-docker-examples/llms.txt Clone the repository and configure your environment variables. Ensure your UID and GID match your user to avoid permission issues. ```bash git clone https://github.com/rw4lll/laravel-docker-examples.git cd laravel-docker-examples cp .env.example .env # Get your UID and GID id -u # Replace UID=1000 in .env with output id -g # Replace GID=1000 in .env with output ``` -------------------------------- ### Install Laravel Dependencies Source: https://github.com/dockersamples/laravel-docker-examples/blob/main/README.md Execute commands within the workspace container to install Composer and NPM dependencies, and to build frontend assets. ```bash docker compose -f compose.dev.yaml exec workspace bash composer install npm install npm run dev ``` -------------------------------- ### Install Dependencies and Build Assets in Workspace Source: https://context7.com/dockersamples/laravel-docker-examples/llms.txt Installs PHP dependencies using Composer and Node.js dependencies using npm. Builds assets for development or production. ```bash composer install npm install npm run dev # Development build with hot reload on port 5173 npm run build # Production build ``` -------------------------------- ### Start Docker Compose Services Source: https://github.com/dockersamples/laravel-docker-examples/blob/main/README.md Start the Docker Compose services in detached mode using the development configuration file. ```bash docker compose -f compose.dev.yaml up -d ``` -------------------------------- ### Clone Laravel Docker Examples Repository Source: https://github.com/dockersamples/laravel-docker-examples/blob/main/README.md Clones the project repository and navigates into the project directory. This is the first step to setting up the development environment. ```bash git clone https://github.com/rw4lll/laravel-docker-examples.git cd laravel-docker-examples ``` -------------------------------- ### Verify Docker and Docker Compose Installation Source: https://github.com/dockersamples/laravel-docker-examples/blob/main/README.md Checks if Docker and Docker Compose are installed on your system. Ensure these commands return versions before proceeding with setup. ```bash docker --version docker compose version ``` -------------------------------- ### Copy Environment File Source: https://github.com/dockersamples/laravel-docker-examples/blob/main/README.md Copy the example environment file to a new file named .env. Adjust environment variables like UID and GID to match your system's user and group IDs. ```bash cp .env.example .env ``` -------------------------------- ### Multi-Stage PHP-FPM Dockerfile Source: https://context7.com/dockersamples/laravel-docker-examples/llms.txt Illustrates a multi-stage Dockerfile for PHP-FPM. The builder stage installs dependencies, while the production stage includes only runtime requirements. The development stage can optionally add Xdebug. ```dockerfile # Stage 1: Build dependencies FROM php:8.5-fpm AS builder RUN apt-get update && apt-get install -y --no-install-recommends \ curl unzip libpq-dev libicu-dev libzip-dev \ && docker-php-ext-install pdo_pgsql pgsql intl zip bcmath \ && pecl install redis && docker-php-ext-enable redis WORKDIR /var/www COPY . /var/www RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \ && composer install --no-dev --optimize-autoloader # Stage 2: Production (minimal runtime) FROM php:8.5-fpm AS production RUN apt-get update && apt-get install -y --no-install-recommends \ libpq-dev libicu-dev libzip-dev libfcgi-bin procps COPY --from=builder /usr/local/lib/php/extensions/ /usr/local/lib/php/extensions/ COPY --from=builder /var/www /var/www RUN chown -R www-data:www-data /var/www USER www-data CMD ["php-fpm"] ``` -------------------------------- ### Enable Xdebug in Development Dockerfile Source: https://context7.com/dockersamples/laravel-docker-examples/llms.txt This Dockerfile snippet enables Xdebug during the development build stage if the XDEBUG_ENABLED argument is set to 'true'. It installs Xdebug using PECL and enables the extension. ```Dockerfile FROM production AS development ARG XDEBUG_ENABLED=true USER root RUN if [ "${XDEBUG_ENABLED}" = "true" ]; then \ pecl install xdebug && docker-php-ext-enable xdebug; fi USER www-data CMD ["php-fpm"] ``` -------------------------------- ### Clone Your Forked Repository Source: https://github.com/dockersamples/laravel-docker-examples/blob/main/README.md Clone your forked repository to your local machine and navigate into the project directory. ```bash git clone https://github.com/your-user-name/laravel-docker-examples.git cd laravel-docker-examples ``` -------------------------------- ### Configure Xdebug for Development Source: https://context7.com/dockersamples/laravel-docker-examples/llms.txt Sets up Xdebug in the development environment for debugging, code coverage, and profiling. Ensure your IDE is configured to listen on the specified IDE key. ```bash # .env file Xdebug configuration XDEBUG_ENABLED=true XDEBUG_MODE=develop,coverage,debug,profile XDEBUG_HOST=host.docker.internal XDEBUG_IDE_KEY=DOCKER ``` ```bash # Rebuild PHP-FPM with Xdebug settings docker compose -f compose.dev.yaml up -d --build php-fpm workspace ``` ```bash # Verify Xdebug is enabled docker compose -f compose.dev.yaml exec workspace php -m | grep xdebug # Expected: xdebug ``` ```bash # Run tests with code coverage docker compose -f compose.dev.yaml exec workspace php artisan test --coverage ``` -------------------------------- ### Commit Your Changes Source: https://github.com/dockersamples/laravel-docker-examples/blob/main/README.md Stage and commit your changes with a descriptive message. ```bash git commit -m "Description of changes" ``` -------------------------------- ### View Docker Logs Source: https://github.com/dockersamples/laravel-docker-examples/blob/main/README.md Follow the logs of all services defined in the Docker Compose file. Use 'web' to view logs for a specific service. ```bash docker compose -f compose.dev.yaml logs -f ``` ```bash docker compose -f compose.dev.yaml logs -f web ``` -------------------------------- ### Configure Environment Variables Source: https://context7.com/dockersamples/laravel-docker-examples/llms.txt Defines essential environment variables for application settings, database connections, and Redis configuration. It also includes UID/GID synchronization for development to prevent permission issues. ```bash # .env configuration for Docker environment APP_NAME=Laravel APP_ENV=local APP_DEBUG=true APP_URL=http://localhost # PostgreSQL database (uses 'postgres' service name as host) DB_CONNECTION=pgsql DB_HOST=postgres DB_PORT=5432 DB_DATABASE=app DB_USERNAME=laravel DB_PASSWORD=secret # Redis cache and queue (uses 'redis' service name as host) CACHE_STORE=redis QUEUE_CONNECTION=redis REDIS_HOST=redis REDIS_PORT=6379 # User/Group ID sync for development (prevents permission issues) UID=1000 # Output of: id -u GID=1000 # Output of: id -g ``` -------------------------------- ### Push to Your Fork Source: https://github.com/dockersamples/laravel-docker-examples/blob/main/README.md Push your local branch to your forked repository on GitHub. ```bash git push origin feature-branch ``` -------------------------------- ### Clear and Cache Configurations and Routes Source: https://context7.com/dockersamples/laravel-docker-examples/llms.txt Clears existing configurations and routes, then caches them for improved performance. Useful after making changes to configuration files or routes. ```bash php artisan config:clear php artisan config:cache php artisan route:cache ``` -------------------------------- ### Manage Docker Container Lifecycle Source: https://context7.com/dockersamples/laravel-docker-examples/llms.txt Provides commands for managing Docker containers, including viewing logs, rebuilding services, stopping containers, and removing images. Use with caution when removing volumes or images. ```bash # View logs for all services docker compose -f compose.dev.yaml logs -f ``` ```bash # View logs for specific service docker compose -f compose.dev.yaml logs -f web docker compose -f compose.dev.yaml logs -f php-fpm ``` ```bash # Rebuild containers after Dockerfile changes docker compose -f compose.dev.yaml up -d --build ``` ```bash # Rebuild specific service only docker compose -f compose.dev.yaml up -d --build php-fpm ``` ```bash # Stop all containers docker compose -f compose.dev.yaml down ``` ```bash # Stop and remove volumes (WARNING: deletes database data) docker compose -f compose.dev.yaml down -v ``` ```bash # Remove all images to force fresh build docker compose -f compose.dev.yaml down --rmi all ``` -------------------------------- ### Run Laravel Migrations Source: https://github.com/dockersamples/laravel-docker-examples/blob/main/README.md Execute the Artisan migrate command within the workspace container to apply database migrations. ```bash docker compose -f compose.dev.yaml exec workspace php artisan migrate ``` -------------------------------- ### Run Laravel Artisan Commands from Workspace Source: https://context7.com/dockersamples/laravel-docker-examples/llms.txt Executes common Laravel Artisan commands such as migrations, seeding, model generation, and running tests within the workspace container. ```bash php artisan migrate php artisan migrate --step -v php artisan migrate:rollback php artisan db:seed php artisan make:model Product -mc php artisan test ``` -------------------------------- ### Rebuild Docker Containers Source: https://github.com/dockersamples/laravel-docker-examples/blob/main/README.md Rebuild the Docker images and restart the services in detached mode. ```bash docker compose -f compose.dev.yaml up -d --build ``` -------------------------------- ### Create a New Git Branch Source: https://github.com/dockersamples/laravel-docker-examples/blob/main/README.md Create a new branch for your feature or bug fix. ```bash git checkout -b your-feature-branch ``` -------------------------------- ### Execute Artisan Commands via Docker Compose Exec Source: https://context7.com/dockersamples/laravel-docker-examples/llms.txt Runs Laravel Artisan commands directly from the host machine by executing them within the workspace container using `docker compose exec`. ```bash docker compose -f compose.dev.yaml exec workspace php artisan migrate docker compose -f compose.dev.yaml exec workspace php artisan migrate --step -v docker compose -f compose.dev.yaml exec workspace php artisan migrate:rollback docker compose -f compose.dev.yaml exec workspace php artisan db:seed docker compose -f compose.dev.yaml exec workspace php artisan make:model Product -mc docker compose -f compose.dev.yaml exec workspace php artisan test ``` -------------------------------- ### Check Application Health Endpoint Source: https://context7.com/dockersamples/laravel-docker-examples/llms.txt Verifies the health of the application by checking connectivity to database, Redis, and storage. Returns HTTP 200 if healthy, 503 if any service fails. ```bash curl http://localhost/health ``` -------------------------------- ### Access Workspace Container Source: https://github.com/dockersamples/laravel-docker-examples/blob/main/README.md Open a bash shell inside the workspace container, which contains development tools like Composer and Node.js. ```bash docker compose -f compose.dev.yaml exec workspace bash ``` -------------------------------- ### Production Nginx Configuration Source: https://context7.com/dockersamples/laravel-docker-examples/llms.txt Configures Nginx as a production web server, proxying requests to PHP-FPM and serving static files. It routes all non-static requests through Laravel's front controller. ```nginx events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; root /var/www/public; index index.php index.html; # Try static files first, then route to Laravel location / { try_files $uri $uri/ /index.php?$query_string; } # PHP-FPM proxy for .php files location ~ \.php$ { fastcgi_pass php-fpm:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } } ``` -------------------------------- ### Stop Docker Containers Source: https://github.com/dockersamples/laravel-docker-examples/blob/main/README.md Stop and remove all containers, networks, and volumes defined in the Docker Compose file. ```bash docker compose -f compose.dev.yaml down ``` -------------------------------- ### Check Production Service Health Status Source: https://context7.com/dockersamples/laravel-docker-examples/llms.txt Lists the status of services in the production environment, including their health status. Useful for verifying that all services are running correctly. ```bash docker compose -f compose.prod.yaml ps ``` -------------------------------- ### Check PHP-FPM Health Source: https://context7.com/dockersamples/laravel-docker-examples/llms.txt Executes a health check script directly within the PHP-FPM container to verify its status. Use this to manually check the container's health. ```bash docker compose -f compose.prod.yaml exec php-fpm php-fpm-healthcheck ``` ```bash # Expected output (healthy): # Pool status: www # Processes: active 1, idle 1, total 2 ``` ```bash # View container health in docker docker inspect --format='{{.State.Health.Status}}' php-fpm # Expected: healthy ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.