host react app on shared cpanel hosting

Host react app on shared cpanel hosting

Posted on Posted in Blogs

[vc_row][vc_column][vc_column_text]If you have been a web designer/developer, you must have at least heard about React. Most of you may have even transitioned to being a full-time react developer. React is an amazing javascript library, which helps in making front end applications, which are client heavy, so less resources are used in the server. They are extremely fast and are used to make single page applications(SPA), meaning they don’t fetch new html pages, instead change the content of a single index.html page. With this new technology, hosting of such application has also moved away from traditional apache servers. React developers prefer static servers or such servers that has node installed, like heroku. But that doesn’t mean we cannot host react app on shared cpanel hosting servers.[/vc_column_text][vc_column_text]

How to host react app on shared cpanel hosting.

Shared servers with cpanel are normally apache servers. And since they are shared, you won’t be able to get root access and install node. But that’s not an issue. React applications are essentially HTML, CSS and plain javascript after they get built for production. These files can run on any kind of server. In fact they can be run right from your file system, like any simple HTML page.

But there are two important things to consider while hosting your app’s build folder in your shared hosting.

  1. When using an Apache HTTP Server, you have to create a .htaccess file in the public folder that looks like this:
    Options -MultiViews
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.html [QSA,L]

    This file will automatically get copied to the build folder when you run the command npm run react app on shared cpanel hosting
  2.  If you’re not placing the files in the root of your server (i.e. public_html), then you’ll have to configure the package.json file. Create React App produces a build assuming your app is hosted at the server’s root. To override this, specify the following:
    "homepage": "" in your package.json,

[/vc_column_text][/vc_column][/vc_row][vc_row][vc_column][vc_column_text]This should be everything you need to do to host your react app in a cheap shared hosting with cpanel.







2 thoughts on “Host react app on shared cpanel hosting

Comments are closed.