A bash script for zero-downtime Craft CMS deployment to run on production servers. Inspired by the Capistrano routine. This script is still beta! Please use it very carefully!
- Copy the files to your project folder on the server.
- Run
chmod +x deploy.sh setup.shto set execution permissions. - Run
./setup.shto create the initial folders and files. - Upload
.envintoshared/. - Upload
storagefolder intoshared/. - Upload
web/.htaccessintoshared/web/. - Upload
web/cpresourcesfolder intoshared/web/. - Upload your
[ASSETS_DIR]folder andweb/cpresourcesfolder intoshared/web/. - Setup a webhook to call the scripts or run
./deploy.shmanually.
Following files and folders must be added to .gitignore to make the symlinks work:
- .env
- storage
- web/[ASSETS_DIR]
- web/cpresources
- web/.htaccess
This script is still beta. Please use it carefully and not on large and heavy projects. Or do, whatever, your call.
Creates the necessary releases, shared and shared/web folders on the server. Run this script first.
- Runs
./craft backup/dbto create a database backup first. - Creates a release folder in
releasesnamed by the current timestamp, i.e.20190623170859. - Clones your git repo into this folder.
- Runs
composer installto install Craft CMS. - Creates symlinks for shared folders and files.
- Runs
./craft migrate/alland./craft project-config/sync. - Creates a symlink from the
currentfolder to the newest release. - Deletes old releases and keeps max.
[DEPLOY_KEEP_RELEASES]releases. - Deletes oldest backup and keeps max.
[DEPLOY_KEEP_BACKUPS]backups. - Restarts PHP to delete symlink cache (optional)
Creates a symlink from current/ to the second newest release folder (i.e. the former release), deletes the current release folder afterwards and runs composer install, ./craft migrate/all and ./craft project-config/sync. That's all. No further database actions.
If you run a major update with significant database migrations you do it on your own responsibility!
Optional webhook script to run the bash scripts and creates a logfile. You can use your own scripts of course.
When you don't want to spend money on deployment services and tools like Capistrano are just too much to set up for smaller projects.
- Set project folder name in .env
Add.envfor better config handling.Delete releases folder if an error occurs during deployment.Delete not only the oldest release folder, but multiple release folders if there's more than 5 folders (occurs if an deployment fails).(Corrupt folders will be removed if installation fails)Integrateupdate.shscripts intodeploy.shand/or create flags.
Itsa MIT!