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
- Install DDEV for local development, more info here.
- Sign up for a Hetzner Cloud account
- Sign up for a DeployHQ account
- Set up SSH keys in DeployHQ for server access
- 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
- Set up your Hetzner server with a LAMP stack
- Create a new database and database user
- Install phpMyAdmin for database management
- Import the database dump file
Configure DeployHQ
- Create a new project in DeployHQ
- Connect your GitHub repository
- Add your server as a deployment target:
- Enter server hostname/IP
- Specify the deployment path
- Add SSH key authentication
Configure Deployment Settings
- 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
- Add environment variables in DeployHQ project settings
- Copy values from
.env.example.production
- Add security key and database credentials
- Ensure these are deployed to the server
SSL Setup
- Install Let's Encrypt SSL certificate on your server
- Configure virtual host for SSL
Additional Steps
- Add
config/license.key
to.gitignore
- Set up automatic deployments (optional):
- Configure GitHub webhooks in DeployHQ
- Enable automatic deployments for your environment
Ready for Deployment
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.