Deploy October CMS With Docker
October is a free, open-source, self-hosted CMS platform based on the Laravel PHP Framework. This tutorial will teach you how to easily deploy October CMS using docker, but if you wish to get more information on using October CMS, then I would recommend going to the tutorials page.
Steps
Deploy an Ubuntu 18.04 Server with at least 1GB of RAM. Add some swap too if you are on something like DigitalOcean that uses local SSDs.
Download the latest October CMS release:
wget https://github.com/octobercms/october/archive/v1.1.0.tar.gz
tar --extract --gzip --file v1.1.0.tar.gz
rm v1.1.0.tar.gz
mv -i october-1.1.0 octobercms
Create a docker-compose.yml
file on your server with the following (editing the DB_PASSWORD
and MYSQL_PASSWORD
to something else, but matching each other).
editor $HOME/octobercms/docker-compose.yml
version: '2.2'
services:
web:
container_name: web
restart: always
image: aspendigital/octobercms:latest
ports:
- 80:80
environment:
- DB_TYPE=mysql
- DB_HOST=db #DB_HOST should match the service name of the database container
- DB_DATABASE=octobercms
- DB_USERNAME=octobercms
- DB_PASSWORD=octobercms
volumes:
- $HOME/octobercms/plugins:/var/www/html/plugins
- $HOME/octobercms/storage/app:/var/www/html/storage/app
- $HOME/octobercms/storage/logs:/var/www/html/storage/logs
- $HOME/octobercms/themes:/var/www/html/themes
db:
image: mariadb
container_name: db
restart: always
environment:
MYSQL_RANDOM_ROOT_PASSWORD: 1
MYSQL_DATABASE: octobercms
MYSQL_USER: octobercms
MYSQL_PASSWORD: octobercms
volumes:
- $HOME/volumes/mysql/data:/var/lib/mysql
Start Services In Order
For the first startup, we want to "warm up" the database to make sure it's ready, so start it on its own:
docker-compose up db
When it appears to have stopped outputting the console and says:
[Note] mysqld: ready for connections.
Then start up the web application:
docker-compose up web
Fix Permissions
The web user needs to be able to edit the content in the plugins
, storage
, and themes
folders/volumes, so run the following commands:
docker-compose exec web chown -R www-data /var/www/html/plugins
docker-compose exec web chown -R www-data /var/www/html/storage/app
docker-compose exec web chown -R www-data /var/www/html/storage/logs
docker-compose exec web chown -R www-data /var/www/html/themes
Run Migrations
Now run the following command to run database migrations (create the table structures etc).
docker-compose exec web php artisan october:up
Log Into the Backend
Navigate to your server's IP/hostname and append /backend
to the URL. Then login with admin
for the username and password.
Future Starting Up
You only had to perform the previous steps (such as starting the services in order, and running database migrations) once. From now on, you can just navigate to the octobercms folder and run:
docker-compose up
Adding HTTPS/SSL
I used an nginx reverse proxy (jwilder/nginx-proxy) to achieve SSL/HTTPS support by altering my docker-compose.yml
configuration to be like so:
version: '2.2'
services:
reverse-proxy:
image: jwilder/nginx-proxy
restart: always
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- $HOME/volumes/ssl:/etc/nginx/certs
web:
container_name: web
restart: always
image: aspendigital/octobercms:latest
# ports:
# - 80:80
environment:
- DB_TYPE=mysql
- DB_HOST=db #DB_HOST should match the service name of the database container
- DB_DATABASE=octobercms
- DB_USERNAME=octobercms
- DB_PASSWORD=octobercms
- CMS_LINK_POLICY=secure
- VIRTUAL_HOST=www.mydomain.com,mydomain.com
- VIRTUAL_PROTO=http
- VIRTUAL_PORT=80
- CERT_NAME=mydomain.com
volumes:
- $HOME/octobercms/plugins:/var/www/html/plugins
- $HOME/octobercms/storage/app:/var/www/html/storage/app
- $HOME/octobercms/storage/logs:/var/www/html/storage/logs
- $HOME/octobercms/themes:/var/www/html/themes
db:
image: mariadb
container_name: db
restart: always
environment:
MYSQL_RANDOM_ROOT_PASSWORD: 1
MYSQL_DATABASE: octobercms
MYSQL_USER: octobercms
MYSQL_PASSWORD: octobercms
volumes:
- $HOME/volumes/mysql/data:/var/lib/mysql
In this example, I am using a wildcard certificate for *.mydomain.com as discussed here.
- The
CMS_LINK_POLICY=secure
fixes the issue whereby stylesheets would otherwise try to load over http instead of https and then get blocked by the browser (the web application thinks it is running in plain http). - Notice that port 80 on the web service is now commented out as that is also handled by the reverse proxy.
- You will need to put your certificate files in a folder at
$HOME/volumes/ssl
with the same name as yourCERT_NAME
value, with the extensions.crt
and.key
for the combined certificate and the private key.
Themes
When working on this recently, there were URLs being passed to | theme
filter, which weren't getting translated to https even with the CMS_LINK_POLICY
set so I ended up having to hardcode them.
References
First published: 7th April 2020