-
Notifications
You must be signed in to change notification settings - Fork 0
Strapi application setup
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.
-
Login to the remote server
ssh <user>@<host>. Make sure that you are using the sameuseras you define in your local.envfile. -
Create an ssh key
cd ~/.ssh
ssh-keygen -f github_JeffreyArts_jeff_payload -t ecdsa -b 521
Replace <github_username> with the username that the repo belongs to, and replace <repo> with the name of the repo.
- Update (or create)
~/.ssh/configfile
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/github_<github_username>_<repo>
If this code already exists, you can add a new one underneath like so; and modify the repo url in the ecosystem file.
Host <custom-host>.github.com
HostName github.com
User git
IdentityFile ~/.ssh/github_<github_username>_<repo>
For consistency / transparent communication, id is advisable to use the host-name for a custom-host property
repo: "git@<custom-host>.github.com:<github_username>/<repo>.git",
- 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>.pubhere. Leaveallow write accessunchecked!
These are all the required steps needed for pm2 to be able to setup the deployment flow.
- Download the
ecosystem.config.jsfile and place it in the root of your project. - Run
export NODE_ENV=production; 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
userwith the username required to login to the remote server. - Replace
hostwith the name of the server (no www, https or other prefixes, ip address could be fine as well) - Replace
projectwith the name of the directory that you want to install the project - Replace
github_username&repowith the same properties of the repo where you added the deploy key to
-
Copy .env file to remote server
scp .env <user>@<host>:/var/www/strapi/<project>/source -
Test if deployment works
pm2 deploy ecosystem.config.js production --force -
Update package.json If deployment works, add
"deploy": "pm2 deploy ecosystem.config.js production"to the package.json file
Now that the deployment flow is working, we need to complete the nginx configuration.
- Log in to the server via ssh, and call
create_strapi_server www.example.com, this will prompt you for the location of your Strapi application (/var/www/strapi//source) and set-up the NGINX configuration, including SSL via certbot. - Configure Strapi Go to https://www.example.com/admin and create a admin account, setting up a new Strapi environment will not take over any data. So make sure that you manually go through your configuration settings to validate if everything is configured as it should.
You can now deploy the application with yarn deploy.