DEV Community

Cover image for Deploy react app on shared hosting
Qasim Nadeem
Qasim Nadeem

Posted on

Deploy react app on shared hosting

For deploying a react app on a shared hosting you need to create a production build. Production build is a pack of all your react code and its dependencies.

in most shared hosting we put our site/app inside a public_html directory so if we hit www.yourdomain.com it serves the code from public_html directory.

so if your react app is ready to go, edit your package.json file add a new key value:

"homepage":"http://yourdomain.com"

then create a build using following command:

npm run build

after running the command you will see a new directory named build in your app root. It will contain js and css for the app and a index.html file. You need to upload all the content inside build directory to public_html directory, and that's all, go to your domain and your app will be working just fine.

Top comments (3)

Collapse
 
delc82 profile image
dleon

Thanks for this!

Collapse
 
schajx profile image
Jesse Schaaf

Hi Qasim, I am currently trying to publish a portal that I have running on my local env to a shared server. I am using Laravel and React. When you say run "npm run build" I am assuming you are talking about from your local server correct and then just moving the code up to the shared server(in my case Bluehost).

We have two folders "Frontend" and "Backend" and I am trying to figure out how to upload this to a test site(on a shared server with no command line access).

In this case, my frontend folder has another folder in it called public that has the index page. So trying to understand where the code(which code) I would need to place in the public_html root folder. I believe the backend can be placed any where as I can just update my .env file to point to it/.

Thanks!!

Collapse
 
thisdotmedia_staff profile image
This Dot Media

🙌