a-kryvenko / docker-webserver

Ready to use webserver, which include NGINX, MySQL, PHP, SMTP, Cloud backups and DEV environment

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Webserver on docker containers

License: MIT Stand With Ukraine

Development process described in habr.com.

Webserver included:

  • MySQL
  • PHP
  • Nginx
  • msmtp
  • composer
  • cloud backups

Before starting

  1. Prepare server
  2. [optional] For SSL certificates up containers with nginx-proxy and acme-companion:
docker network create nginx-proxy-network

docker run --detach \
    --name nginx-proxy \
    --publish 80:80 \
    --publish 443:443 \
    --net nginx-proxy-network \
    --volume certs:/etc/nginx/certs \
    --volume vhost:/etc/nginx/vhost.d \
    --volume html:/usr/share/nginx/html \
    --volume /var/run/docker.sock:/tmp/docker.sock:ro \
    nginxproxy/nginx-proxy

docker run --detach \
    --name nginx-proxy-acme \
    --net nginx-proxy-network \
    --volumes-from nginx-proxy \
    --volume /var/run/docker.sock:/var/run/docker.sock:ro \
    --volume acme:/etc/acme.sh \
    --env "DEFAULT_EMAIL=mail@yourdomain.tld" \
    nginxproxy/acme-companion

Where mail@yourdomain.tld is you contact email for sending emails with certs renew notifications.

Installation:

1. Clone repository

git clone git@github.com:a-kryvenko/docker-webserver.git .

2. Create copy of .env file:

cp .env.example .env

3. Modify .env, set up variables

Variables description
  • COMPOSE_FILE - which docker-compose files will be included;
  • SYSTEM_GROUP_ID - ID of host user group. Usually 1000;
  • SYSTEM_USER_ID - ID of host user. Usually 1000;
  • APP_NAME - url by which the site is accessible. For example, example.com or example.local for local development;
  • ADMINISTRATOR_EMAIL - email to which we send information about certificates;
  • DB_HOST - database host. By default db, but in the case when the database is on another server - specify the server address;
  • DB_DATABASE - database name;
  • DB_USER - the name of the user who works with the database;
  • DB_USER_PASSWORD - database user password;
  • DB_ROOT_PASSWORD - password of the root database user;
  • AWS_S3_URL - url of cloud backup storage;
  • AWS_S3_BUCKET - name of the bucket in the backup storage;
  • AWS_S3_ACCESS_KEY_ID - storage key;
  • AWS_S3_SECRET_ACCESS_KEY - storage password;
  • AWS_S3_LOCAL_MOUNT_POINT - path to the local folder where we mount the cloud storage;
  • MAIL_SMTP_HOST - smpt host for sending mail, e.g. smtp.gmail.com;
  • MAIL_SMTP_PORT - smpt port. Default 25;
  • MAIL_SMTP_USER - smpt username;
  • MAIL_SMTP_PASSWORD - smtp password.

Separately, it is worth mentioning COMPOSE_FILE. Depending on the environment we are launching a website - we need different services. For example, locally - you only need a base app, cloud for backups:

dc-app.yml:dc-cloud.yml

For dev server - all above and https:

dc-app.yml:dc-proxy.yml:dc-cloud.yml

For production server - app, https and cloud backups:

dc-app.yml:dc-proxy.yml:dc-cloud.yml

Also, you may need to open database ports on dev server (for example, for PhpStorm database inspect) and open 80 port for nginx. Ports setting up in compose-dev.yml, so in this case you need:

dc-app.yml:dc-dev.yml:dc-standalone.yml

4. Build images and up server

docker-compose build
docker-compose up -d

5. Initialize crontab

./cgi-bin/prepare-crontab.sh

6. Optional. Restore backups

./cgi-bin/restore-backup.sh

7. Optional. Install dependencies

docker-compose run --rm composer update
docker-compose run --rm composer install

P.S. You can add alias to make interaction with composer more simple:

vi ~/.bashrc

alias dcr='docker-compose run --rm'

And then use composer:

dcr composer install

About

Ready to use webserver, which include NGINX, MySQL, PHP, SMTP, Cloud backups and DEV environment

License:MIT License


Languages

Language:Shell 71.7%Language:Dockerfile 24.5%Language:PHP 3.8%