???? How to Host a React.js App in cPanel

You can host your React.js app in cPanel by building a static version of your app and uploading it to the public_html/ directory.


1️⃣ Build Your React App for Production

  1. Open your terminal and navigate to your React project folder:

    bash
    cd /path/to/your-react-app
  2. Run the build command:

    bash
    npm run build

    (or for Yarn users: yarn build)

  3. This will create a build/ folder with optimized HTML, CSS, and JavaScript files.


2️⃣ Upload Files to cPanel

Method 1: Using File Manager (Recommended)

  1. Log in to cPanel.
  2. Open File Manager → Navigate to public_html/.
  3. Delete any old files (if necessary).
  4. Upload the contents of the build/ folder (not the folder itself) to public_html/.

Method 2: Using FTP (Alternative)

  • Use FileZilla or another FTP client to upload the contents of the build/ folder into public_html/.

3️⃣ Set Up .htaccess for React Routing (SPA Support)

  • Inside public_html/, create or edit the .htaccess file.

  • Add the following code to enable React's client-side routing:

    apache
    <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.html$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.html [L] </IfModule>

4️⃣ Check Your Website

  • Open your browser and visit:
    arduino
    https://yourdomain.com
    Your React app should now be live! ????

⚠️ Common Issues & Fixes

???? 404 Page Not Found?
✔️ Ensure .htaccess is set correctly to enable React routing.

???? Old Version Loading?
✔️ Clear browser cache or force reload (Ctrl + Shift + R).

???? CORS Issues with APIs?
✔️ Enable CORS headers on your backend or use a proxy.

  • 0 Users Found This Useful
Was this answer helpful?