Deploy with FTP
Use these instructions to deploy your site to a web server with an FTP client.
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
publicdirectory. 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 thepublicdirectory before you build, or build with the--cleanDestinationDirflag or thecleanDestinationDirconfiguration 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
publicdirectory 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:
- Create a Hugo project and test it with the
hugo servercommand. - Set the
baseURLin your project configuration to the URL of your production site. - 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.
- 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
publicdirectory to the document root.Upload the files and directories inside the
publicdirectory, not thepublicdirectory itself. For example, theindex.htmlfile 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
publicdirectory. See configure build. --gc- Removes unused files from the file cache. See configure file caches.
--minify- Minifies the output. See configure minify.
