Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy a react app on cPanel?

I've created a react app with the following folder structure

-public
 --dist
  ---bundle.js
  ---styles.css
 --index.html
 --images
-server
 --server.js
-src
 --components
 --app.js
-.babelrc
-package.json
-webpack.config.js

I want to upload it to cPanel. Is that possible? Would I also need to upload the node_modules/ folder?

here is a link to my repo: https://github.com/theoiorga/react-expensify-app

like image 447
Theo I. Avatar asked Apr 20 '18 10:04

Theo I.


People also ask

How do I deploy a React app to hosting?

For your React app, you'll have to drag and drop the build folder onto the Netlify Dashboard. Run npm run build beforehand to deploy the latest build. You can also connect GitHub, GitLab, or Bitbucket, depending on where your project is stored. This allows automatic deployment whenever you push your changes.


3 Answers

step 1:"homepage": ".", -->add this on package.json file

step 2 : npm run build --> this will create a build folder.

step 3 : make a .htaccess it will look like this

<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>

step 4 : now take all the files in build folder plus your htaccess and drop them in the desired domain or subdomain

like image 181
Sumit Saha Avatar answered Oct 27 '22 06:10

Sumit Saha


Follow the steps to deploy your React website on CPanel

Step(1) : Under your local project directory run this command "npm 
           run build" or "yarn build" then "build" directory will be created. This directory contains the bundle of all static files with dependencies which you can directly copy onto your production server. 

Step (2) : Go to inside the "build" folder and select all files and compress or make a Zip then upload in cpanel it will work. 

Note: for react app no need to upload whole projects we need to deploy only "build" directory.

like image 37
kallayya Hiremath Avatar answered Oct 27 '22 06:10

kallayya Hiremath


To Deploy React App on Cpanel/Server. Please follow the Steps

Step 1) Go to Package.json file and add this Property "homepage":"http://yourdomain.com" and paste your domain within it. Like

enter image description here

Step 2) Now build the App using npm run build

In your project directory it will create a build folder and it will contain all your static files for project. Zip all files and upload on your cpanel directory where your website run.

Step 3) Create an .htaccess file and Place it on root directory. And paste the below code in .htaccess file.

<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>

Now Run your Project. It will Work.

Thanks

like image 5
Muhammad Wasim Akram Avatar answered Oct 27 '22 06:10

Muhammad Wasim Akram