Skip to content
  • Homepage
  • HTML
  • CSS
  • Symfony
  • PHP
  • How to
  • Contact
  • Donate

Teach Developer

Articles, Guides & Tips

How to Deploy or Host your ReactJS App in cPanel

Home  »  How to • Node js • React • Tips   »   How to Deploy or Host your ReactJS App in cPanel
Posted on August 28, 2022September 17, 2022
1,227

This tutorial assumes you already have a cPanel hosting service purchased and a domain name registered. If yes, Let’s go straight to the steps (If No, You can comment, I can give you steps on how to get a domain and hosting service)

Step 1. Using the Terminal/CMD in your project directory, create a react app if you haven’t by running `npx create-react-app my-app`, Once the installation is successful, CD into the my-app directory is created.

Step 2. Open the package.json file add a “homepage” attribute with your domain/subdomain has the value;

Add homepage attribute to the package.json file of your react project

Step 3. In your project directory, locate the public folder and add a .htaccess file to your project with the following configuration options;

add .htaccess to the public folder

Step 4. Open up the .htaccess file and add the following configurations;

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

This assumes that the index.html and the .htaccess file are in the same directory (public folder), if your react app is in another folder, then change the RewriteRule to ./anotherfolder/index.html

Step 5. Run npm build or yarn build command (Depending on which one you are using), this will create a new directory in your project called build

This new directory contains a compressed version of your react app in static files, this is what you will deploy to your cPanel File Manager.

Step 6. Upload all the contents of the build folder into your cPanel account via FTP (You can use FileZilla)or File Manager Upload;

upload build contents to Cpanel with FTP

Step 7. Congratulations, Your ReactJS app is live, visit the domain/subdomain link and share it with your friends.

Step 8. Drop a comment below

How to, Node js, React, Tips

Post navigation

Previous Post: How to check PHP version using the command line
Next Post: Difference Between Git and GitHub

Related Posts

  • How to change background Opacity when the bootstrap modal is open with CSS?
  • How to Delete Unused Database Tables in WordPress
  • How to make a div always float on the screen in the top right corner with CSS?
  • How to Get Environment Variables in Laravel ReactJS
  • How to Send Email from Localhost in PHP
  • How to make the div move up and down when scrolling the page with CSS?

Categories

  • Codeigniter (3)
  • CSS (11)
  • eCommerce (1)
  • Framework (1)
  • Git (3)
  • How to (43)
  • HTML (5)
  • JavaScript (15)
  • Jquery (7)
  • Laravel (1)
  • Linux (4)
  • Magento-2 (1)
  • Node js (4)
  • Others (2)
  • PHP (11)
  • React (13)
  • Server (1)
  • SSH (3)
  • Symfony (6)
  • Tips (16)
  • Top Tutorials (10)
  • Ubuntu (3)
  • Vue (1)
  • Wordpress (7)

Latest Posts

  • What is SSH in Linux?
  • How to Delete Files in Ubuntu Command Line
  • How to Deploy a React application on a cPanel
  • How to use events listeners and Event Subscriber in Symfony
  • How to Convert PHP CSV to JSON

WEEKLY TAGS

AJAX (1) Codeigniter (1) Javascript (11) JQuery (1) PHP (16) Programming (1) React (3) Symfony (1)

Random Post

How to display the last updated date of a post in WordPress
Common Mistakes with Conditionals
How to make a div always float on the screen in the top right corner with CSS?
How to Disable WordPress Auto Update? Turn Off WordPress Auto Updates
How to Delete and Remove Files on Ubuntu Linux Terminal

Quick Navigation

  • About
  • Contact
  • Privacy Policy

© Teach Developer 2021. All rights reserved