Setup Craft CMS with Docker
Contents
This guide will take you through how to set up a Craft CMS instance in docker. It includes NGINX, PHP and MYSQL
1 Clone repo
git clone https://github.com/hanas879/craft-docker-compose.git
cd craft-docker-compose
2 Install craft files
-
Create a folder named “code”
mkdir code
-
Download the latest craft and extract it to the
code
directory you just created v3 v4 -
Do a
sudo chown -R www-data code
to change the permission so that nginx and php can access the files
3 Change config files
- Change the
site.conf
to what your site is called, something likeyoursite.conf
- Inside the
.conf
:
server_name YourSiteHere.com;
server_tokens off;
root /code/web;
index index.html index.htm index.php;
charset utf-8;
Info
Change
server_name
to whatever your site is calledaccess_log off;
error_log /var/log/nginx/YourSiteHere.com-error.log error;
Info
Change
YourSiteHere.com
to your site
fastcgi_param HTTP_PROXY "";
fastcgi_param HTTP_HOST YourSiteHere.com; # Change this
Info
Change
YourSiteHere.com
to your site-
Inside the
docker-compose.yml
change parameters to fit your needs -
Open up
code/.env
and apply the database settings from thedocker-compose.yml
to match.
CRAFT_DB_DRIVER=mysql
CRAFT_DB_SERVER=db
CRAFT_DB_PORT=3306
CRAFT_DB_DATABASE=craft
CRAFT_DB_USER=craftuser
CRAFT_DB_PASSWORD=craft
Warning
Make sure that CRAFT_DB_SERVER is set to
db
- You also have to make a Security Key for the craft instance. You can do this in tons of ways, but one of them is by running the command:
openssl rand -hex 16
and take the output and put it inCRAFT_SECURITY_KEY=
4 Start the container
-
docker compose up -d
-
Now navigate to
yourSite.com/admin/
and complete the installation