
How to deploy PayloadCMS to Digitialocean and connect to S3 bucket
21 November, 2022
8
8
1
Contributors
Step 1 - Create droplet.

Step 1.2 - Initial server setup.
Step 1.3 - Add an admin user.
Step 1.4 - Set up a basic firewall.
Step 2 - Change nameservers.
Step 3 - Add your domain to the Networking tab.
Step 4 - Install Nginx.
Step 4.1 - Set up server block.
When using the Nginx web server, server blocks (similar to virtual hosts in Apache) can be used to encapsulate configuration details and host more than one domain from a single server.
index.html
file within the /var/www
directory -index.html
pageSave and close the file by pressing Ctrl+X to exit, then when prompted to save, Y and then Enter.
index.html
with our PayloadCMS instance but for now we'll keep the index.html
to make sure that we are able to access everything correctly over HTTP/HTTPS.sites-enabled
directoryTo avoid a possible hash bucket memory problem that can arise from adding additional server names, it is necessary to adjust a single value in the /etc/nginx/nginx.conf file. Open the file:
Find the server_names_hash_bucket_size directive and remove the # symbol to uncomment the line. If you are using nano, you can quickly search for words in the file by pressing CTRL and w.
Step 4.2 - Secure Nginx with Let's encrypt.
Certbot provides a variety of ways to obtain SSL certificates through plugins. The Nginx plugin will take care of reconfiguring Nginx and reloading the config whenever necessary. To use this plugin, type the following:
Let’s Encrypt’s certificates are only valid for ninety days. This is to encourage users to automate their certificate renewal process. The certbot package we installed takes care of this for us by adding a systemd timer that will run twice a day and automatically renew any certificate that’s within thirty days of expiration.
You can query the status of the timer with systemctl:
If you see no errors, you’re all set. When necessary, Certbot will renew your certificates and reload Nginx to pick up the changes. If the automated renewal process ever fails, Let’s Encrypt will send a message to the email you specified, warning you when your certificate is about to expire.
index.html
via your domain.Step 5 - Connect to MongoDB.
Step 6 - Setting up cloud storage with S3 bucket.
Step 6.1 - Generating access keys via AWS IAM.
Access key
. Then give the AmazonS3FullAccess
policy to the user.Step 6.2 - Add a bucket policy (Optional)
Step 6.3 - Install & set up payloadcms/plugin-cloud-storage
npm install @payloadcms/plugin-cloud-storage
to install the package and configure your payload.config.ts
according to your own preferences. Here's my setup for reference -Step 6.4 - disableLocalStorage.
Step 7 - Create a repository on Github.
Step 8 - Set up Node for production.
git clone your_repository_url
.cd
into your repo and install all the dependencies for your project by running npm install
.npm run dev
to start up a development session on http://localhost:your_project_port/admin. This session isn't publically accessible however if you open up another terminal and connect to your droplet via SSH, you should be able to connect to your development session using curl -Step 9 - Install & configure PM2
PM2 makes it possible to daemonize applications so that they will run in the background as a service.
payload.config.ts
make sure to change your URL endpointnpm run build
. If you get stuck, have a look at your package.json
file and make sure the scripts are configured correctly. Here's mine for reference -Applications that are running under PM2 will be restarted automatically if the application crashes or is killed, but we can take an additional step to get the application to launch on system startup using the startup subcommand.
As an additional step, we can save the PM2 process list and corresponding environments:
Start the service with systemctl:
If at this point you encounter an error, you may need to reboot, which you can achieve with sudo reboot
.
Check the status of the systemd unit:
Step 10 - Set up reverse proxy
Within the server block, you should have an existing location / block. Replace the contents of that block with the following configuration.
3000
with your own port and restart the Nginx serverStep 10.2 - Adjust upload file size
Thanks for reading. If you enjoyed this article make sure to leave a like and feel free to share your thoughts down below in the comment section. Let's connect!
headless
s3
develevate
howto
digitalocean