What is the easiest way to dockerize PHP applications? Let's find out with the GitHub repository example.
In order to create scalable architecture, we will dockerize two apps that will use the same reverse proxy.
Services can only communicate with other services on networks they share, so we will have three networks:
- Proxy Network which contains Reverse Proxy (Nginx), Best App (Apache/PHP), and Awesome App (Apache/PHP);
- Best Network which contains Best App and Best DB (MySQL);
- Awesome Network which contains only Awesome App.
Requirements for our architecture are:
- There are no permission issues;
- Xdebug works out-of-the-box;
- Every application has a unique domain;
- We use HTTPS;
- Setup supports multiple applications.
Permission Issues and Xdebug
To prevent permission issues and have package availability out-of-the-box, we will use thecodingmachine/php for PHP applications, a general-purpose PHP image for Docker.
Unique Domains, HTTPS and Multiple Applications
In order to have unique domains, HTTPS and multiple applications support out-of-the-box, we will use nginx-proxy, as it supports everything mentioned above.
As we have defined the architecture and tools we will use, this is the part where you should visit https://github.com/v-m-i/simple-php-app-dockerization and see how to configure and run everything mentioned so far.
This post could have been a lot longer, but I've kept it as short as possible because everything should be explained in the example repository.
Is the Easiest Way the Best Way?
It depends on what our goal is. If our goal is to create an optimized, clean and precise docker environment, then it's not the best way, as it's a fat setup. But if we want to dockerize our app for our local development in the fastest and hassle-free way, then it might be the best way to do it.