{"id":26893551,"url":"https://github.com/dazz/s6-nginx-php-fpm","last_synced_at":"2025-05-12T16:13:19.035Z","repository":{"id":207348363,"uuid":"719026681","full_name":"dazz/s6-nginx-php-fpm","owner":"dazz","description":"Run nginx and php-fpm in one container supervised by s6-overlay","archived":false,"fork":false,"pushed_at":"2024-09-22T07:15:41.000Z","size":27,"stargazers_count":14,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-07T06:10:04.722Z","etag":null,"topics":["docker","nginx","php-fpm","s6-overlay"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dazz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-11-15T09:45:03.000Z","updated_at":"2025-04-03T10:35:29.000Z","dependencies_parsed_at":"2023-11-28T09:27:53.904Z","dependency_job_id":null,"html_url":"https://github.com/dazz/s6-nginx-php-fpm","commit_stats":null,"previous_names":["dazz/s6-nginx-php-fpm"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dazz%2Fs6-nginx-php-fpm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dazz%2Fs6-nginx-php-fpm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dazz%2Fs6-nginx-php-fpm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dazz%2Fs6-nginx-php-fpm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dazz","download_url":"https://codeload.github.com/dazz/s6-nginx-php-fpm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253774281,"owners_count":21962198,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","nginx","php-fpm","s6-overlay"],"created_at":"2025-03-31T23:58:20.254Z","updated_at":"2025-05-12T16:13:18.979Z","avatar_url":"https://github.com/dazz.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# S6 nginx/php-fpm container\n\n\n## usage\n\nThis is a simple container with nginx and php-fpm based on alpine linux.\nTo install all the dependencies and build the container run:\n\n```bash\nmake up\n```\n\n## What is this about\nWe often have the case that we need to deploy our PHP application to `$server`, but since PHP does not come with its own\nwebserver we always run a second container which passes the requests to our PHP process.\nWe looked into many options and decided against them for different reasons.\n\n- **Kubernetes:** Overkill for a PHP-Application\n- **Docker Compose:** Not recommended in production, not well documented\n- **FrankenPHP:** Not stable enough (at the time), written in go, compiles PHP\n- **SupervisorD:** Not recommended for running as PID 1 in a dockerized environment\n- **SystemD:** Not available for alpine (package requires gclib)\n- **s6-overlay:** Works like a charm in ubuntu (glibc) and alpine (musl) and is made for running as PID 1 in container\n\n\n## What are the components\nWe installed just an index file in the `app` directory to showcase a running php application.\n\n- Alpine\n- s6-overlay\n- nginx\n- php-fpm\n\nWe use preconfigured user `www-data` and install the app in `var/www/html`.\n\n## s6-overlay\n- starts PID 1 with `ENTRYPOINT [\"/init\"]`\n- starts all services and scripts that are defined in `/etc/s6-overlay/s6-rc.d/user/contents.d`\n\n## Recipes\nUse cases and how they can be solved using s6\n\n### Feature Flags\nSometimes you need to enable or disable services. \n\n\u003e s6-rc wasn't made for dynamic service sets; it was made for reliability and predictability of the machine state, \n\u003e which runtime changes are bad for - and you're going against its design by attempting to conditionally start services.\n\n\u003e The way to achieve what you want is by making sure that only the services you want to activate are in s6-rc's user \n\u003e bundle, which contains everything that will be started. For that purpose, you have the S6_STAGE2_HOOK environment variable: \n\u003e in it, put the path to a script, and that script will be run before s6-rc analyzes its service set. \n\u003e That script should be the one to read your environment variables, and adjust the files of /etc/s6-overlay/s6-rc.d/user/contents accordingly.\n\n\n```yaml\n# docker-compose.yml\nservices:\n  app:\n    environment:\n      S6_STAGE2_HOOK: /etc/s6-hook/feature-toggle\n      FEATURE_MIGRATIONS_ENABLED: \"false\"\n```\n\n#### /etc/s6-hook/feature-toggle\n```shell\n#!/command/with-contenv sh\n\n# Read environment variable and default to \"false\" if not set\nINIT_MIGRATIONS=\"${FEATURE_MIGRATIONS_ENABLED:-false}\"\n\n# Define a space-separated list of feature toggles (since arrays are not supported in sh)\n# the feature name is the upper SNAKE_CASE version of the feature directory name in lower kebab-case\nfeatures=\"INIT_MIGRATIONS\"\n\n# Iterate through each feature toggle\nfor feature in $features; do\n    # Get the value of the environment variable, default to \"false\" if not set\n    is_enabled=$(eval echo \\${$feature:-false})\n\n    # Convert the feature name to lowercase and replace underscores with hyphens\n    feature_file=$(echo \"$feature\" | tr 'A-Z' 'a-z' | tr '_' '-')\n\n    # Check if the feature is enabled\n    if [ \"$is_enabled\" = \"true\" ]; then\n        touch \"/etc/s6-overlay/s6-rc.d/user/contents.d/$feature_file\"\n    else\n        rm -f \"/etc/s6-overlay/s6-rc.d/user/contents.d/$feature_file\"\n    fi\ndone\n\nexit 0\n```\n\n### Doctrine Migrations\n\n```shell []\n/etc/s6-overlay/s6-rc.d\n├── init-migrations\n│   ├── dependencies.d\n│   │    └── svc-php-fpm\n│   ├── type\n│   └── up\n└── scripts\n        └── init-migrations\n```\n\n```shell []\n#!/command/with-contenv sh\ns6-setuidgid www-data\n\nphp /var/www/html/bin/console doctrine:migrations:migrate --env=`printcontenv APP_ENV` --no-interaction\nphp /var/www/html/bin/console doctrine:migrations:status --env=`printcontenv APP_ENV`\n```\n\n### CronJobs with Symfony Scheduler Component\n\n```shell []\n/etc/s6-overlay/s6-rc.d\n├── svc-scheduler\n│   ├── dependencies.d\n│   │    └── svc-php-fpm\n│   ├── type\n│   └── up\n└── scripts\n        └── svc-scheduler\n```\n\n```shell []\n#!/command/with-contenv sh\ns6-setuidgid www-data\n\nphp /var/www/html/bin/console messenger:consume scheduler_default \\\n  --time-limit=300 \\\n  --limit=10 \\\n  --env=`printcontenv APP_ENV` --quiet\n```\n\n### check requirements in dev\n\n```shell []\n/etc/s6-overlay/s6-rc.d\n├── init-dependencies\n│   ├── dependencies.d\n│   │    ├── base\n│   │    └── svc-php-fpm\n│   ├── type\n│   └── up\n└── scripts\n        └── init-dependencies\n```\n\n```shell []\n#!/command/with-contenv sh\n\n# Check if the composer binary exists\nif command -v composer \u003e/dev/null 2\u003e\u00261; then\n    # Composer is installed, run composer install\n    echo \"init-dependencies: info: Composer found. Checking dependencies.\"\n    composer -d /var/www/html check-platform-reqs\n    exit 0\nfi\necho \"init-dependencies: info: Composer not found. Please install Composer before running this script.\"\nexit 0\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdazz%2Fs6-nginx-php-fpm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdazz%2Fs6-nginx-php-fpm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdazz%2Fs6-nginx-php-fpm/lists"}