Help a noob - getting my hugo website to work with a webserver (Apache 2)


I am new to all of this. I have been able to build hugo websites and view them at localhost.

Now I am trying to build one on a headless ubuntu server that has a public IP. Because of this, I have been unable to view my website using any variation of the hugo server command. My best attempt and one that I thought should work was hugo server --bind= --baseUrl=http://myIP/

(I know this isn’t the most secure but I am working on a cheap bare-bones PC at the moment)

Because of these problems, I have found myself trying this guide to install apache2 on ubuntu, and have it run my hugo website:

I can get Apache 2 to run the sample webpage when it starts, and I can hit it from a different computer

I am now around Step 5. I get lost here for a couple of reasons:

  • I don’t have a Domain Name yet, and would prefer not to get one as I am just doing this to learn at the moment

  • This example create a sampe index.html page. But my hugo website contains more, correct? In particular, it contains the entire public directory. So would I simply put the entire public dir into /var/www/ ?

  • In my above comment, what should I replace with? My IP? Does it matter? A random DN?

Sorry if I’m not using the right terms, or completely missing easy concepts here. Any help would be appreciated.

Hey, you’ve made some good progress so far.

  • No domain name: No problem, wherever it says the domain name, substitute the IP address. If it talks about DNS anywhere, just ignore it. DNS is what converts domain names to IP addresses.

  • Site folder: When you do a Hugo build, by default, you get a folder /public that contains all the files you need Apache to serve. Either direct the hugo build command to output to the folder you want to use or simply copy/move the files.

    Note that typically, Apache installations will create /var/www as you’ve seen. You want your folder there.

    So if you have your source under ~/hugo/mysite, and use a simple hugo command to build.

    A command something like cp ~/hugo/mysite/public/ /var/www/mysite/ should be used. You might need to tweak that though, I don’t use Linux day-to-day.

    You will need to make sure that the folders and files are owned by the “user” that runs the Apache server. Typically something like www or www-data, I can’t quite remember, been a while since I used Apache.

    Something like sudo chown -R www:www /var/www/mysite should do the job.

    Finally, you will need to add something to the Apache configuration files so that it links your folder to a website it will serve. You should find those instructions online readily enough.

  • As for the last point, as mentioned, you use your public IP address - and yes, it does matter.

Without wishing too much to confuse you even more, you would be better off using NGINX rather than Apache, especially if you are using a cheap VPS for hosting since NGINX will perform a lot better than Apache with limited resources. Personally, I also find NGINX easier to configure than Apache.

1 Like