mern stack hosting in hostinger with apache2
- Date

-
admin
MERN Stack Hosting on Hostinger with Apache2
In this blog post, we will walk you through how to deploy a MERN (MongoDB, Express, React, Node.js) stack application on Hostinger using Apache2 as a reverse proxy server. This tutorial is designed for beginners and intermediate users, making it easy to set up a production-ready MERN app on a shared hosting environment.
What is MERN Stack?
MERN Stack is a powerful collection of technologies for building full-stack web applications. It consists of:
- MongoDB - A NoSQL database for storing application data.
- Express.js - A web application framework for Node.js, simplifying routing and handling HTTP requests.
- React - A JavaScript library for building user interfaces.
- Node.js - A JavaScript runtime built on Chrome's V8 JavaScript engine, allowing you to run JavaScript server-side.
Why Use Apache2 for Hosting MERN Stack?
Apache2 is a popular web server that can be used to serve static files and act as a reverse proxy for backend servers like Node.js. With its stability and large community, it makes an excellent choice for hosting applications in production. By using Apache2 in combination with the MERN stack, you can ensure that your app can handle a large number of requests efficiently while maintaining high security.
Steps to Host MERN Stack on Hostinger with Apache2
Here are the steps to successfully deploy your MERN stack application on Hostinger using Apache2 as the reverse proxy:
- Step 1: Set Up Your Hostinger VPS
Create a VPS on Hostinger and choose a Linux distribution (Ubuntu or CentOS) for the server environment. - Step 2: Install Node.js and NPM
SSH into your server and install Node.js and NPM:sudo apt update sudo apt install nodejs npm
- Step 3: Upload Your MERN App to the Server
Use SCP, SFTP, or Git to upload your MERN app files to your Hostinger server. Navigate to the app directory after uploading the files. - Step 4: Install Dependencies
Inside your app's directory, run the following command to install dependencies:npm install
- Step 5: Run Your Node.js App in the Background
Use PM2, a process manager for Node.js, to run your app in the background. This ensures your app stays running even if you close the terminal:pm2 start app.js --name "mern-app" pm2 save
- Step 6: Install Apache2
Install Apache2 on your server using the following command:sudo apt install apache2
- Step 7: Configure Apache2 to Act as a Reverse Proxy
After installing Apache2, you'll need to configure it to act as a reverse proxy for your Node.js application. Open the Apache config file:
In the `VirtualHost` section, add the following configuration:sudo nano /etc/apache2/sites-available/000-default.conf
This will forward incoming requests on port 80 to your Node.js app running on port 3000.ServerAdmin webmaster@localhost ServerName your_domain_or_ip DocumentRoot /var/www/html ProxyPass / http://localhost:3000/ ProxyPassReverse / http://localhost:3000/ - Step 8: Enable Apache Modules for Proxying
Enable the required modules for Apache2 to proxy requests to your Node.js app:sudo a2enmod proxy sudo a2enmod proxy_http
- Step 9: Restart Apache2
After configuring Apache2, restart the server to apply the changes:sudo systemctl restart apache2
- Step 10: Verify Your Setup
Open your web browser and visit your server's IP address or domain. If everything is set up correctly, your MERN app should be live and accessible via Apache2.
Conclusion
By following these steps, you’ve successfully deployed your MERN stack application on Hostinger using Apache2 as a reverse proxy server. Apache2 helps manage traffic efficiently and securely, while Node.js and Express handle the backend functionality of your MERN stack app. This setup ensures your app is production-ready and can scale to handle more traffic.
Now you can start developing more features for your MERN app and monitor it for performance and errors. Enjoy building with the MERN stack and Apache2!