Docker is great for linking together multiple technologies, but some aspects of it are not terribly obvious.
One such use case is when you want to host multiple PHP sites on the same server.
This repo lets you set up a LEMP stack with a few extra bells and whistles.
In case you're unfamiliar with the term LEMP, it's an awful acronym for:
- Linux
- Nginx (which is pronounce "Engine-X"...so this is really stretching)
- Mariadb
- PHP
This repo also features MongoDB and Certbot.
- Modify
.env
to fit the particulars of your setup. Use absolute file paths. - Modify
docker-compose.yml
; replacingexample.com
andothersite.com
with your own URLs. - Modify
nginx/vhosts/example.com
and replace occurences ofexample.com
with your URLs. - Create the following directories:
/database
,/lets-encrypt
,/logs
,/mongo-db/
, andnginx/certs/
- Run
setup.sh
. It creates thedhparam.key
file that your server will need to create valid SSL connections. The key generation is set to its highest setting, and it will take a fair amount of time to work its magic. Go get a coffee or something.
File locations You can place your web sites in any directory on your server that you wish. If you chose a directory other than /sites/example.com, be sure to update the references in your .env file to point to the appropriate directory.
Launch the containers with docker-compose up -d
. This runs Docker in detached mode. You'll see a message that your containers have launched, but you will not see continuous logs on your screen.
Open a new web browser and pull up your domain name. If it doesn't appear, check the Nginx logs to see what went wrong.
Nginx logs are written to logs/nginx/access.log
and logs/nginx/error.log
To view the logs for other services, type sudo journalctl <service name>
Once the non-SSL version of your site appears, it's time to generate the SSL certificate with Let's Encrypt.
Log into certbot with docker exec -it certbot bash
Then, run:
./certbot-auto certonly --email [email protected] --webroot -w /www -d domain.com -d www.domain.com -d otherdomain.com
Please replace the domains in the string above with your own values. Certbot will then update itself and attempt to validate your domain. Once it does, you can add the SSL-specific segments to your vhost files.
- Navigate to
vhosts.secure/example.com
- Copy the second server block and paste it into your existing
vhosts/example.com
file. Replace all instances of example.com with your own domain name. - Restart nginx:
docker restart nginx
- Attempt to access the secure version of your domain name.
You can check the quality of your setup by verifying it at the SSL Labs web site.