HUGO
Menu
GitHub 90066 stars Mastodon

Deploy with FTP

Deploy your site to a web server with an FTP client.

Use these instructions to deploy your site to a web server with an FTP client.

If your hosting provider offers SSH access, deploy with Rsync or Rclone instead. Both tools transfer only the files that changed and remove orphaned files automatically.

Deployment constraints

Deploying a Hugo site to a web server requires more than copying files. For example, typical FTP clients do not remove orphaned files from the server, and compare files by modification time and size.

  • Deployments must remove orphaned files. When you rename a page, change its permalink, or delete content, Hugo does not remove the corresponding files from your local public directory. Hugo also leaves a page’s files in place when the page becomes a draft, expires, or has its publication date changed to a future date. To remove these files, clear the public directory before you build, or build with the --cleanDestinationDir flag or the cleanDestinationDir configuration option enabled. Unless your deployment also removes them from the server, the old pages remain online.

  • Deployments should compare files by checksum. Hugo updates the modification time of every file in the public directory on every build, so tools that compare modification times transfer your entire site each time. Tools that compare only file size can miss changed files, because editing text does not always change a file’s size.

FTP clients do not meet these requirements. The procedure below removes orphaned files by deleting the contents of the document root before each upload, and uploads every file each time you deploy.

Prerequisites

Please complete the following tasks before continuing:

  1. Create a Hugo project and test it with the hugo server command.
  2. Set the baseURL in your project configuration to the URL of your production site.
  3. Obtain the host name, user name, and password for your hosting account, and the path to the document root, the directory from which your web server serves files.
  4. Install an FTP client that supports SFTP.

If your hosting provider supports SFTP, use it instead of FTP. FTP sends your password and files without encryption.

Procedure

Step 1
Build your site from the root of your project.
hugo build --cleanDestinationDir --gc --minify
Step 2
Connect to your web server with your FTP client and open the document root.
Step 3
Delete the contents of the document root.
Step 4
Upload the contents of the public directory to the document root.

Upload the files and directories inside the public directory, not the public directory itself. For example, the index.html file for your home page must be at the top level of the document root.

Your site is incomplete from the moment you delete the contents of the document root until the upload finishes.

Command-line flags

The hugo build command uses these flags:

--cleanDestinationDir
Removes orphaned files from the public directory. See configure build.
--gc
Removes unused files from the file cache. See configure file caches.
--minify
Minifies the output. See configure minify.