Let’s look into the setup to deploy React app on cPanel. Bobcares, as a part of our cPanel & WHM Support Services offers solutions to every query that comes our way.
Setup to Deploy Reactjs App on cPanel
We must run the following steps in order to set up React.js app on cPanel:
1. Initially, open the terminal or command prompt.
2. Go to the directory where we want to create the React app.
3. Run the next code:
npx create-react-app your-app-name.
4. Go to the React app’s root directory.
5. Open package.json in a text editor.
6. Add the “homepage” attribute with the domain name:
"homepage": "http://your_domain_name.com"
7. Now, go to the root directory of the React app.
8. Install dependencies:
i. Using Yarn: yarn install
ii. Using npm: npm install
9. Build the app:
i. Using Yarn: yarn build
ii. Using npm: npm run build
10. Go to the public folder in the React app.
11. Create a new file named .htaccess.
12. Insert the following content:
RewriteEngine On RewriteBase / RewriteRule ^index\.html$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-l RewriteRule . /index.html [L]
13. Now, to deploy the app on cPanel, log into the cPanel account.
14. Navigate to “File Manager” in the cPanel dashboard.
15. Go to the public_html directory.
16. Upload the build directory from the React app.
17. Save the uploaded files.
[Looking for a solution to another query? We are just a click away.]
Conclusion
The article offers the steps from our Tech team to set up React app on cPanel.
0 Comments