Photo by American Public Power Association on Unsplash
How to Deploy a React App on cPanel (e.g., Namecheap) and Vercel
Deploying your React app ensures that your application is accessible to users online. This guide will walk you through deploying your React app on both cPanel (commonly provided by hosting providers like Namecheap) and Vercel. By the end, your app will be live and ready for the world to use.
Option 1: Deploying React on cPanel
Prerequisites
A React app ready for production.
Access to your hosting account's cPanel (e.g., Namecheap, HostGator, etc.).
A domain or subdomain set up for your deployment.
Step 1: Create a Production Build
React needs to be optimized for production. To do this:
Open a terminal in your React project directory.
Run the following command:
npm run build
This generates a
build
folder containing the production-ready version of your app.
Step 2: Compress the Build Folder
To upload the app to cPanel, the build
folder must be compressed:
On Mac: Right-click the
build
folder and select Compress "build".On Windows: Right-click the folder and choose Send to > Compressed (zipped) folder.
This creates a build.zip
file.
Step 3: Upload the Build Folder to cPanel
Log in to your cPanel account.
Navigate to File Manager.
Go to the directory for your domain or subdomain:
Main Domain:
public_html
.Subdomain: Look for
public_html/<subdomain_name>
or a similar folder.
Click the Upload button and select your
build.zip
file.After the upload is complete, select the
build.zip
file and click Extract to unpack the files.
Step 4: Move Files to Root Directory
If the extracted files are inside a folder named build
, move the contents of the build
folder to the root of your domain or subdomain directory.
Step 5: Configure .htaccess
for Routing
React apps using React Router require special handling for client-side routing. To handle this:
Create or edit the
.htaccess
file in the root directory of your domain.Add the following code:
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^ index.html [L] </IfModule>
Save the file.
Step 6: Test Your App
Visit your domain (e.g., https://yourdomain.com
) or subdomain (e.g., https://app.yourdomain.com
) in a browser. Your React app should now be live!
Option 2: Deploying React on Vercel
Vercel is a cloud platform optimized for frontend frameworks like React. It’s quick, free (for most use cases), and requires minimal setup.
Prerequisites
A React project hosted on GitHub, GitLab, or Bitbucket (optional, but recommended).
A Vercel account (sign up at vercel.com).
Step 1: Create a Vercel Account
Go to Vercel and sign up for an account.
Log in to the Vercel dashboard.
Step 2: Import Your Project
Click the New Project button.
Connect your GitHub/GitLab/Bitbucket account to Vercel.
Select the repository for your React app.
Step 3: Configure Build Settings
When prompted, Vercel will automatically detect your React app.
Ensure the following settings are correct:
Framework Preset: React.
Build Command:
npm run build
(default).Output Directory:
build
(default).
Click Deploy to start the deployment process.
Step 4: Wait for Deployment
Vercel will build and deploy your app. Once complete, you’ll receive a live URL (e.g., https://yourapp.vercel.app
).
Step 5: Add a Custom Domain (Optional)
In the Vercel dashboard, go to your project settings.
Add a custom domain under the Domains section.
Update your domain’s DNS settings (add an
A
orCNAME
record) to point to Vercel’s servers.
Step 6: Test Your App
Visit your Vercel-provided URL or your custom domain to see your React app live.
Key Differences Between cPanel and Vercel
Feature | cPanel Hosting | Vercel Hosting |
Ease of Use | Manual file upload and configuration | Automated deployment via Git |
Cost | Paid hosting plans | Free for most use cases |
Performance | Depends on your hosting provider | Optimized for frontend frameworks |
Custom Domain Setup | Manual (via cPanel DNS settings) | Easy (via Vercel dashboard) |
Conclusion
Both cPanel and Vercel are excellent platforms for hosting React apps, depending on your needs:
Use cPanel if you’re already paying for shared hosting or need to host backend services alongside your app.
Use Vercel for quick, free, and scalable deployments optimized for React.
No matter which method you choose, your React app will be live and accessible to your users in just a few steps!