Setup to Deploy React.js App on cPanel

Setup to Deploy React.js App on cPanel

šŸš€ Setup to Deploy React.js App on cPanel

Follow these steps to deploy your React app on a cPanel server:


1ļøāƒ£ Create and Build Your React App

  1. Open a terminal or command prompt.

  2. Navigate to the directory where you want to create the React app.

    # npx create-react-app your-app-nameĀ 
  3. Go to the app’s root directory:

    # cd your-app-name
  4. Open package.json in a text editor and add your domain:

    "homepage": "http://yourdomain.com"
  5. Install dependencies:

    # npm installĀ # or yarn install
  6. Build the production files:

    #Ā  npm run build
    Ā or
    # yarn build

2ļøāƒ£ Add .htaccess for React Routing

Inside the public folder of your React app, create a file named .htaccess and add this:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]

šŸ‘‰ This ensures React handles routing properly (avoids 404 on refresh).


3ļøāƒ£ Upload Files to cPanel

  1. Log in to cPanel.

  2. Open File Manager.

  3. Go to the public_html directory (or the addon domain folder if using a subdomain/domain).

  4. Upload the contents of the build folder (not the folder itself, just its contents).

  5. Save and confirm.


4ļøāƒ£ Verify Deployment

  • Open your domain in the browser → it should load your React app.

  • If you see issues with routing, double-check the .htaccess file.

Share

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Angry Angry 0
Sad Sad 0
Wow Wow 0