skip to Main Content

I have developed a react app with strapi as the backend locally. Now I have successfully uploaded the react app on cpanel but I am unable to upload strapi because of the limited resources available on the internet. Kindly assist

I tried using this article from strapi but its too shallow as it does not provide way of doing it

2

Answers


  1. Do the build locally.
    When you can initiate the build locally you can either upload it to Git or manually zip it(don’t include node modules)

    Either pull the code from Git or unpack it in the needed directory.
    When that’s done you can do npm install to validate node modules and serve the application.

    I tried the zipping method:

    1. Create a new project by npx create-strapi-app@latest yourprojectname
    2. Add your needed configurations(database credentials to ENV, etc..)
    3. Run npm run strapi build locally.
    4. Package the whole folder into a zip(without the node modules)
    5. Drop the zipped file into your FTP or the location where you would like to unzip the package
    6. Unzip the package (if you’re on a Linux machine you can use unpack filename.zip command)
    7. If everything is unpacked run npm install
    8. If all the node modules are installed you should be good to go.
    9. Run the application via npm run strapi start.
    Login or Signup to reply.
  2. Okay. Since somebody was kind enough to delete my post, as it ‘was not asking question’ or so, I had to come to the solution myself.

    I am sharing it with you below:

    SETTING THE STRAPI CMS ON A CPANEL SHARED HOSTING (I did it with v4)

    Actions on your local machine:

    • create a new mysql database

    • create a new Strapi project with: npx create-strapi-app@latest my-project

    • populate its .env file with:

    DATABASE_CLIENT=mysql2
    DATABASE_HOST=localhost
    DATABASE_PORT=3306
    DATABASE_NAME='YOUR DB NAME HERE'
    DATABASE_USERNAME='YOURMYSQL USER NAME HERE'
    DATABASE_PASSWORD='YOUR MYSQL PASSWORD HERE'

    • install mysql2 db client with: npm install mysql2 --save

    • build Strapi admin panel with: npm run develop

    • run the Strapi app, add user (write down user login credentials!) and
      some data models with: npm run start

    • to enable REST API access to your data models, when in dashboard go
      to: settings->users & permissions plugin/Roles->public click on the
      data models you want to give permissions to, and select which ones
      you want. For public access to Post model, check the 'find' and
      'findOne' fields and save

    • !!! ADDING NEW DATA MODELS IS POSSIBLE ONLY IN LOCAL ENVIRONMENT
      (READ THIS AFTER YOU SET THE APP): WHEN ADDING A NEW DATA MODEL TO
      EXISTING HOSTED APP, FIRST RUN IT WITH 'NPM RUN DEVELOP', AND MAKE
      YOUR CHANGES. REBUILD THE APP AND PLACE THE BUILD FOLDER IN THE
      PROJECT’S LOCATION ON CPANEL! EXPORT THE LOCAL DB AND IMPORT IT TO THE CPANEL’S DB.

    • build the Strapi app with: npm run build

    • zip all app files except node_modules

    • export your mysql database with: mysqldump -u root -S /var/run/mysqld/mysqld.sock -p DATABASE NAME HERE > ~/Desktop/strapi_backup.sql

    Actions on your CPanel:

    • create a subdomain: subdomain.yourwebsite.com

    • create a new DB and attach a user to it with all privileges

    • import your local mysql DB dump file (with auto-pre-populated
      strapi-related settings) into PhpMyAdmin interface

    create a new nodejs app (CPanel interface for creating nodejs apps):

    • select NodeJS version to: 18+ or 20+

    • set application mode to: Production

    • set application root to where your project folder is:
      /home/yourusername/public_html/subdomain.yourwebsite.com

    • set application url to your subdomain: subdomain.yourwebste.com

    • set application startup file: server.js

    • save

    • copy the command to access the virtual environment on your server.
      This one is found in a paragraph at the top of the same interface for
      creating the nodejs app, just under the ‘Destroy’, ‘Cancel’ and
      ‘Save’ buttons. And it looks like this: Enter to the virtual environment.To enter to virtual environment, run the command: source/home/yourusername/nodevenv/public_html/subdomain.yourwebsite.com/20/bin/activate && cd /home/yourusername/public_html/subdomain.yourwebsite.com

    • enter the terminal from your CPanel and paste the command above. You
      should now be inside the project directory on your CPanel’s virtual
      server environment.

    • install the project’s dependencies from package.json with: npm install

    • open another tab and use your file manager. Navigate to the folder
      where your project is, confirm that you see the node_modules folder
      installed there.

    • create the application’s entrypoint file (server.js). It should have the following:

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

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

    app.start();

    • start the application from the terminal where you ran ‘npm install’, with: npm run start

    • your app should now start at the 0.0.0.0:1337, but you cannot access it still.

    • go to the project’s folder, in the top right corner click 'Settings'and check the show hidden files option.

    • you should see .htaccess file now. It should look like this:

    #DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION BEGIN

    PassengerAppRoot "/home/yourusername/public_html/subdomain.yourwebsite.com"

    PassengerBaseURI "/" PassengerNodejs

    "/home/yourusername/nodevenv/public_html/subdomain.yourwebsite.com/20/bin/node"
    PassengerAppType node PassengerStartupFile server.js

    #DO NOT REMOVE.CLOUDLINUX PASSENGER CONFIGURATION END

    • modify your .htaccess to look like this, and you should be ready to go afterwards:

    #DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION BEGIN

    PassengerAppRoot "/home/yourusername/public_html/subdomain.yourwebsite.com"

    PassengerBaseURI "/" PassengerNodejs

    "/home/yourusername/nodevenv/public_html/subdomain.yourwebsite.com/20/bin/node"
    PassengerAppType node PassengerStartupFile server.js

    <ifModule>

    RewriteEngine on

    RewriteRule (.*) http://127.0.0.1:1337/$1 [P]

    </IfModule>

    #DO NOT REMOVE.CLOUDLINUX PASSENGER CONFIGURATION END

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