Installing a React website on a standard cPanel hosting

Installing a React website on a standard cPanel hosting account involves creating a production build on your local machine and then uploading those static files to your server. Our servers don't need any special changes; this is the standard procedure for all cPanel based servers. Following are easy step by step instructions to do so:

 

1.  Prepare Your Production Build

React code must be converted into standard HTML, CSS, and JavaScript that web browsers can read. 

  • Set Homepage: Open your package.json file and add "homepage": "." or "homepage": "http://yourdomain.com" to ensure file paths resolve correctly after deployment.
  • Run Build Command: In your project's terminal, execute npm run build (or yarn build).

This generates a build/ folder (or dist/ if using Vite) containing your production-ready files.

  • Compress Files: Navigate into the build/ or dist/ folder, select all files inside, and compress them into a single .zip archive.  

 

2.  Upload to cPanel

  • Access File Manager: Log in to your cPanel account and open the File Manager.
  • Select Directory: Navigate to the public_html directory for your main domain, or the specific folder for a subdomain.
  • Upload and Extract: Use the cPanel Upload tool to upload your .zip file. Once uploaded, right-click the file and select Extract.  

  

3.  Configure Client-Side Routing 

If your app uses React Router, you must redirect all traffic to index.html to avoid 404 errors on page refreshes.  

  • Create .htaccess: In the same directory as your uploaded files, create a new file named .htaccess
  • Add Rules: Paste the following boilerplate code into the file and save:

 <IfModule mod_rewrite.c>

  RewriteEngine On

  RewriteBase /

  RewriteRule ^index\.html$ - [L]

  RewriteCond %{REQUEST_FILENAME} !-f   RewriteCond %{REQUEST_FILENAME} !-d

  RewriteCond %{REQUEST_FILENAME} !-l   RewriteRule . /index.html [L]

</IfModule>

Was this answer helpful?

 Print this Article

Also Read

Can you migrate/move my web site for me from my existing host for FREE?

Yes, we can do this for you for FREE. Simply contact our support department with the following...

I uploaded my HTML files, but I am still seeing your default page?

Your main file (web page) must be named as index.*  Example: "index.html",...

Can I make or use my own PHP or PERL scripts?

Yes, you can make and use your own or any 3rd-party scripts without any problems. We also offer...

Is there any book or guide available to teach me the use of my web hosting control panel?

Yes there is: visit http://www.cpanel.net/support/docs/11/cpanel/ or check the...

Do you allow wildcard subdomains so that anything.mydomain.com points to mydomain.com?

Yes wildcard sub-domains are allowed and *.yourdomain.com can point to yourdomain.com. Simply...