Hetzner web page deployment (level 1 web hosting package)
My .de domain is hosted on Hetzner, a German hosting company. I have the cheapest web hosting package they offer, called 'level1'. It doesn't give you full ssh access, so how can you deploy your (in my case static) page automatically? I came up with the following instructions that worked with my .de domain - no idea where it may differ for other domain endings.
Per default, anything in your /public_html
directory on the Hetzner account is served automatically.
The horribly sluggish konsoleh interface offers a 'graphical' WebFTP client under Services->Extras->WebFTP
.
It is not exactly a modern UI experience.
Copying from local to remote
In short: rsync does not work with 'level1' web hosting on Hetzner - probably, because it doesn't allow proper SSH sessions.
But scp and sftp seem to "work".
Assuming your local directory is called public_html
:
scp -r public_html <domain-name-without-.de>@www132.your-server.de:/
Alternatively, you can also use OpenSSH's sftp
command:
sftp <domain-name-without-.de@www132.your-server.de
sftp
drops you in an interactive shell.
Basically, sftp
has a current local and remote directory.
Commands like ls
act on the remote directory, while the equivalent lls
acts on the local one.
To copy a local directory to the remote from the sftp
interactive shell:
sftp> put -r public_html /
public_html
) exists on the remote target, or you'll get an error message (Couldn't canonicalize: No such file or directory
).
In that case you'd first have to create the remote directory with mkdir
.
Deleting old content
That's all nice, but I want to have an exact copy of my local directory on the remote - again, rsync
is not an option with my hosting package.
The easiest way to guarantee this, is to simply delete everything under /public_html
on the remote and then re-upload the whole folder.
Currently, this site is so small that this is good enough.
OpenSSH's sftp
doesn't seem to offer a feature to recursively delete a directory that is not empty.
There are alternative sftp command line clients that seem to offer such a feature, but at this point I decided to write a Python script instead.
Deployment with a Python script
I use the paramiko
sftp library together with Python.
The code can be found here - it is currently not a great achievement of software architecture, but it works for me.
It first deletes the deployment directory on the remote and then copies everything to the remote server. The script can be run like this:
python3 -m venv venv
source venv/bin/activate
pip install paramiko
python deploy.py LOCAL_DIR_NAME [REMOTE_DIR_NAME]
Closing
Maybe I could have just asked Hetzner support for some guidance, but I had fun figuring this out by myself.
If there is an easier way, I'd be glad to hear about it.
Just drop me an email at <my-first-name>.<my-last-name>@posteo.de
.