How to install and use Hugo on Ubuntu 23.04, served by NGINX on DigitalOcean
This is a consolidation of personal notes and tutorials I used to setup the DigitalOcean droplet for this site. I would have submitted a more step-by-step version to DO’s awesome Community Tutorials, but unfortunately their Write for DOnations program is temporarily closed.
Why Ubuntu 23.04?
The Lowkey theme used for this site requires Node v16+. Unfortunately, Ubuntu 22.04 offers v12. Thankfully, Ubuntu 23.04 offers v18+.
Initial Server Setup
Reference:
Personal Notes:
- Disabled root login using sshd for security reasons.
- Edit the sshd config file
sudo nano /etc/ssh/sshd_config
- Comment out the line
PermitRootLogin yes
- Restart the service
sudo systemctl restart ssh
- Edit the sshd config file
- When generating ssh keys using
puttygen
on Windows, copy the public key from the textbox.
Installing NGINX on Ubuntu 23.04
Reference:
- How to install NGINX on Ubuntu 22.04 by Alex Garnett
- Certbot instructions for NGINX on Ubuntu 20.04 Focal
Personal Notes:
- Allowed “Nginx Full” in ufw. Cerbot adds rules to redirect HTTP traffic to HTTPS.
- Configured root for hobobandy.dev to be /var/www/hobobandy-dev, see below how this affects Hugo.
- Allow user to manage files in that folder
chown user:user /var/www/hobobandy-dev
- Allow user to manage files in that folder
- Turned off server signature at bottom of error pages.
- Edit the nginx config
sudo nano /etc/nginx/nginx.conf
- Uncomment the line
server_tokens off;
in thehttp
block - Restart NGINX for changes to take effect
sudo systemctl restart nginx
- Edit the nginx config
Installing Hugo on Ubuntu 23.04
References:
- How to install and use Hugo, a static site generator on Ubuntu 14.04 by Justin Ellingwood
- Deploying a static Hugo site with NGINX by Gideon Wolfe
- Hugo Getting Started
- Git Clone, Push, Pull over SSH
Personal Notes:
- Download (
wget
) pre-built binaries from Hugo’s Github, I chose the extended version to prevent dependencies errors from modules/themes. Install the package usingdpkg -i hugo_extended_0.119.0_linux-amd64.deb
- Hugo autocompletion fails to create the file in
/etc/bash_completion.d/
, workaround:- Create file in a temp folder your user has access to:
hugo completion bash > ~/hugo
- Move the file as superuser to the bash_completion folder:
sudo mv ~/hugo /etc/bash_completion.d/
- Restart session, or type
. /etc/bash_completion.d/hugo
- Create file in a temp folder your user has access to:
- In case you haven’t done this yet, prepare the ssh key and add it to your Github. (see ref 4)
- Create a Github repo (kept mine private) for the site prior to the
hugo new site
command. Clone the empty repo in your preferred folder. Use the commandhugo new site /home/user/my-site
. Add the folderspublic
andressources
to the.gitignore
, and any other files containing sensitive information (API keys, etc.). - Installed the theme using git:
- Add theme repo as a submodule:
git submodule add https://github.com/nixentric/Lowkey-Hugo-Theme.git themes/lowkey
- Delete
hugo.toml
in the Hugo root folder. - Copy theme example site files and overwrite existing:
cp themes/lowkey/ExampleSite/* .
- Install packages, from Hugo root folder:
npm install
- All done!
- Add theme repo as a submodule:
- When building the Hugo site, make sure to specify destination and clean the directory.
hugo --cleanDestinationDir -d /var/www/hobobandy-dev
- Extension matters when creating new content with Hugo:
hugo new content posts/some-slug/some-slug.md
- Remember to commit and push changes to your Github repo for backup.