1️⃣Install NodeJS
We will guide you here on how to install Nodejs with NPM, Apache server, and PM2 process manager.
To install the latest NodeJS version 18.x, type the commands below.
cd ~
curl -sL https://deb.nodesource.com/setup_18.x -o nodesource_setup.sh
Then run the below command
sudo bash nodesource_setup.sh
sudo apt install nodejs
This will install NodeJS 18.x and NPM to your system. to verify the version, you can check by below command.
node -v
v18.17.0
Install Apache server.
To install Apache2 package, follow the below command line in your terminal.
sudo apt install apache2
Enable required Apache modules:
Next.js projects often use Node.js and require proxying to the Node.js application running on a different port. To enable the required Apache modules, run:
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_balancer
sudo a2enmod lbmethod_byrequests
Configure a new virtual host: Create a new virtual host configuration file for your domain.
sudo nano /etc/apache2/sites-available/hostinghub.com.conf
Replace hostinghub.com with your own domain.
Add the following content to the file. Replace hostinghub.com and www.hostinghub.com with your domain again.
<VirtualHost *:80>
ServerName hostinghub.com
ServerAlias www.hostinghub.com
ProxyPreserveHost On
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
</VirtualHost>
Enable the virtual host: Replace hostinghub.com with your domain.
sudo a2ensite hostinghub.com
Restart Apache to apply the changes:
sudo service apache2 restart
Thats it.
Install PM2 process manager
PM2 is a process manager, to install it, follow the below command line
sudo npm install pm2 -g
We will use this service when we install the script.
Last updated