Deploying a Craft CMS Project with DeployHQ
Deploying a Craft CMS Project with DeployHQ
This guide assumes you already have a hosted server with a web server like Apache or Nginx installed and configured to serve your Craft CMS application.
Using DeployHQ for Deployments
DeployHQ is a service that simplifies deploying applications to your servers. You can define configurations, custom commands, and automate deployments on pushing code.
The free plan lets you deploy 1 project up to 5 times a day!
Creating a Project
After signing up and logging in, create a project by going to Projects > New Project.
Follow the wizard and choose your repository. If you encounter issues connecting, refer to DeployHQ's support page.
Dedicated User for DeployHQ
For security, it's recommended to create a separate user for deployments:
sudo adduser deployhq
sudo usermod -a -G www-data deployhq
Configuring a Server
Now, tell DeployHQ where your Craft CMS application resides. Go to Servers > New Server.
- Choose a memorable name and select SSH as the protocol.
- Enter your server's IP address in the Hostname field.
- The Username should be
deployhq
. - Check the Use SSH key rather than password for authentication? box. Then, run these commands on your server:
su - deployhq
mkdir ~/.ssh
chmod 700 ~/.ssh
nano ~/.ssh/authorized_keys
- Paste DeployHQ's public key, press
Ctrl + X
,y
, thenEnter
to save. - Finally, set correct permissions with:
chmod 600 ~/.ssh/authorized_keys
- Set the Deployment Path to where your Craft CMS application resides (e.g.,
/var/www/your-craft-project
). Enable Perform zero-downtime deployments on this server.
Zero-downtime deployments ensure your previous version stays live until the new one is ready. You can learn more about this process in DeployHQ's documentation.
By enabling this, your application files will reside in a path like /var/www/your-craft-project/current
. Update your web server configuration accordingly.
- Enter
production
in the Environment field and enable automatic deploy.
Once done, press Save.
Note: If you have connection issues, refer to DeployHQ's support page.
Config Files (Optional)
DeployHQ allows uploading files during deployment that you don't want in your repository (like .env
files containing sensitive database credentials).
Go to Config Files and click New Config File.
In your project, copy the contents of your .env
file (or similar) into the config file content field.
Setting Up SSH Commands
We'll configure commands to execute on the server after deployment.
Go to SSH Commands and click New SSH Command.
Create the following commands:
- Clear Cache:
cd %path% && craft cache/flush
- Update Composer Dependencies (if using Composer):
cd %path% && composer install --optimize-autoloader
- Migrate Database (if using migrations):
cd %path% && craft migrate
Commands run sequentially, so ensure they're in the correct order.
Deploying Your Project
That's it! Time to deploy.
Click Deploy Project in the header. The created server and revisions should be preselected. Once everything looks good, click Deploy to begin deployment.
Now you've automated your Craft CMS project deployments!
If you’ve got any other projects you’d like to automate deployments for, we’ve written lots of guides for deploying the most popular application frameworks and content management systems.