Setting up a Drupal 11 website on Hetzner
Learn how to set up a Drupal 11 website on Hetzner webhosting from scratch.
When it comes to hosting, Hetzner is my partner of choice. Their combination of products, consistently high quality, competitive pricing, hosting within the EU, and a strong commitment to sustainable energy makes them the perfect foundation for reliable, future-proof web projects.
With a wide range of options including cloud servers, dedicated machines, storage boxes, and networking solutions, Hetzner offers one of the most flexible hosting portfolios on the market.
Their offering can feel overwhelming at first.
In my case I chose the Webhosting L (under Web & managed > Webhosting). We need SSH access so the S or M package are not an option in our case.
Once you have access to the KonsoleH dashboard it's time to setup the server.
The first step is to setup PHP (Services > PHP configuration).
At the time of writing we use PHP 8.3 as the PHP version.
Enable allow_url_fopen, set the memory_limit to 384 (max), and enable the following PHP extensions APCu, Oauth, OPcache, Redis, SSH2.
Now it's time to create a database, make sure to use secure credentials (Services > MariaDB/Mysql).
Once the database is setup import your local database. You can use the web interface of Hetzner or your Database tool of preference for example Sequel Ace.
The next step is to setup SSL & force https, in my case I prefer to use LetsEncrypt to generate free certificates (Services > SSL Manager).
Also make sure to enable HTTPS redirect to force it.
Since we want to login using SSH we add our SSH key to the server. If you still need to generate an SSH key pair I advice you to ask your LLM of choice to guide you (Prompt example: Explain to me the steps to create an SSH key pair on my Mac / Windows computer).
On my mac I edit my SSH config (~/.ssh/config) so it knows what key to use and when.
# [Your site]
Host [hetzner-host]
UseKeychain yes
IdentitiesOnly yes
IdentityFile ~/.ssh/your_private_key_name
Replace the parts between brackets which are applicable for you.
Make sure to add your public key in the Hetzner dashboard (Services > Login data under Public SFTP keys and Public SSH keys)
Once this is done you can login into your Hetzner server with:
ssh [hetzner-username]@[hetzner-host] -p 222
Replace the parts between brackets which are applicable for you.
Now that we are logged in on the server we install Composer and Drush.
The good news is we don't have to install Composer as it already ships with Hetzner.
composer --version
Will show you what version of Composer is currently installed.
Now we install Drush globally with the following commands:
composer global require drush/drush:dev-master -W
vi .bashrc
export PATH="$HOME/.config/composer/vendor/bin:$PATH"
source ~/.bashrcNext we want to access our GIT repository from our server.
In order to do this you first generate a new keypair on the server.
ssh-keygen -t rsa -b 4096
I'm using Gitlab so in Gitlab I go to Settings > Repository > Deploy keys and I add the public ssh key there in order to get access to it from my server.
Now that we can access the repo we setup our Drupal project:
cd ~/public_html
mkdir [your-projectname]
cd [your-projectname]
mkdir production
cd production
git clone [your-git-repo-url] .
git submodule init
git submodule update
git config --global submodule.recurse true
git pull --recurse-submodules
Now we run Composer:
cd ~/public_html/[your-projectname]/production
composer install
And we put our files in place:
cd web/sites/default
mkdir files
chmod -Rf 777 files
To put the files in place you can connect with your favorite FTP client (for example Cyberduck) or use rsync.
And you setup settings.php to connect to your configured Hetzner database.
Once everything is setup I mostly run
drush deploy
To check if everything works and to make sure all config is imported correctly in the database.
There are only two things left and that is tell Hetzner that our document root is /[your-projectname]/production/web and setup the cron.
To setup the Cron (Services > Cronjob Manager), I mostly setup the cron to run hourly.
The summary of your Cron should look like this: @hourly curl -s [your-url-with-cron-key]
The url for the Cron can be found in your Drupal project under /admin/config/system/cron.
Now your Drupal website is setup on Hetzner and it should be running smoothly.
In a next Insight I'll show you how you can Deploy from Gitlab directly to your server.
Disclaimer: In this Insight I don't touch performance, scaling, backups, disaster recovery, etc. This is on purpose to limit the scope of the insight. That doesn't mean this isn't important and should be setup properly on your server.