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

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 Disable WordPress Auto Update? Turn Off WordPress Auto Updates
  • How to Reverse A String with JavaScript
  • Git basics: The simple commands to begin with
  • How to check if a customer is logged in to Magento 2 or not?
  • ES6 classes
  • Difference between var, let, and const in JavaScript

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 Get Environment Variables in Laravel ReactJS
How to Use useLocation Hook in React Router DOM V6
How to use :hover to modify the CSS of another class?
How to change password in the CodeIgniter framework
How do sum values from an array of key-value pairs in JavaScript?

Quick Navigation

  • About
  • Contact
  • Privacy Policy

© Teach Developer 2021. All rights reserved