How to Deploy Vite React Project on NameCheap cPanel?

223 Views Asked by At

I am trying to deploy my Vite react app on NameCheap cPanel but, I am unable to deploy my react app.

I run this command npx vite build to create a build of my react app. I got the dist folder in which index.html and assets folders are available. I simply go to cPanel select Node.js and create a node app. In the file manager, I upload the dist folder and zip in the exact folder that I created during the Node.js setup. I unzip the dist file and run the Node.js server. But I got a 503 error. I also tried to create a server.js file and in this file, I used express.js to call the dist and public folder, and then I uploaded server.js, package.json, and dist/public.zip files in cPanel. I also run the Run NPM Install to install all the dependencies but none of the methods works. Below is the image: image

If anyone knows how to deploy the Vite React project on NameCheap cPanel then please answer my question.

1

There are 1 best solutions below

0
Lutzfy21 On

you need to add .htaccess inside your public_html folder, like below

<IfModule mod_headers.c>
 Options +Indexes
 RewriteEngine On
 RewriteCond %{REQUEST_URI} !^/dist/
 RewriteRule (.*) /dist/$1 [L]
</IfModule>