1

I am trying to delpoy strapi project to shared host but always have same message Error Capture

have anyone uploaded strapi to cpanel give me the right way to deploy it

steps I made : 1-build project 2-made app.js file 3-add db 4-create node app (but also give error on npm install I don't now what the error so uploaded the node_moduls)

any one have any ideas about this problem

1 Answer 1

4

Took me a few days to get this figured. This is what I got working:

1st (failed) attempt was setting up a node.js app in CPanel as a folder under the domain. i.e. domainname.com/CMS. This would not route properly, no matter what I tried. Kept throwing 404s.

2nd (successful) was using a subdomain.

Three main steps:

  1. register a CNAME record on the domain for cms.domainname.com
  2. Configure and Build a new nodejs application in CPanel
  3. Bob's your uncle

Register a CNAME

Make sure your domain is configured with a CNAME record pointing at cms.domainname.com

Configure and Build

CPanel - Domain config

Under CPanel domains click Create a New Domain Create a New Domain

Configure your domain and save it Domain Configuration

CPanel - Create and configure

  1. In the nodeJS software page, create a new application and set it Create nodejs application
  2. Either checkout your code into the root directory configured above or build locally and ftp the build artifacts later.

The file structure of your folder on the server should look like this:

cms.domainname.com/
├── dist/    // build folder
└── server.js
└── package.json
└── .env

server.js

const strapi = require("@strapi/strapi");

// if you want logging enabled ... 
// uncomment and see instructions section below
// const logger = require("./dist/config/logger");

const app = strapi({ distDir: "./dist" });
app.start();

.env

HOST=0.0.0.0 // might want to use the static IP address here. Don't know. Haven't tested it
PORT=3000

JWT_SECRET=
ADMIN_JWT_SECRET=
APP_KEYS=
API_TOKEN_SALT=
TRANSFER_TOKEN_SALT=

EXTERNAL_URL=https://cms.domainname.com
DATABASE_CLIENT=mysql
DATABASE_HOST=cms-mysql
DATABASE_PORT=3306
DATABASE_NAME=cms
DATABASE_USERNAME=root
DATABASE_PASSWORD=
DATABASE_SSL= false

package.json

Just make sure it has the latest npm packages and the standard script commands:

scripts": {
    "dev": "strapi develop",
    "start": "strapi start",
    "build": "strapi build",
    "strapi": "strapi"
  },

Logging (optional)

If you want logging enabled:

  • install loggig package winston : npm i winston
  • edit/add a file to ./config/logger.ts with the following:
"use strict";

import winston, { level, transports } from "winston";

export default {
  level: "debug",
  format: winston.format.combine(
    winston.format.timestamp(),
    winston.format.json()
  ),
  transports: [
    new transports.Console({ level: "http" }),
    new transports.File({ filename: "http.log", level: "http" }),
    new transports.File({ filename: "debug.log", level: "debug" }),
    new transports.File({ filename: "warn.log", level: "warn" }),
    new transports.File({ filename: "error.log", level: "error" }),
    new transports.File({ filename: "combined.log" }),
  ],
};

Build (through ssh)

  • install packages:npm i --omit=dev
  • build: npm run build
 note: you need to rebuild every time you make a change to the code OR the `.env` file. 
  • Run: npm start

That should do it. You might need to access the application through the CPanel nodejs application dashboard and explicitly start it through the UI.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.