run strapi4 or strapi5 on plesk obsidian 18
In this short guide, I will demonstrate how to host a strapi4 or strapi5 on a linux server managed with plesk obsidian. Let's get started!
strapi4 setup (4.25.13)
In your strapi4 folder (repository) add a file named index.js
and put that content into it:
// /<strapi-root-folder>/index.js
const strapi = require('@strapi/strapi');
strapi(/* {...} */).start();
This file is where you point your Application Startup File in the Node.js settings in plesk.
Make sure to run strapi4 with Node >= 18 and Node <= 20, like it is pointed out under engines
in the package.json of the strapi folder.
In addition you need to configure your database connection and you're good to go.
By default strapi4 uses a sqlite database, which gives you the "battery included" feeling when start a new strapi project, but if you want to use a mysql/mariadb connection on your server follow these steps:
$ npm i mysql
And provide all database connection information:
I still run npm ci
and npm run build
via ssh
because the output after I ran the build
command using the "Run script" button confuses me. It tells me that NODE_ENV
is not set and this feedback I do not get via shell.
strapi5 setup (5.1.0)
In your strapi5 folder (repository) create a file name index.js
with that content - this content differs from strapi4! Check out the strapi docs.
// /<strapi-root-folder>/index.js
const strapi = require('@strapi/strapi');
strapi.createStrapi(/* {...} */).start();
This file is where you point your Application Startup File in the Node.js settings in plesk.
Make sure you use a node version supported by strapi, for strapi5 you can use Node >= 18 and Node <= 22.
Assuming you want to use a mysql
database, make sure you have the mysql2
package installed:
$ npm i mysql2
See, strapi5 is using mysql2
package, and strapi4 is using the mysql
package. All database connection information will be setup via the plesk interface. You could also put them into your .env
file.
troubleshooting
You might experience a "Passenger Error Page" on your first steps, and to get a clue about what is going wrong you need to ssh
to your server as root
and do a tail -f /var/log/passenger/passenger.log
. Everytime you reload the strapi page this file will give you information about errors.
For example if the database connection did not work, or that the jwtSecret
is missing.
And the nice thing is, strapi developers put all information to create such a string into the error message! You can start node on your local machine $ node
and than put that into the console:
const {
randomBytes,
} = require('node:crypto');
randomBytes(16).toString('base64');
That's it. Happy strapi'ing!