How do I set up a Strapi App on a Phusion Passenger NodeJS environment

249 views Asked by At

I have this hoster that use Phusion Passenger for the NodeJS environment and I want to run my Strapi App on it.

For now I did the following:

  1. Strapi and the node modules are installed on the server
  2. The app is connected to the database
  3. the app.js can start fine

I don't know how to configure my app.js file to make it launch Strapi

I did something like this but I'm pretty sure this is wrong:

const http = require("http");
const hostname = "127.0.0.1";
const port = "passenger";
const strapi = require("@strapi/strapi");

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader("Content-Type", "text/plain");
  res.end("Hello World! NodeJS");
});

server.listen(port, hostname, () => {
  console.log(`Server running at https://somary.fr/`);
  strapi().start();
});

How do I configure my app.js file to finally access my strapi app?

2

There are 2 answers

0
DBlocher On

I'm deploying a [email protected] app on Phusion Passenger.

Here is my updated app.js file:

const strapi = require("@strapi/strapi");
strapi({ dir: "./build" }).start();

To create the build folder, you need to run:

npm run build

I hope I helped.

0
Fabus On

In my case Phusion Passenger was explicitly looking for a server.js (not app.js | index.js) on my managed hosting (plesk, phusion passenger, ...).

Also pm2 and mysql were not installed, since access is restricted to install stuff globally. So I had to make a way around.

CAREFUL: in config/server.js is a file dedicated to configure your server. Though this is not the one you want to set as the entry point of your app.

Here's what I did:

  1. install pm2 and mysql
npm install pm2 mysql
  1. create a server.js file (in my root: ./server.js) with following contents
const strapi = require('@strapi/strapi');
strapi(/* {...} */).start();
  1. rebuild my admin webapp
npm run build
  1. build my app for production
npm run production

ps: make sure to have the proper ports and url set up in your .env file