### Setup Project Dependencies Source: https://github.com/serversideup/docker-php/blob/main/docs/README.md These commands guide you through the initial setup of the project. It includes navigating to the correct directory, copying environment variables, and installing necessary dependencies using yarn. ```bash cd docs/ ``` ```bash cp .env.example .env ``` ```bash yarn install ``` -------------------------------- ### Dockerfile Example Using Helper Commands Source: https://context7.com/serversideup/docker-php/llms.txt An example Dockerfile demonstrating the use of serversideup/php helper commands. It shows how to install system packages and PHP extensions, set user and file permissions, and copy application code into the image. This approach allows for reproducible builds with consistent configurations. ```dockerfile FROM serversideup/php:8.5-fpm-nginx USER root # Install system packages (works on both Alpine and Debian) RUN docker-php-serversideup-dep-install-debian git RUN docker-php-serversideup-dep-install-alpine git # Install PHP extensions RUN install-php-extensions intl bcmath # Set file permissions ARG USER_ID=1000 ARG GROUP_ID=1000 RUN docker-php-serversideup-set-id www-data ${USER_ID}:${GROUP_ID} && \ docker-php-serversideup-set-file-permissions --owner ${USER_ID}:${GROUP_ID} USER www-data COPY --chown=www-data:www-data . /var/www/html ``` -------------------------------- ### Initialize and Run Documentation Locally Source: https://github.com/serversideup/docker-php/blob/main/docs/AGENTS.md Commands to install dependencies and start the local development server for the documentation project. This assumes the user is in the root of the documentation directory. ```bash cd docs/ yarn install yarn dev ``` -------------------------------- ### Install PHP Extensions using install-php-extensions (Dockerfile) Source: https://github.com/serversideup/docker-php/blob/main/docs/content/docs/1.getting-started/4.these-images-vs-others.md This Dockerfile example illustrates how to install multiple PHP extensions, including bcmath, imagick, and mongodb, using the pre-installed `install-php-extensions` script. This method simplifies the process of adding necessary extensions to the PHP environment. ```dockerfile FROM serversideup/php:8.5-cli # Switch to root to install extensions USER root # Install any PHP extension easily RUN install-php-extensions bcmath imagick mongodb ``` -------------------------------- ### Install PHP Extensions using Dockerfile Source: https://context7.com/serversideup/docker-php/llms.txt Install additional PHP extensions in a Dockerfile for the `serversideup/php` image using the `install-php-extensions` tool. This example installs `intl`, `bcmath`, `gd`, `imagick`, and `redis`. ```dockerfile # Dockerfile FROM serversideup/php:8.5-fpm-nginx # Switch to root to install extensions USER root # Install extensions (supports 100+ extensions) RUN install-php-extensions intl bcmath gd imagick redis # Drop back to unprivileged user USER www-data ``` -------------------------------- ### Create a Production Dockerfile Source: https://github.com/serversideup/docker-php/blob/main/docs/content/docs/4.deployment-and-production/3.packaging-your-app-for-deployment.md Demonstrates how to build a production-ready image by copying application code into the container and installing necessary PHP extensions. ```dockerfile FROM serversideup/php:8.5-fpm-nginx USER root RUN install-php-extensions intl bcmath USER www-data COPY --chown=www-data:www-data . /var/www/html ``` -------------------------------- ### Install PHP Extensions Source: https://github.com/serversideup/docker-php/blob/main/docs/content/docs/8.reference/2.command-reference.md Installs PHP extensions using a simplified command, acting as a wrapper for the official `docker-php-ext-install` command. It allows for easy installation of extensions like 'intl'. ```bash install-php-extensions intl ``` -------------------------------- ### Check Docker Installation Source: https://github.com/serversideup/docker-php/blob/main/docs/content/docs/1.getting-started/3.installation.md Verifies that Docker and Docker Compose are installed and configured correctly on your system by checking their versions. ```bash docker --version docker compose version ``` -------------------------------- ### Run Artisan Commands in Entrypoint Source: https://github.com/serversideup/docker-php/blob/main/docs/content/docs/6.customizing-the-image/3.adding-your-own-start-up-scripts.md An advanced startup script example that checks for the existence of an artisan file before executing a custom Laravel command. ```bash #!/bin/sh # Check if the artisan file exists if [ -f "$APP_BASE_DIR/artisan" ]; then # Run the custom artisan command php "$APP_BASE_DIR/artisan" my:custom-command else # If the artisan file is not found, stop the container echo "❌ Artisan file not found in $APP_BASE_DIR" exit 1 fi # Exit with a success code exit 0 ``` -------------------------------- ### Run a test web server with Docker Source: https://github.com/serversideup/docker-php/blob/main/docs/content/docs/1.getting-started/99.contributing.md Starts a temporary Docker container using the serversideup/php image to serve the current directory on ports 80 and 443. ```bash docker run --rm -v $(pwd):/var/www/html -p 80:8080 -p 443:8443 serversideup/php:8.4-fpm-nginx ``` -------------------------------- ### Run Development Server Source: https://github.com/serversideup/docker-php/blob/main/docs/README.md Starts the local development server for the project, allowing for real-time updates and testing. The server is typically accessible at http://localhost:3000. ```bash yarn dev ``` -------------------------------- ### Install PHP Extension Installer Source: https://github.com/serversideup/docker-php/blob/main/docs/content/docs/8.reference/2.command-reference.md Installs the PHP extension installer script for a specified version. This is an internal helper script to simplify the installation process of PHP extensions. ```bash # Usage: docker-php-serversideup-install-php-ext-installer [version] docker-php-serversideup-install-php-ext-installer 2.2.0 ``` -------------------------------- ### Apply Docker Production Best Practices Source: https://github.com/serversideup/docker-php/blob/main/docs/content/docs/4.deployment-and-production/3.packaging-your-app-for-deployment.md Examples of proper image tagging, non-root user execution, and avoiding hardcoded secrets in Dockerfiles. ```dockerfile # Use specific versions FROM serversideup/php:8.5-fpm-nginx # Ensure non-root user USER www-data # Do not bake secrets into ENV ``` -------------------------------- ### Install PHP Extensions in Dockerfile Source: https://github.com/serversideup/docker-php/blob/main/docs/content/docs/6.customizing-the-image/2.installing-additional-php-extensions.md This Dockerfile snippet demonstrates how to install PHP extensions like 'intl' and 'bcmath'. It switches to the root user to execute the 'install-php-extensions' command and then switches back to the unprivileged 'www-data' user. This is a common pattern for hardening Docker images. ```dockerfile FROM serversideup/php:8.5-fpm-nginx USER root RUN install-php-extensions intl bcmath USER www-data ``` -------------------------------- ### Start PHP Application with Docker Compose Source: https://github.com/serversideup/docker-php/blob/main/docs/content/docs/1.getting-started/3.installation.md Launches the PHP application defined in the 'compose.yml' file using Docker Compose, making it accessible via localhost. ```bash docker compose up ``` -------------------------------- ### Helper Commands for PHP Image Customization Source: https://context7.com/serversideup/docker-php/llms.txt A collection of bash commands provided by serversideup/php images to assist in customizing the environment. These include installing PHP extensions, setting file permissions, configuring user/group IDs, and installing system packages on both Alpine and Debian-based systems. ```bash # Install PHP extensions install-php-extensions intl bcmath gd # Set file permissions (run as root) docker-php-serversideup-set-file-permissions --owner 1000:1000 # Set user/group ID for www-data (run as root) docker-php-serversideup-set-id www-data 1000:1000 # Install packages on Alpine (auto-detects OS) docker-php-serversideup-dep-install-alpine git curl # Install packages on Debian (auto-detects OS) docker-php-serversideup-dep-install-debian git curl ``` -------------------------------- ### Run FrankenPHP with Docker CLI Source: https://github.com/serversideup/docker-php/blob/main/docs/content/docs/2.image-variations/frankenphp.md Starts a FrankenPHP container using the Docker CLI, mapping local ports and mounting the current directory to the webroot. ```bash docker run -p 80:8080 -v $(pwd):/var/www/html/public serversideup/php:8.5-frankenphp ``` -------------------------------- ### Define Docker Compose Service Source: https://github.com/serversideup/docker-php/blob/main/docs/content/docs/6.customizing-the-image/3.adding-your-own-start-up-scripts.md Example configuration for running the containerized application using Docker Compose. ```yaml services: php: build: context: . dockerfile: Dockerfile ports: - 80:8080 volumes: - .:/var/www/html ``` -------------------------------- ### Configure PHP Settings with Docker CLI Environment Variables Source: https://github.com/serversideup/docker-php/blob/main/docs/content/docs/6.customizing-the-image/1.changing-common-php-settings.md This example shows how to set PHP configuration options, such as DATE_TIMEZONE, directly from the command line when running a Docker container. This is useful for quick adjustments or when not using a compose file. ```bash docker run -d \ -p 80:8080 \ -v $(pwd):/var/www/html \ -e PHP_DATE_TIMEZONE="America/New_York" \ serversideup/php:8.2.12-fpm-nginx-bookworm ``` -------------------------------- ### Package Application Code into Docker Image Source: https://context7.com/serversideup/docker-php/llms.txt Build a production-ready Docker image with your application code baked in. This involves creating a Dockerfile that installs necessary PHP extensions and copies your application code into the image with correct ownership. ```dockerfile # Dockerfile FROM serversideup/php:8.5-fpm-nginx USER root # Install any needed PHP extensions RUN install-php-extensions intl bcmath redis USER www-data # Copy application code with correct ownership COPY --chown=www-data:www-data . /var/www/html ``` -------------------------------- ### Build Docker Image with PHP Extensions using Docker Compose Source: https://github.com/serversideup/docker-php/blob/main/docs/content/docs/6.customizing-the-image/2.installing-additional-php-extensions.md This example shows how to configure Docker Compose to build a Docker image that includes custom PHP extensions. It specifies the Dockerfile context and then defines the service, including port mappings and volume mounts. A simple PHP file is included to demonstrate functionality. ```dockerfile # Choose our base image FROM serversideup/php:8.5-fpm-nginx # Switch to root so we can do root things USER root # Install the intl and bcmath extensions with root permissions RUN install-php-extensions intl bcmath # Drop back to our unprivileged user USER www-data ``` ```yaml services: php: # Use "build" instead of "image" build: # Use the Dockerfile in the current directory context: . dockerfile: Dockerfile # Expose localhost:80 to NGINX's port 8080 ports: - 80:8080 # Mount current directory to /var/www/html volumes: - ./:/var/www/html ``` ```php ``` -------------------------------- ### Build Docker Image with Custom PHP Extensions Source: https://context7.com/serversideup/docker-php/llms.txt Build a Docker image using a custom Dockerfile that includes additional PHP extensions. This example shows the Dockerfile and the corresponding Docker Compose configuration to build and run the image. ```yaml # compose.yml services: php: build: context: . dockerfile: Dockerfile ports: - 80:8080 volumes: - ./:/var/www/html ``` ```bash # Build with the custom Dockerfile docker compose up --build ``` -------------------------------- ### Configure FPM-Apache with Docker Compose Source: https://github.com/serversideup/docker-php/blob/main/docs/content/docs/2.image-variations/fpm-apache.md Defines a service using the FPM-Apache image with port mappings and environment variables for OPcache and SSL. This setup is recommended for consistent local development and production environments. ```yaml services: php: image: serversideup/php:8.5-fpm-apache ports: - "80:8080" - "443:8443" volumes: - ./:/var/www/html environment: PHP_OPCACHE_ENABLE: "1" SSL_MODE: "full" ``` -------------------------------- ### Define Custom NGINX Server Directives Source: https://github.com/serversideup/docker-php/blob/main/docs/content/docs/2.image-variations/fpm-nginx.md An example of NGINX configuration syntax for adding custom headers, defining location blocks for API endpoints, and implementing rate limiting. ```nginx add_header X-Custom-Header "My Value" always; location /api { try_files $uri $uri/ /index.php?$query_string; client_max_body_size 50M; } limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s; location /api/ { limit_req zone=api burst=20 nodelay; } ``` -------------------------------- ### Configure Nuxt UI App Settings Source: https://github.com/serversideup/docker-php/blob/main/docs/AGENTS.md Example of configuring Nuxt application settings with line highlighting. This snippet demonstrates how to define icon mappings within the nuxt.config.ts file. ```typescript export default defineAppConfig({ ui: { icons: { copy: 'i-lucide-copy', copyCheck: 'i-lucide-copy-check' } } }) ``` -------------------------------- ### Build and Run Docker Compose with Custom PHP Extensions Source: https://github.com/serversideup/docker-php/blob/main/docs/content/docs/6.customizing-the-image/2.installing-additional-php-extensions.md This bash command builds a Docker image with the specified PHP extensions using Docker Compose and then starts the containers. The `--build` flag ensures that the image is rebuilt from the Dockerfile, which is useful when making changes to the Dockerfile. ```bash docker compose up --build ``` -------------------------------- ### Switching User in Dockerfile for Permissions Source: https://github.com/serversideup/docker-php/blob/main/docs/content/docs/7.troubleshooting/1.common-issues.md This Dockerfile snippet demonstrates how to switch to the root user to perform privileged operations like installing system packages and then switch back to the non-root user (www-data) for security. It's crucial for resolving build-time permission issues. ```dockerfile FROM serversideup/php:8.5-fpm-nginx USER root # Install system packages RUN install-php-extensions intl bcmath # Switch back to www-data USER www-data ``` -------------------------------- ### Integrate Custom php.ini into Dockerfile Source: https://github.com/serversideup/docker-php/blob/main/docs/content/docs/6.customizing-the-image/1.changing-common-php-settings.md This Dockerfile example shows how to copy a custom php.ini file into the PHP container's configuration directory, ensuring that the custom settings are applied upon container startup. It also includes an option to remove default configuration files if necessary. ```dockerfile FROM serversideup/php:8.5-fpm-nginx-bookworm COPY zzz-custom-php.ini /usr/local/etc/php/conf.d/ ``` ```dockerfile FROM serversideup/php:8.5-fpm-nginx-bookworm RUN rm /usr/local/etc/php/conf.d/serversideup-docker-php.ini COPY zzz-custom-php.ini /usr/local/etc/php/conf.d/ ``` -------------------------------- ### Run FPM-Apache Container via Docker CLI Source: https://github.com/serversideup/docker-php/blob/main/docs/content/docs/2.image-variations/fpm-apache.md Starts a single container instance of the FPM-Apache image mapping host port 80 to container port 8080. It mounts the current directory to the web root for immediate application serving. ```bash docker run -p 80:8080 -v $(pwd):/var/www/html/public serversideup/php:8.5-fpm-apache ``` -------------------------------- ### Create Sample PHP Project Structure Source: https://github.com/serversideup/docker-php/blob/main/docs/content/docs/1.getting-started/3.installation.md Sets up a basic directory structure for a PHP project, including a 'public' directory for web-accessible files. ```bash mkdir -p my-php-project/public cd my-php-project ``` -------------------------------- ### Health Checks for Laravel Octane with FrankenPHP Source: https://context7.com/serversideup/docker-php/llms.txt Configuration for health checks when using Laravel Octane with FrankenPHP. This example specifies the FrankenPHP image and command, and utilizes a dedicated `healthcheck-octane` command for monitoring the application's health, with a shorter start period suitable for Octane applications. ```yaml services: php: image: serversideup/php:8.5-frankenphp command: ["php", "artisan", "octane:start", "--server=frankenphp", "--port=8080"] healthcheck: test: ["CMD", "healthcheck-octane"] start_period: 10s ``` -------------------------------- ### Configure Health Checks for PHP Containers Source: https://context7.com/serversideup/docker-php/llms.txt This section provides examples of configuring health checks for PHP containers in Docker Compose. It shows how to set a custom health check path using an environment variable and defines the test, interval, timeout, retries, and start period for the health check. ```yaml services: php: image: serversideup/php:8.5-fpm-nginx environment: # Default health check path HEALTHCHECK_PATH: "/healthcheck" # For Laravel, use the built-in /up endpoint # HEALTHCHECK_PATH: "/up" healthcheck: test: ["CMD", "curl", "-f", "http://localhost:8080/healthcheck"] interval: 30s timeout: 10s retries: 3 start_period: 40s ``` -------------------------------- ### Configure S6 Overlay Services in Dockerfile Source: https://github.com/serversideup/docker-php/blob/main/docs/content/docs/6.customizing-the-image/3.adding-your-own-start-up-scripts.md Demonstrates how to copy one-shot scripts and long-running services into a Docker image, then use the docker-php-serversideup-s6-init script to automate dependency management for S6 Overlay. ```dockerfile FROM serversideup/php:8.5-fpm-nginx USER root COPY --chmod=755 ./entrypoint.d/ /etc/entrypoint.d/ RUN docker-php-serversideup-s6-init COPY --chmod=755 ./my-s6-service/ /etc/s6-overlay/s6-rc.d/my-s6-service/ USER www-data ``` -------------------------------- ### Install Laravel Octane via Terminal Source: https://github.com/serversideup/docker-php/blob/main/docs/content/docs/3.framework-guides/1.laravel/octane.md Command to install the Laravel Octane package into an existing Laravel project using Docker Compose. ```bash docker compose run php composer require laravel/octane ``` -------------------------------- ### Install Debian Packages Source: https://github.com/serversideup/docker-php/blob/main/docs/content/docs/8.reference/2.command-reference.md Installs specified packages on Debian-based systems. This command is beneficial for Dockerfiles that target multiple operating systems. It relies on the Debian package manager. ```bash # Usage: docker-php-serversideup-dep-install-debian [debian-packages] docker-php-serversideup-dep-install-debian git ``` -------------------------------- ### Configure PHP via Environment Variables Source: https://github.com/serversideup/docker-php/blob/main/docs/content/docs/1.getting-started/2.container-basics.md Demonstrates how to adjust PHP runtime settings like upload limits and OPcache status using environment variables in the compose file. ```yaml environment: PHP_UPLOAD_MAX_FILE_SIZE: "500M" PHP_OPCACHE_ENABLE: "1" ``` -------------------------------- ### Install Alpine Packages Source: https://github.com/serversideup/docker-php/blob/main/docs/content/docs/8.reference/2.command-reference.md Installs specified packages on Alpine-based systems. It's useful for Dockerfiles that build on multiple operating systems. Dependencies include the Alpine package manager. ```bash # Usage: docker-php-serversideup-dep-install-alpine [alpine-packages] docker-php-serversideup-dep-install-alpine git ``` -------------------------------- ### Configure Dockerfile for Custom Scripts Source: https://github.com/serversideup/docker-php/blob/main/docs/content/docs/6.customizing-the-image/3.adding-your-own-start-up-scripts.md Shows how to copy local startup scripts into the container and ensure they have the correct permissions (755) to be executed. ```dockerfile FROM serversideup/php:8.5-fpm-nginx # Copy our scripts as executable COPY --chmod=755 ./entrypoint.d/ /etc/entrypoint.d/ ``` -------------------------------- ### Create Custom Entrypoint Script Source: https://github.com/serversideup/docker-php/blob/main/docs/content/docs/6.customizing-the-image/3.adding-your-own-start-up-scripts.md A basic shell script designed to run during container initialization. It must be executable and placed in the /etc/entrypoint.d directory. ```bash #!/bin/sh echo "👋 Hello, world!" ``` -------------------------------- ### Full Laravel Production Stack with Docker Compose Source: https://context7.com/serversideup/docker-php/llms.txt A comprehensive Docker Compose setup for a full Laravel production stack. It includes services for PHP (FPM/Nginx), MariaDB, and Redis, along with configurations for queue workers and schedulers. Environment variables are used extensively for zero-configuration setup, including SSL mode, OPcache, memory limits, and automated tasks like migrations. ```yaml services: php: image: serversideup/php:8.5-fpm-nginx ports: - "80:8080" - "443:8443" volumes: - .:/var/www/html environment: SSL_MODE: "full" PHP_OPCACHE_ENABLE: "1" PHP_MEMORY_LIMIT: "512M" AUTORUN_ENABLED: "true" AUTORUN_LARAVEL_MIGRATION_ISOLATION: "true" depends_on: - mariadb - redis mariadb: image: mariadb:11 environment: MYSQL_ROOT_PASSWORD: rootpassword MYSQL_DATABASE: laravel MYSQL_USER: laravel MYSQL_PASSWORD: laravel volumes: - db_data:/var/lib/mysql redis: image: redis:alpine command: redis-server --appendonly yes volumes: - redis_data:/data # Queue worker queue: image: serversideup/php:8.5-cli volumes: - .:/var/www/html command: ["php", "artisan", "queue:work", "--sleep=3", "--tries=3"] depends_on: - mariadb - redis # Scheduler scheduler: image: serversideup/php:8.5-cli volumes: - .:/var/www/html command: ["php", "artisan", "schedule:work"] depends_on: - mariadb - redis volumes: db_data: redis_data: ``` -------------------------------- ### Preview Production Build Source: https://github.com/serversideup/docker-php/blob/main/docs/README.md Locally previews the production build of the application. This is useful for testing the production environment before actual deployment. ```bash yarn preview ``` -------------------------------- ### Build and Test Production Docker Images Source: https://github.com/serversideup/docker-php/blob/main/docs/content/docs/4.deployment-and-production/3.packaging-your-app-for-deployment.md Commands to build the custom application image and run it using a production-specific Docker Compose configuration. ```bash docker build -t my-app:latest . docker compose -f compose.prod.yml up ``` ```yaml services: php: image: my-app:latest ports: - 80:8080 ``` -------------------------------- ### Sample PHP Index File Source: https://github.com/serversideup/docker-php/blob/main/docs/content/docs/1.getting-started/3.installation.md A simple PHP file that outputs the output of the phpinfo() function, useful for verifying PHP configuration and version. ```php ``` -------------------------------- ### Implement Image Versioning Strategies Source: https://github.com/serversideup/docker-php/blob/main/docs/content/docs/4.deployment-and-production/3.packaging-your-app-for-deployment.md Various methods for tagging Docker images to track deployments, including git SHAs, semantic versioning, and build timestamps. ```bash docker build -t my-app:$(git rev-parse --short HEAD) . docker build -t my-app:1.2.3 . docker build -t my-app:2024-10-31-build-42 . ``` -------------------------------- ### Configure Docker PHP Service in Docker Compose Source: https://github.com/serversideup/docker-php/blob/main/docs/content/docs/1.getting-started/7.upgrade-guide.md Basic configuration for a PHP service using the serversideup/php image. This snippet demonstrates how to define the image tag for a standard FPM-NGINX setup. ```yaml services: php: image: serversideup/php:8.5-fpm-nginx ```