skip to Main Content

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

2

Answers


  1. 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.

    Login or Signup to reply.
  2. Would you please specify where did you get the ‘dist’ folder from, since strapi has ‘build’ folder, at least v4.24.4?

    I have a local mysql db which I’ve used to run strapi locally, and initialize the admin panel and add some data.

    I then logged to cpanel, made a fresh db and connected a user to it, and imported my local mysql db to the cpanel db.

    Then I changed my .env file to correspond to the cpanel parameters and built the app locally (with NODE_ENV=production).

    I uploaded the .zip of all local app files (except the node modules) and unpacked it.

    Then I created nodejs app and added your server.js file, both to the folder (creating a new file) and as an application startup file in the create node app UI.

    And nothing happens when I start the app and visit my domain.

    Any idea what I might be missing here?

    Anyways, you did a great work if you made this running on a cpanel.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search