Header

Deploy CraftCMS via DeployHQ on Hetzner Cloud

Open Source, PHP, Tips & Tricks, and Tutorials

Post Image

What is an easy way to get a CraftCMS site up and running? Here's a simple method using DeployHQ, a Hetzner CX11 virtual cloud server (max. € 4.51 / month) and DDEV for local development.

Prerequisites

  1. Install DDEV for local development, more info here.
  2. Sign up for a Hetzner Cloud account
  3. Sign up for a DeployHQ account
  4. Set up SSH keys in DeployHQ for server access
  5. Create your server on Hetzner Cloud

Create GitHub repository, clone it locally

Create a new GitHub project (with README), clone it locally and run these commands for the CraftCMS installation:

# Set up the DDEV environment:
ddev config --project-type=craftcms --docroot=web --create-docroot

# Boot the project and install the starter project:
ddev start
ddev composer create -y --no-scripts craftcms/craft

# Run the Craft installer:
ddev craft install
ddev launch

Push the new files to your GitHub repository.

Dump the local database

For the initial installation we need a dump of the database. This can be achieved via ddev export-db -f dump.sql.gz.

This database dump will be later imported into the live sites database.

But do not worry: After that initial DB import, changes to the data structure will be applied via files in git and by CLI migrate commands (for example php craft migrate/all --no-content --interactive=0).

Server Setup

  1. Set up your Hetzner server with a LAMP stack
  2. Create a new database and database user
  3. Install phpMyAdmin for database management
  4. Import the database dump file

Configure DeployHQ

  1. Create a new project in DeployHQ
  2. Connect your GitHub repository
  3. Add your server as a deployment target:
    • Enter server hostname/IP
    • Specify the deployment path
    • Add SSH key authentication

Configure Deployment Settings

  1. Set up deployment configuration:
# DeployHQ deployment commands
cd ${DEPLOY_PATH}
git pull origin main
composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader

# CraftCMS deployment commands
php craft update/composer-install --interactive=0
php craft migrate/all --no-content --interactive=0
php craft project-config/apply
php craft migrate --track=content --interactive=0
sudo service php8.2-fpm reload
echo "Application deployed!"

Environment Configuration

  1. Add environment variables in DeployHQ project settings
  2. Copy values from .env.example.production
  3. Add security key and database credentials
  4. Ensure these are deployed to the server

SSL Setup

  1. Install Let's Encrypt SSL certificate on your server
  2. Configure virtual host for SSL

Additional Steps

  1. Add config/license.key to .gitignore
  2. Set up automatic deployments (optional):
    • Configure GitHub webhooks in DeployHQ
    • Enable automatic deployments for your environment

Ready for Deployment

  1. Push your changes to GitHub
  2. Deploy via DeployHQ dashboard
  3. Monitor deployment logs for any issues

Remember to:

  • Keep your SSH keys secure (you can also use Global SSH Keys)
  • Monitor deployment logs
  • Test thoroughly after each deployment
  • Set up proper backup solutions

For automatic deployments, DeployHQ provides Webhook URLs that can be integrated with GitHub Actions or other CI/CD tools.

A little bit about the author

Facundo is the CTO at DeployHQ. He oversees our software engineering team by day and, in his free time, enjoys hobbies such as cycling, spending time in nature, and the company of Bono 🐶

Tree

Proudly powered by Katapult. Running on 100% renewable energy.