Simple Docker LEPM stack
Warning This project is no longer maintained. Use it only as inspiration.
This is a server stack used to host your web application with Docker based Nginx, MySQL and PHP. It is a super easy to setup on local development or even on production environment (VPS). There is also PhpMyAdmin to manage your database and Portainer to manage Docker components. The stack is SSL ready by using ACME challenge to get Let's Encrypt certificate. To put everything together there is the Traefik reverse proxy.
How to install Docker based Nginx, MySQL and PHP on Digital Ocean:
https://www.youtube.com/watch?v=ciiX3a-BzZs
How to install Docker based LEMP server for localhost development:
https://www.youtube.com/watch?v=mkmcFuJt5Gk
For example, you can use Digital Ocean droplet with Docker preinstalled.
Following steps of this stack production deployment are demonstrated on example.com
domain name.
/srv/web/example.com
./srv/web/example.com/docker
folder.sh start.sh --production
and enter prompted questions (domain name, e-mail).https://example.com
https://traefik.example.com
https://pma.example.com
https://portainer.example.com
https://example.com
there should be working phpinfo()
and MySQL database connection test through PDO.You can use any OS where the Docker is supported.
Following steps of this stack localhost deployment are demonstrated on example.localhost
domain name. However even on localhost development, you can use typical example.com
form of domain name.
/docker
subfolder.sh start.sh --localhost
and enter prompted questions (domain name, HTTP port).hosts
file. If you use Google Chrome browser you don't need to, because he can do it automatically for every *.localhost
like domain name.127.0.0.1 example.localhost
127.0.0.1 traefik.example.localhost
127.0.0.1 pma.example.localhost
127.0.0.1 portainer.example.localhost
example.localhost
traefik.example.localhost
pma.example.localhost
portainer.example.localhost
example.localhost
there should be working phpinfo()
and MySQL database connection test through PDO.There are some default users and passwords, which have to be set to sign in to the Traefik dashboard, MySQL/PhpMyAdmin and Portainer. Obviously, you can change these by rewriting preconfigured values.
admin
and default password is secret
./docker/traefik/traefik.toml
file on production environment in users = ["username:password"]
form where the password string is replaced to SHA1 hash. There is no login on localhost development.admin
and default password is secret
./docker/mysql/.env
file.portainer.example.com
on production environment or at portainer.example.localhost
on localhost development after you first started Docker containers. Then configuration will be stored in /docker/poratiner
folder. This folder is created automatically.Just after you successfully deploy this stack on production or localhost you can see whether it's working by opening example.com
or example.localhost
where is phpinfo()
and MySQL database connection test running. Now it's time to change this functionality test content to your own web application. Your files have to be put to the /public
folder which is root folder for Nginx to looking for index.php
file. If you have more complicated project structure divided to public and private components like Laravel has for example, then put public files to /public
folder and all other folders and files (app, resources, routes, ...) put next to the /docker
folder therefor same level. It means that this stack is a part of your project folder. Therefore, you are not putting your web application into this stack but vice versa this stack into you web application project folder.
/public
folder is place where you have to put your own web application files. At least index.php
file.mysql
string for a host parameter./mysql
folder. This folder is created automatically.If you want to manually swap non SSL configuration to SSL variant and vice versa run sh traefik-swap.sh
script in /docker/traefik
folder.
If you want to change configuration (domain name, port, e-mail) without cloning clear repository and starting from the scratch after you have already configure it up once, you can simply use start script again by running sh start.sh --production
or sh start.sh --localhost
in /docker
folder. However, be careful to not delete /docker/.env
file after it's created, because it's needed for reconfiguration process. If you want to (re)configure stack without starting Docker containers you can use another prepared script sh configure.sh --production
or sh configure.sh --localhost
in /docker
folder instead.
sh start.sh --production
or sh start.sh --localhost
again.There are a few configuration files you can manually change if you need to.
/docker/nginx/nginx.conf
./docker/mysql/.env
.php.ini
file is /docker/php-fpm/php-ini-overrides.ini
./docker/traefik/traefik.toml
./docker/traefik/traefik.http.toml
or /docker/traefik/traefik.https.toml
depending on whether the stack is configured to production environment or localhost development. These files are for non SSL to SSL swapping purposes and vice versa, but only the primary configuration file is in usage./docker/portainer
. This folder is automatically created after the Docker containers are started.There are several files used for logging service errors and their statuses.
/docker/nginx/logs
folder. This folder is created automatically.