{"id":16320433,"url":"https://github.com/tuupola/php-docker-k8s","last_synced_at":"2025-07-07T12:03:07.696Z","repository":{"id":65838543,"uuid":"575432404","full_name":"tuupola/php-docker-k8s","owner":"tuupola","description":"Examples how to run PHP with Docker and Kubernetes","archived":false,"fork":false,"pushed_at":"2023-03-04T10:17:34.000Z","size":65,"stargazers_count":15,"open_issues_count":1,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-18T15:11:53.557Z","etag":null,"topics":["docker","kubernetes","kustomize","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","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/tuupola.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-07T13:57:33.000Z","updated_at":"2025-01-09T07:15:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"579b5a98-2e9d-4836-a8e7-bd34c2b49da7","html_url":"https://github.com/tuupola/php-docker-k8s","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuupola%2Fphp-docker-k8s","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuupola%2Fphp-docker-k8s/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuupola%2Fphp-docker-k8s/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuupola%2Fphp-docker-k8s/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tuupola","download_url":"https://codeload.github.com/tuupola/php-docker-k8s/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245022943,"owners_count":20548624,"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","kubernetes","kustomize","php"],"created_at":"2024-10-10T22:44:19.280Z","updated_at":"2025-03-22T21:32:12.545Z","avatar_url":"https://github.com/tuupola.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP with Docker and Kubernetes\n\n![Docker + Kubernetes](https://www.appelsiini.net/img/docker-kubernetes.png)\n\nExamples how to run [Slim Framework](https://www.slimframework.com/) with Docker and Kubernetes. Same setups should work with any PHP application. Subfolders have their own more specific README.\n\n## Setups\n### Apache + MariaDB\n\n[The simplest possible setup](apache/). PHP 8.1 as Apache an module and MariaDB in separate containers. This setup also has a Kubernetes and Kustomize example.\n\n### NGINX + PHP-FPM + MariaDB\n\n[The fashionable setup](nginx-phpfpm/). PHP 8.1 as PHP-FPM reverse proxied by NGINX and MariaDB as database. All in separate containers. This setup also has a Kubernetes example.\n\n### Caddy + Apache + MariaDB\n\n[Modern simple setup](caddy-apache/). Caddy as a reverse proxy in front of PHP 8.1 as an Apache module and MariaDB as the database. All in separate containers. With Docker Caddy handles TLS automatically. There is no Kubernetes example. With Kubernetes you would use ingress instead of manually installed Caddy.\n\n\n### Caddy + PHP-FPM + MariaDB\n\n[Modern setup](caddy-phpfpm/). PHP 8.1 as PHP-FPM reverse proxied by Caddy and MariaDB as database. All in separate containers. With Docker Caddy handles TLS automatically. TODO: add Kubernetes example.\n\n### Traefik + Apache + MariaDB\n\n[Enterprisey setup](traefik-apache/). Traefik as reverse proxy in front of PHP 8.1 as Apache an module and MariaDB as the database. With Docker Traefik handles TLS automatically. There is no Kubernetes example. With Kubernetes you would use ingress instead of manually installed Traefik.\n\n## Docker Compose\n\nUse docker compose for development. The application source is bindmounted into the container so edits can be seen instantly.\n\n```\n$ docker compose up --build\n```\n\n## Docker Stack\n\nDocker stack is usually used for deployment into a swarm. Although you could use it also for development. To use Docker stack you must have initialised a [Docker swarm](https://docs.docker.com/engine/swarm/) before deploying.\n\n```\n$ docker swarm init\n$ docker stack deploy -c stack.yaml slim\n```\n\n## Kubernetes\n\n### Manifests\n\nVanilla manifests are the simplest way to create Kubernetes deployments. If an example supports Kubernetes manifests it will have a file named `deployment.yaml`.\n\n```\n$ kubectl apply -f deployment.yaml\n```\n\n### Kustomize\n\n[Kustomize](https://kustomize.io/) provides more robust way of deploying applications to Kubernetes. If an example supports Kustomize it will have a subfolder named `kustomize`.\n\n```\n$ kubectl apply -k kustomize\n```\n\nYou can also deploy alternative production or staging configurations. These are just examples on how to use Kustomize. Only difference between production and staging deployments is the number of replicas.\n\n```\n$ kubectl apply -k kustomize/overlays/production\n$ kubectl apply -k kustomize/overlays/staging\n```\n\nIf you have the standalone kustomize binary installed, you can also see the generated manifests with the following.\n\n```\n$ kustomize build kustomize\n$ kustomize build kustomize/overlays/production\n$ kustomize build kustomize/overlays/staging\n```\n\n### Ingress\n\nSince Kubernetes does not bind ports to localhost, you should somehow make `example.local` resolv to the ingress ip address. Easiest way is to add it to the hosts file.\n\n```\n$ kubectl get ingress\n\nNAME           CLASS     HOSTS           ADDRESS      PORTS   AGE\nslim-ingress   traefik   example.local   172.23.0.2   80      70s\n\n$ echo \"172.23.0.2 example.local\" | sudo tee --append /etc/hosts\n```\n\nThere are several ways to create a local Kubernetes for testing. Easiest are probably [k3d](https://k3d.io/) and [Minikube](https://minikube.sigs.k8s.io/docs/start/). I have not tested, but [Docker Desktop](https://docs.docker.com/desktop/kubernetes/) most likely works too.\n\n```\n$ k3d cluster create slim-test --servers 1 --agents 3\n```\n\nOr you can use the provided config file.\n\n```\n$ k3d cluster create -f k3d.yaml\n```\n\nWith Minikube remember to enable ingress addon first.\n\n```\n$ minikube addons enable ingress\n$ minikube start\n```\n\n## Testing\n\nAfter deploying you can test different endpoints with curl.\n\n```\n$ curl --ipv4 --include example.localhost\n$ curl --ipv4 --include example.localhost/cars\n$ curl --ipv4 --include example.localhost/static.html\n$ curl --ipv4 --include example.localhost/server\\?foo=bar\n```\n\nIf testing Kubernetes deployment use `example.local` instead.\n\n```\n$ curl --ipv4 --include example.local\n$ curl --ipv4 --include example.local/cars\n$ curl --ipv4 --include example.local/static.html\n$ curl --ipv4 --include example.local/server\\?foo=bar\n```\n\nNote that some setups use TLS.\n\n```\n$ curl --ipv4 --include https://example.localhost\n$ curl --ipv4 --include https://example.localhost/cars\n$ curl --ipv4 --include https://example.localhost/static.html\n$ curl --ipv4 --include https://example.localhost/server\\?foo=bar\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftuupola%2Fphp-docker-k8s","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftuupola%2Fphp-docker-k8s","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftuupola%2Fphp-docker-k8s/lists"}