Logo

dev-resources.site

for different kinds of informations.

Simple Guide to Deploying Your Vite React App on Cpanel for Beginners

Published at
11/2/2023
Categories
react
vite
deploy
cpanel
Author
iamtakdir
Categories
4 categories in total
react
open
vite
open
deploy
open
cpanel
open
Author
9 person written this
iamtakdir
open
Simple Guide to Deploying Your Vite React App on Cpanel for Beginners

Step 1: Specify Your Site's URL in Vite Config

First off, we need to tell your Vite React app where it's going to be published on the internet. In your Vite project, there’s a file named vite.config.js. Open this file and add a base property under export default defineConfig. This is where your site's URL will go. It should look something like this:

export default defineConfig({
  base: 'http://myvitereactapp.com/',
  // ... other config settings
})
Enter fullscreen mode Exit fullscreen mode

Step 2: Prepare Your App for Deployment

Now, let's get your app ready to go live. This step converts your project into a form that's more efficient for web browsers and usually it compresses your all CSS and JavaScript codes to make it more faster. Open your project's terminal, and run yarn install to make sure all dependencies are up to date. After that, execute yarn build. This will create a dist folder in your project, holding the production-ready version of your app.

Step 3: Zip the dist folder

Zip/ Compress your dist folder, use any compressor tool to zip your dist folder. Usually people uses (WinZip, 7zip, etc.) .

Step 4: Upload Your App to File Manager.

Login in to the control panel or cPanel, and look for the File Manageror you can use the search bar at the top to find the file manager. Inside the File Manager, you should see a folder named public_html. This is where your react build source code will go.

File Manager

public html

Step 5: Uploading dist.zip to public_html

Click on upload button at the top of File Manager then Select the dist.zip file from your source code folder, then upload them directly into the public_html folder on your cpanel.

Image upload

Image select

Step 6: Extract Your Zip file

After uploading the dist.zip file you have to extract the zip file, click on to the zip button and click on to the extract button.

extract

Image edit

Step 7: Set Up Redirects for SPA

Vite React apps are usually single-page applications (SPAs), and they require special handling of page requests. In the public_html folder on your host, create a file called .htaccess. Paste in the following configuration to manage redirects:

<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>
Enter fullscreen mode Exit fullscreen mode

htaccess

Now save the .htaccess file.

CASE CLOSED !

You've successfully deployed your Vite React Application! Visit your web address, and you should see your app shining back at you from the web. Congrats on bringing your project to the world!

cpanel Article's
30 articles in total
Favicon
Run NextJS App in shared-hosting cPanel domain!
Favicon
How to deploy laravel project on cpanel or shared hosting
Favicon
Host Nextjs 14 Application on cPanel
Favicon
VPS vs. Shared Hosting: Understanding the Key Differences
Favicon
How I Deployed Next.js to cPanel on Shared Hosting
Favicon
Error yang sering di jumpai ketika Setup NodeJS App pada cPanel.
Favicon
Deploy NextJs to cPanel
Favicon
Deploy Laravel to cPanel v.2
Favicon
Need Help! php server
Favicon
cPanel Hosting vs NGINX Hosting: A Comparison for Linux Hosting
Favicon
How to Import MBOX to cPanel?
Favicon
next js app on cPanel
Favicon
Deploy Laravel to cPanel v.1
Favicon
Deploy Frontend Web Application with React to cPanel.
Favicon
Deploy Backend API with Express Js to cPanel
Favicon
Web Hosting on cPanel WHM - What and How of cPanel and cPanel Terminal Commands- A Beginner Guide
Favicon
How to create a Node.js web server with cPanel
Favicon
How to install Node on cPanel shared hosting (without root access)
Favicon
The best FREE hosting control panel & alternative to CPanel: CyberPanel!
Favicon
Unlocking Economical Potential: Low-Cost cPanel Hosting Options
Favicon
cPanel UAPI Operations for Creating Subdomains, MySQL Databases, and File Operations
Favicon
My webhosting business journey
Favicon
How to Migrate Email from G Suite to cPanel?
Favicon
Steps To Remove/Delete Domain Name from cPanel?
Favicon
Resolving cPanel Git Error Code 128: ‘Permission Denied’ Issue
Favicon
How to Deploy your Django Web App and connect a MySQL Database in cPanel
Favicon
Plesk vs. cPanel: A Comprehensive Comparison
Favicon
How to deploy django app on cpanel
Favicon
Simple Guide to Deploying Your Vite React App on Cpanel for Beginners
Favicon
How To Set Up Auto Deploy For Laravel Applications On Cpanel

Featured ones: