
Setting up a Next.js website on Hostinger involves creating a new account and selecting a suitable hosting plan.
Hostinger offers a range of plans, including the Single Web Hosting plan, which starts at $0.99 per month.
To get started, navigate to the Hostinger website and click on the "Sign Up" button.
You'll then be prompted to choose a hosting plan and enter your account details.
Additional reading: Webflow Freelancer Plan
Prerequisites
Before you start deploying your Next.js app on Hostinger, make sure you have a VPS hosting plan from Hostinger. This is the foundation of our setup.
To ensure a smooth deployment, it's also recommended to have a domain name connected to your VPS. This will make it easier to access and manage your app later on.
You'll need a basic understanding of Linux commands and SSH. Don't worry if you're new to this – it's not as scary as it sounds, and there are plenty of resources available to help you learn.
Your Next.js app needs to be ready for deployment, so make sure it's in a deployable state before moving on.
To connect to your VPS and manage your app, you'll need a local terminal or SSH client like PuTTY.
A fresh viewpoint: Next Js Drizzle Supabase
Hosting Setup
You can host a Next.js application on Hostinger, as it provides the necessary infrastructure to support Node.js applications, which is the runtime environment Next.js runs on.
Hostinger's infrastructure is capable of handling Node.js applications, making it a suitable choice for Next.js hosting.
To get started, simply set up your Next.js application and Hostinger will take care of the rest.
For another approach, see: Developing Web Apps
Sign up for hosting
Sign up for hosting is a crucial step in setting up your hosting. You can sign up for a hosting account with Hostinger, a popular hosting platform that offers affordable hosting plans with reliable performance.
Hostinger's cheapest hosting services are a great option for beginners, and its basic plans can handle huge traffic very easily. I choose Hostinger because it is cheap, but provides faster performance.
Hostinger offers single, premium, and business shared hosting plans. I would suggest going with the premium plan as it is price-worthy and includes a free domain, email, and the ability to host multiple websites.
To sign up for a Hostinger account, complete the registration process by providing the necessary details and selecting a payment method. This will create your Hostinger account.
Here are the main features of Hostinger's shared hosting plans:
- Single plan: No information available
- Premium plan: Includes a free domain, email, and the ability to host multiple websites
- Business plan: No information available
With your Hostinger account created, you can start setting up your hosting.
Hosting Node.js
You can host a Node.js application on Hostinger, but you'll need to use their VPS Plans. This is because shared hosting may not provide the necessary infrastructure to support Node.js applications.
Hostinger provides the necessary infrastructure to support Node.js applications, which is a requirement for hosting a Next.js application.
To host a Node.js application on Hostinger, you can use their VPS Plans. This will give you the flexibility to run your application as needed.
Here are the steps to deploy a Next.js application on Hostinger's VPS Plans:
- Update your VPS IP address and domain name in the deployment script.
- Configure Apache to proxy requests to your Next.js application.
- Secure your website with SSL certificates using Certbot.
- Update your .env file to use HTTPS.
Note that you can also deploy a Next.js application on shared hosting by using the next export command to generate static files and then uploading them to your hosting provider. However, for dynamic features or server-side rendering, consider using VPS or cloud hosting.
Recommended read: Next Js on Aws
Configuring Next.js
To configure Next.js, you need to modify the "next.config.mjs" file. This file is crucial in setting up the output directory for your static files.
Add the output, basePath, and assetPrefix lines to the "next.config.mjs" file to achieve this. For example, executing npx next build will create the "out" directory with all links and CSS files.
When using next/image for image management, update the image paths as necessary. This ensures that your images are properly linked to the output directory.
Note that you should not use dynamic routes in Next.js if you're exporting like this, especially if you plan to host your website on Hostinger.
Recommended read: Nextjs Images
Building and Deploying
To deploy your NextJS website, you'll need to start by making some changes to your VPS IP address and domain name. This will involve adding dummy changes, committing and pushing them to your Hostinger repository.
You can open your NextJS website by visiting http://5.182.18.65:3000 in your browser.
To configure Apache, you'll need to install it first, then enable the necessary modules and create a new configuration file.
Here's a step-by-step guide to configuring Apache:
After configuring Apache, you can open your NextJS website by visiting http://nextjs-ecommerce.com in your browser.
To secure your website with HTTPS, you'll need to install Certbot and obtain an SSL certificate.
Here's how to do it:
1. Install Certbot: `sudo apt install certbot python3-certbot-apache`
2. Obtain SSL certificate: `sudo certbot -d nextjs-ecommerce.com -d www.nextjs-ecommerce.com -m [email protected] --apache --agree-tos --no-eff-email --redirect`
Once you have obtained an SSL certificate, you can update your .env file to use HTTPS.
1. Update .env file: `nano .env` and change `NEXT_PUBLIC_SERVER_URL` to `https://nextjs-ecommerce.com`
After updating your .env file, you can open your NextJS website by visiting https://nextjs-ecommerce.com in your browser.
For more insights, see: Nextjs Install
Testing and Deployment
To test your deployed Nextjs website or project, simply open your browser and go to your website or project's URL. If everything is configured correctly, you should see your Nextjs website or project running on the hosting platform.
A fresh viewpoint: Html Project Ideas
The IP address of your VPS is used to access your website temporarily. For example, if your VPS IP address is 5.182.18.65, you can open http://5.182.18.65:3000 to test your website.
To deploy your Nextjs application, you'll need to configure Apache on your VPS. This involves installing Apache, enabling the necessary modules, and creating a new configuration file.
Here are the steps to configure Apache:
- Install Apache: `sudo apt install apache2`
- Enable the necessary modules: `sudo a2enmod proxy proxy_http rewrite headers expires`
- Create a new configuration file: `sudo nano /etc/apache2/sites-available/nextjs-ecommerce.com.conf`
Once you've completed these steps, you can restart Apache to apply the changes: `sudo service apache2 restart`
After configuring Apache, you can test your website by opening http://nextjs-ecommerce.com in your browser.
To secure your website with HTTPS, you'll need to obtain an SSL certificate. You can use Certbot to obtain an SSL certificate from Let's Encrypt. Here are the steps to obtain an SSL certificate:
- Install Certbot: `sudo apt install certbot python3-certbot-apache`
- Obtain an SSL certificate: `sudo certbot -d nextjs-ecommerce.com -d www.nextjs-ecommerce.com -m [email protected] --apache --agree-tos --no-eff-email --redirect`
After obtaining an SSL certificate, you can update your .env file to use HTTPS: `cd /root/apps/nextjs-ecommerce/dest/ && nano .env` and update the `NEXT_PUBLIC_SERVER_URL` variable to `https://nextjs-ecommerce.com`.
Domain and Settings
To configure your domain settings, log in to the control panel and go to the Domains section, where you can click on Add Domain.
You'll then see two options: Register a new domain or Use an existing one. If you already have a domain, you can use that to host your website and add your domain to Hostinger.
To update your existing domain's nameservers, follow this guide: Setup domain in hostinger. Alternatively, contact Hostinger support for help if you're facing problems with domain configuration.
This process is straightforward and can be completed in a few steps.
Intriguing read: I Want to Add News to My Website Html
Frequently Asked Questions
Is NextJS overkill for a static website?
Yes, Next.js can be overkill for a static website, as it includes a full React ecosystem that may not be necessary for sites with minimal interactivity. Consider using a lightweight alternative for simple static sites.
Featured Images: pexels.com


