A React single-page app runs entirely in the visitor’s browser. The hosting server only has to deliver index.html and the JavaScript and CSS bundles, so there is nothing to install on the server. Most problems come from three things: the base path, environment variables that are only read at build time, and the missing fallback rule for client-side routes.
Prerequisites
- Node.js 20 or 24 on your computer, and a project that runs with
npm run dev. - The final address: the domain root (
example.com) or a subfolder (example.com/app/). - The URL of your API, if the app calls one.
- A domain pointing to your hosting account.
Step-by-step deployment
1. Set the base path
At the domain root you can skip this step. For a subfolder:
- Vite: in
vite.config.jsaddbase: "/app/". - Create React App: in
package.jsonadd"homepage": "/app". - React Router: use
<BrowserRouter basename="/app">(or thebasenameoption ofcreateBrowserRouter).
2. Set build-time environment variables
Variables are inlined into the JavaScript during the build, so the server can’t change them later. Put them in .env.production:
# Vite
VITE_API_URL=https://api.example.com
# Create React App
REACT_APP_API_URL=https://api.example.com
Read them in code as import.meta.env.VITE_API_URL (Vite) or process.env.REACT_APP_API_URL (CRA). Never put secret keys here: everything in the bundle is visible to visitors.
3. Build and preview
npm ci
npm run build
npm run preview # Vite: test the production build locally
Vite writes to dist/, Create React App to build/.
4. Upload to public_html
Compress the contents of dist/ or build/ into a ZIP, so index.html sits at the top of the archive. In cPanel open Files › File Manager, enter public_html (or the subfolder), click Upload, then right-click the ZIP and choose Extract. Delete the ZIP afterwards. To replace an older version, remove the old assets/ (Vite) or static/ (CRA) folder first so stale bundles don’t pile up.
5. Add the SPA fallback in .htaccess
Create .htaccess next to index.html:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
For a subfolder, change RewriteBase / to RewriteBase /app/ and the last line to RewriteRule . /app/index.html [L]. Real files (images, bundles) are still served directly; only unknown paths fall back to the app. More on the file in .htaccess explained.
6. Optional: cache headers
Vite and CRA put a content hash in bundle names, so those files can be cached for a long time, while index.html should always be checked again:
<IfModule mod_headers.c>
<FilesMatch "\.(js|css)$">
Header set Cache-Control "public, max-age=31536000, immutable"
</FilesMatch>
<FilesMatch "^index\.html$">
Header set Cache-Control "no-cache"
</FilesMatch>
</IfModule>
Then force HTTPS if your site doesn’t redirect yet.
7. Publish updates
Repeat the build and upload for every release, or let Git do the copying. If you commit the dist/ folder, a .cpanel.yml at the repository root can sync it into public_html from cPanel’s Git Version Control:
---
deployment:
tasks:
- export DEPLOYPATH=/home/USER/public_html/
- /bin/rsync -a --delete --exclude='.well-known' dist/ $DEPLOYPATH
--delete removes old bundles, but also anything else in public_html that isn’t in dist/, so use it only when the folder holds this app alone. Keep .htaccess in the repository’s public/ folder and Vite copies it into dist/ on every build.
Troubleshooting
- Blank white page, and the browser console shows 404 for
/assets/index-xxxx.js: thebasepath doesn’t match where you uploaded, or you uploaded thedistfolder itself so the files ended up inpublic_html/dist/. Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html": same cause. The bundle path is wrong, so the fallback answers withindex.htmlinstead of the JavaScript file.- 404 when refreshing a route:
.htaccessis missing or misplaced. File Manager may hide dotfiles; enable Settings › Show Hidden Files (dotfiles). See 404 Not Found. - API calls fail: the API must allow your domain in its CORS settings, and an
http://API called from anhttps://page is blocked as mixed content. Check that the variable was set before you built. - Visitors still see the old version: their browser cached
index.html. Add theno-cacheheader above.
On ArabyHost
A React app runs on every ArabyHost plan, shared hosting included, because it is only static files: LiteSpeed serves them, and AutoSSL issues a free certificate automatically once your domain points to us. Daily JetBackup backups cover the files. If the app needs a backend, run the API in Node.js or Python on the AI/Developer plans, which also give you SSH and Git for deploying the build from GitHub Actions; see automatic deploys from GitHub. If you need server-side rendering, deploy Next.js instead.
FAQ
Do I need Node.js hosting for a React app?
Not for a client-side React app: after the build it is HTML, CSS and JavaScript that any web server can serve. You need Node.js only for server-side rendering (for example Next.js) or for a backend API.
Why does refreshing a page give 404?
The server looks for a real file at that path, such as /dashboard, and there is none, because React Router builds that page in the browser. The .htaccess fallback serves index.html for unknown paths so the router can take over.
Can I deploy a React app from GitHub automatically?
Yes. Build in GitHub Actions and upload the output over SSH on AI/Developer plans, or commit the build folder and copy it with .cpanel.yml from cPanel's Git Version Control.