Skip to content

Strapi application setup

Jeffrey Arts edited this page Apr 16, 2023 · 12 revisions

For a Strapi application, we use pm2 for deployment. This will create a node instance on the server. The create_strapi_site command will add the required configuration to nginx. In the current set-up there is no support yet for multiple Strapi running on the same server. But this can easily be achieved by modifying the create_strapi_site so it will prompt for the right port number. This port number should then be equal to the PORT number in the .env file.

Setup

Remote environment preparations

  1. Login to the remote server ssh <user>@<host>. Make sure that you are using the same user as you define in your local .env file.

  2. Create an ssh key

cd ~/.ssh 
ssh-keygen -f github_<github_username>_<repo> -t ecdsa -b 521


Replace <github_username> with the username that the repo belongs to, and replace <repo> with the name of the repo. 3) Update (or create) ~/.ssh/config file

Host github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/github_<github_username>_<repo>

If this code already exists, you can copy the IdentityFile line, and use your newly created keyfile

  1. Add ssh key to the list of deploy keys of your repo Go to your repo, and go to settings > deploy keys > add deploy key. For the title use @, and paste the contents of ~/.ssh/github_<github_username>_<repo>.pub here. Leave allow write access unchecked!

These are all the required steps needed for pm2 to be able to setup the deployment flow.

Local environment

  1. Download the ecosystem.config.js file and place it in the root of your project.
  2. Run pm2 deploy production setup
DEPLOYMENT_USER=<user>
DEPLOYMENT_HOST=<host>
DEPLOYMENT_PATH=/var/www/strapi/<project>
DEPLOYMENT_REPO=git@github.com:<github_username>/<repo>.git
  • Replace the user with the username required to login to the remote server.
  • Replace host with the name of the server (no www, https or other prefixes, ip address could be fine as well)
  • Replace project with the name of the directory that you want to install the project
  • Replace github_username & repo with the same properties of the repo where you added the deploy key to
  1. Copy .env file to remote server scp .env <user>@<host>:/var/www/strapi/<project>/source

  2. Test if deployment works pm2 deploy ecosystem.config.js production --force

Clone this wiki locally