github.com/lyeb/hugo@v0.47.1/docs/content/en/hosting-and-deployment/hosting-on-netlify.md (about)

     1  ---
     2  title: Host on Netlify
     3  linktitle: Host on Netlify
     4  description: Netlify can host your Hugo site with CDN, continuous deployment, 1-click HTTPS, an admin GUI, and its own CLI.
     5  date: 2017-02-01
     6  publishdate: 2017-02-01
     7  lastmod: 2017-03-11
     8  categories: [hosting and deployment]
     9  keywords: [netlify,hosting,deployment]
    10  authors: [Ryan Watters, Seth MacLeod]
    11  menu:
    12    docs:
    13      parent: "hosting-and-deployment"
    14      weight: 10
    15  weight: 10
    16  sections_weight: 10
    17  draft: false
    18  aliases: []
    19  toc: true
    20  ---
    21  
    22  [Netlify][netlify] provides continuous deployment services, global CDN, ultra-fast DNS, atomic deploys, instant cache invalidation, one-click SSL, a browser-based interface, a CLI, and many other features for managing your Hugo website.
    23  
    24  ## Assumptions
    25  
    26  * You have an account with GitHub, GitLab, or Bitbucket.
    27  * You have completed the [Quick Start][] or have Hugo website you are ready to deploy and share with the world.
    28  * You do not already have a Netlify account.
    29  
    30  ## Create a Netlify account
    31  
    32  Go to [app.netlify.com][] and select your preferred signup method. This will likely be a hosted Git provider, although you also have the option to sign up with an email address.
    33  
    34  The following examples use GitHub, but other git providers will follow a similar process.
    35  
    36  ![Screenshot of the homepage for app.netlify.com, containing links to the most popular hosted git solutions.](/images/hosting-and-deployment/hosting-on-netlify/netlify-signup.jpg)
    37  
    38  Selecting GitHub will bring up an authorization modal for authentication. Select "Authorize application."
    39  
    40  ![Screenshot of the authorization popup for Netlify and GitHub.](/images/hosting-and-deployment/hosting-on-netlify/netlify-first-authorize.jpg)
    41  
    42  ## Create a New Site with Continuous Deployment
    43  
    44  You're now already a Netlify member and should be brought to your new dashboard. Select "New site from git."
    45  
    46  ![Screenshot of the blank Netlify admin panel with no sites and highlighted 'add new site' button'](/images/hosting-and-deployment/hosting-on-netlify/netlify-add-new-site.jpg)
    47  
    48  Netlify will then start walking you through the steps necessary for continuous deployment. First, you'll need to select your git provider again, but this time you are giving Netlify added permissions to your repositories.
    49  
    50  ![Screenshot of step 1 of create a new site for Netlify: selecting the git provider](/images/hosting-and-deployment/hosting-on-netlify/netlify-create-new-site-step-1.jpg)
    51  
    52  And then again with the GitHub authorization modal:
    53  
    54  ![Screenshot of step 1 of create a new site for Netlify: selecting the git provider](/images/hosting-and-deployment/hosting-on-netlify/netlify-authorize-added-permissions.jpg)
    55  
    56  Select the repo you want to use for continuous deployment. If you have a large number of repositories, you can filter through them in real time using repo search:
    57  
    58  ![Screenshot of step 1 of create a new site for Netlify: selecting the git provider](/images/hosting-and-deployment/hosting-on-netlify/netlify-create-new-site-step-2.jpg)
    59  
    60  Once selected, you'll be brought to a screen for basic setup. Here you can select the branch you wanted published, your [build command][], and your publish (i.e. deploy) directory. The publish directory should mirror that of what you've set in your [site configuration][config], the default of which is `public`. The following steps assume you are publishing from the `master` branch.
    61  
    62  ## Configure Hugo Version in Netlify 
    63  
    64  You can [set Hugo version](https://www.netlify.com/blog/2017/04/11/netlify-plus-hugo-0.20-and-beyond/) for your environments in `netlify.toml` file or set `HUGO_VERSION` as a build environment variable in the Netlify console.
    65  
    66  For production:
    67  
    68  ```
    69  [context.production.environment]
    70    HUGO_VERSION = "0.36"
    71  ```
    72  
    73  For testing:
    74  
    75  ```
    76  [context.deploy-preview.environment]
    77    HUGO_VERSION = "0.36"
    78  ```
    79  
    80  The Netlify configuration file can be a little hard to understand and get right for the different environment, and you may get some inspiration and tips from this site's `netlify.toml`:
    81  
    82  {{< code file="netlify.toml" nocode="true" >}}
    83  {{< readfile file="netlify.toml" highlight="toml" >}}   
    84  {{< /code >}}
    85  
    86  ## Build and Deploy Site
    87  
    88  In the Netlify console, selecting "Deploy site" will immediately take you to a terminal for your build:.
    89  
    90  ![Animated gif of deploying a site to Netlify, including the terminal read out for the build.](/images/hosting-and-deployment/hosting-on-netlify/netlify-deploying-site.gif)
    91  
    92  Once the build is finished---this should only take a few seconds--you should now see a "Hero Card" at the top of your screen letting you know the deployment is successful. The Hero Card is the first element that you see in most pages. It allows you to see a quick summary of the page and gives access to the most common/pertinent actions and information. You'll see that the URL is automatically generated by Netlify. You can update the URL in "Settings."
    93  
    94  ![Screenshot of successful deploy badge at the top of a deployments screen from within the Netlify admin.](/images/hosting-and-deployment/hosting-on-netlify/netlify-deploy-published.jpg)
    95  
    96  ![Screenshot of homepage to https://hugo-netlify-example.netlify.com, which is mostly dummy text](/images/hosting-and-deployment/hosting-on-netlify/netlify-live-site.jpg)
    97  
    98  [Visit the live site][visit].
    99  
   100  Now every time you push changes to your hosted git repository, Netlify will rebuild and redeploy your site.
   101  
   102  See [this blog post](https://www.netlify.com/blog/2017/04/11/netlify-plus-hugo-0.20-and-beyond/) for more details about how Netlify handles Hugo versions.
   103  
   104  ## Use Hugo Themes with Netlify
   105  
   106  The [`git clone` method for installing themes][installthemes] is not supported by Netlify. If you were to use `git clone`, it would require you to recursively remove the `.git` subdirectory from the theme folder and would therefore prevent compatibility with future versions of the theme.
   107  
   108  A *better* approach is to install a theme as a proper git submodule. You can [read the GitHub documentation for submodules][ghsm] or those found on [Git's website][gitsm] for more information, but the command is similar to that of `git clone`:
   109  
   110  ```
   111  cd themes
   112  git submodule add https://github.com/<THEMECREATOR>/<THEMENAME>
   113  ```
   114  
   115  It is recommended to only use stable versions of a theme (if it’s versioned) and always check the changelog. This can be done by checking out a specific release within the theme's directory.
   116  
   117  Switch to the theme's directory and list all available versions:
   118  
   119  ```
   120  cd themes/<theme>
   121  git tag
   122  # exit with q
   123  ```
   124  
   125  You can checkout a specific version as follows:
   126  
   127  ```
   128  git checkout tags/<version-name>
   129  ```
   130  
   131  ## Next Steps
   132  
   133  You now have a live website served over https, distributed through CDN, and configured for continuous deployment. Dig deeper into the Netlify documentation:
   134  
   135  1. [Using a Custom Domain][]
   136  2. [Setting up HTTPS on Custom Domains][httpscustom]
   137  3. [Redirects and Rewrite Rules][]
   138  
   139  
   140  [app.netlify.com]: https://app.netlify.com
   141  [build command]: /getting-started/usage/#the-hugo-command
   142  [config]: /getting-started/configuration/
   143  [ghsm]: https://github.com/blog/2104-working-with-submodules
   144  [gitsm]: https://git-scm.com/book/en/v2/Git-Tools-Submodules
   145  [httpscustom]: https://www.netlify.com/docs/ssl/
   146  [hugoversions]: https://github.com/netlify/build-image/blob/master/Dockerfile#L216
   147  [installthemes]: /themes/installing/
   148  [netlify]: https://www.netlify.com/
   149  [netlifysignup]: https://app.netlify.com/signup
   150  [Quick Start]: /getting-started/quick-start/
   151  [Redirects and Rewrite Rules]: https://www.netlify.com/docs/redirects/
   152  [Using a Custom Domain]: https://www.netlify.com/docs/custom-domains/
   153  [visit]: https://hugo-netlify-example.netlify.com