
Hostinger is a popular web hosting platform that supports React apps, but it can be overwhelming for beginners to set it up.
To host a React app on Hostinger, you'll need to create a new account and choose a suitable hosting plan.
Hostinger offers a range of hosting plans, including single, premium, and business plans, each with varying levels of storage and bandwidth.
The single plan, priced at $1.99 per month, is suitable for small React apps with minimal storage and bandwidth requirements.
Suggestion: Hostinger Web Hosting Plans
Prerequisites
To host your React app on Hostinger, you'll need a few key things.
First and foremost, you'll need a domain. This is the web address people will use to access your app.
You'll also need a hosting plan. This is where your app's files will live on the internet.
Purchasing a domain and hosting plan can be quite expensive, but Hostinger makes it easy by offering a premium web hosting plan that includes a free domain for the first year.
Additional reading: Domain & Web Hosting
Setting Up Domain
If you already have a Hostinger account and a domain, you can skip this step and go to the next one.
You can register a free domain with Hostinger's premium shared hosting, and you won't need to do any domain configuration.
To set up your domain, log in to the Hostinger control panel, also known as the hpanel.
Under the Domains section, click on "Add Domain", where you have two options: register a new domain or use an existing one.
Upload Build Folder
Uploading the build folder to Hostinger is a crucial step in hosting your React app. You'll need to create a production-ready build folder using the command npm run build.
To do this, open a terminal at your project folder location and enter the command npm run build. This will create a build folder inside your React project.
Once you have your build folder, you'll need to upload it to Hostinger's file manager. To do this, go to your Hostinger hPanel and click on the file manager. It will show you an option to access your files, click on it and it will open the file manager.
Inside the file manager, you'll see a public_html folder where you'll put all your code files. To upload your build folder, drag and drop everything from the React build folder inside the public_html folder.
Alternatively, you can use FileZilla to export all the files and folders from the build folder to public_html. This is what one user did and it worked for them.
If you're still having issues, make sure to check your domain configuration and contact Hostinger's customer support if needed.
Configuring Git and GitHub
To set up Git configuration on Hostinger, go to the GIT configuration settings for your website, located in the Advanced section of Hosting.
First, create a repository in the Create a Repository section and add your Git repository, making sure to use the correct format for private and public repositories.
For the branch, put build, as this will ensure that the build of your code is sent to Hostinger, not the code itself.
A different take: Azure App Config
If the build branch does not exist, it's okay, but be aware that if you already have a branch with this name, it will be used for future builds.
In the Manage Repositories section, click Auto Deployment and note the Webhook URL, which will be used in the next step.
If your repository is private, generate an SSH Key by clicking the generate SSH Key button in the Private Git Repository section, and keep a note of the key for the next step.
A different take: Next Js vs Create React App
Deploying React App
To deploy a React app on Hostinger, you'll need a domain and a hosting plan, which can be purchased together as a premium web hosting plan with a free domain for the first year.
You'll also need to create a build version of your React app by running the command `npm run build` in your project folder. This will create a production-ready build folder inside your React project.
To upload your React app to Hostinger, you can use a file manager like FileZilla to export all the files and folders from the build folder to the `public_html` folder on your Hostinger account.
However, if your React app was built assuming it's hosted at `/`, you may need to adjust the `index.html` file to point to a specific domain name. You can try both variants mentioned in the Hostinger documentation.
If zipping a build folder doesn't work, you can try uploading all the content of the build folder directly into the `public_html` folder.
Some common issues you may encounter when deploying a React app on Hostinger include a 403 error, which can be resolved by adding a `.htaccess` file with the correct code to your `public_html` folder.
Here are the general steps to deploy a React app on Hostinger:
- Create a build version of your React app using `npm run build`
- Export all the files and folders from the build folder to the `public_html` folder using a file manager like FileZilla
- Adjust the `index.html` file to point to a specific domain name if necessary
- Add a `.htaccess` file with the correct code to your `public_html` folder to resolve any 403 errors
Featured Images: pexels.com


