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
-
Open your terminal and navigate to your React project folder:
-
Run the build command:
(or for Yarn users:
yarn build) -
This will create a
build/folder with optimized HTML, CSS, and JavaScript files.
2️⃣ Upload Files to cPanel
Method 1: Using File Manager (Recommended)
- Log in to cPanel.
- Open File Manager → Navigate to
public_html/. - Delete any old files (if necessary).
- Upload the contents of the
build/folder (not the folder itself) topublic_html/.
Method 2: Using FTP (Alternative)
- Use FileZilla or another FTP client to upload the contents of the
build/folder intopublic_html/.
3️⃣ Set Up .htaccess for React Routing (SPA Support)
-
Inside
public_html/, create or edit the.htaccessfile. -
Add the following code to enable React's client-side routing:
4️⃣ Check Your Website
- Open your browser and visit: 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.
