| 1 |
--- |
| 2 |
title: Host on Netlify |
| 3 |
description: Host your project on Netlify. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
aliases: [/hosting-and-deployment/hosting-on-netlify/] |
| 7 |
--- |
| 8 |
|
| 9 |
Use these instructions to enable continuous deployment from a GitHub repository. The same general steps apply for other Git providers such as GitLab or Bitbucket. |
| 10 |
|
| 11 |
{{% include "/_common/gitignore-public.md" %}} |
| 12 |
|
| 13 |
## Prerequisites |
| 14 |
|
| 15 |
Please complete the following tasks before continuing: |
| 16 |
|
| 17 |
1. [Create](https://app.netlify.com/signup) a Netlify account. |
| 18 |
1. [Log in](https://app.netlify.com/login) to your Netlify account. |
| 19 |
1. [Create](https://github.com/signup) a GitHub account. |
| 20 |
1. [Log in](https://github.com/login) to your GitHub account. |
| 21 |
1. [Create](https://github.com/new) a GitHub repository for your project. |
| 22 |
1. [Create](https://git-scm.com/docs/git-init) a local Git repository for your project with a [remote][] reference to your GitHub repository. |
| 23 |
1. Create a Hugo project within your local Git repository and test it with the `hugo server` command. |
| 24 |
1. Commit the changes to your local Git repository and push to your GitHub repository. |
| 25 |
|
| 26 |
## Procedure |
| 27 |
|
| 28 |
Step 1 |
| 29 |
: Create a `netlify.toml` file in the root of your project, adjusting the tool versions and time zone as needed. |
| 30 |
|
| 31 |
```toml {file="netlify.toml" copy=true} |
| 32 |
[build.environment] |
| 33 |
GO_VERSION = "1.27.0" |
| 34 |
HUGO_VERSION = "0.166.0" |
| 35 |
NODE_VERSION = "24.20.0" |
| 36 |
TZ = "Europe/Oslo" |
| 37 |
|
| 38 |
[build] |
| 39 |
publish = "public" |
| 40 |
command = """\ |
| 41 |
git config --global core.quotepath false && \ |
| 42 |
hugo build --gc --minify --baseURL "${URL}" |
| 43 |
""" |
| 44 |
``` |
| 45 |
|
| 46 |
If your project requires Dart Sass to transpile Sass to CSS, set the `DART_SASS_VERSION` and include the Dart Sass installation in the build step. |
| 47 |
|
| 48 |
```toml {file="netlify.toml" copy=true} |
| 49 |
[build.environment] |
| 50 |
DART_SASS_VERSION = "1.104.0" |
| 51 |
GO_VERSION = "1.27.0" |
| 52 |
HUGO_VERSION = "0.166.0" |
| 53 |
NODE_VERSION = "24.20.0" |
| 54 |
TZ = "Europe/Oslo" |
| 55 |
|
| 56 |
[build] |
| 57 |
publish = "public" |
| 58 |
command = """\ |
| 59 |
curl -sfLO "https://github.com/sass/dart-sass/releases/download/${DART_SASS_VERSION}/dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz" && \ |
| 60 |
tar -C "${HOME}/.local" -xf "dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz" && \ |
| 61 |
rm "dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz" && \ |
| 62 |
export PATH="${HOME}/.local/dart-sass:${PATH}" && \ |
| 63 |
git config --global core.quotepath false && \ |
| 64 |
hugo build --gc --minify --baseURL "${URL}" |
| 65 |
""" |
| 66 |
``` |
| 67 |
|
| 68 |
Step 2 |
| 69 |
: In the project configuration file in the root of your local Git repository, set the location of the image cache to the [`cacheDir`][] as shown below. |
| 70 |
|
| 71 |
{{< code-toggle file=hugo copy=true >}} |
| 72 |
[caches.images] |
| 73 |
dir = ':cacheDir/images' |
| 74 |
{{< /code-toggle >}} |
| 75 |
|
| 76 |
See [configure file caches][] for more information. |
| 77 |
|
| 78 |
Step 3 |
| 79 |
: Commit the changes to your local Git repository and push to your GitHub repository. |
| 80 |
|
| 81 |
Step 4 |
| 82 |
: In the upper right corner of the Netlify dashboard, press the **Add new project** button and select “Import an existing project". |
| 83 |
|
| 84 |
 |
| 85 |
|
| 86 |
Step 5 |
| 87 |
: Connect to GitHub. |
| 88 |
|
| 89 |
 |
| 90 |
|
| 91 |
Step 6 |
| 92 |
: Press the "Authorize Netlify" button to allow the Netlify application to access your GitHub account. |
| 93 |
|
| 94 |
 |
| 95 |
|
| 96 |
Step 7 |
| 97 |
: Press the **Configure Netlify on GitHub** button. |
| 98 |
|
| 99 |
 |
| 100 |
|
| 101 |
Step 8 |
| 102 |
: Select the GitHub account where you want to install the Netlify application. |
| 103 |
|
| 104 |
 |
| 105 |
|
| 106 |
Step 9 |
| 107 |
: Authorize the Netlify application to access all repositories or only select repositories, then press the Install button. |
| 108 |
|
| 109 |
 |
| 110 |
|
| 111 |
Your browser will be redirected to the Netlify dashboard. |
| 112 |
|
| 113 |
Step 10 |
| 114 |
: Click on the name of the repository you wish to import. |
| 115 |
|
| 116 |
 |
| 117 |
|
| 118 |
Step 11 |
| 119 |
: On the "Review configuration" page, enter a project name, leave the settings at their default values, then press the **Deploy** button. |
| 120 |
|
| 121 |
 |
| 122 |
|
| 123 |
 |
| 124 |
|
| 125 |
Step 12 |
| 126 |
: When the deployment completes, click on the link to your published site. |
| 127 |
|
| 128 |
 |
| 129 |
|
| 130 |
In the future, whenever you push a change from your local Git repository, Netlify will rebuild and deploy your site. |
| 131 |
|
| 132 |
## Related resources |
| 133 |
|
| 134 |
For more information on hosting and managing your site with Netlify, consult the official documentation: |
| 135 |
|
| 136 |
- [General documentation][] |
| 137 |
- [Custom domain setup][] |
| 138 |
|
| 139 |
[Custom domain setup]: https://docs.netlify.com/domains-https/custom-domains/ |
| 140 |
[General documentation]: https://docs.netlify.com/ |
| 141 |
[`cacheDir`]: /configuration/all/#cachedir |
| 142 |
[configure file caches]: /configuration/caches/ |
| 143 |
[remote]: https://git-scm.com/docs/git-remote |