Man in White Shirt Using Macbook Pro

Deploy a Node Express Project on Apache Web Server with GitHub Integration

we’ll walk you through the process of deploying a Node Express project on an Apache web server using VPS hosting. We’ll also integrate GitHub to automate the deployment process, ensuring smooth and efficient deployment of your applications.

1. Understanding PM2:
PM2 is a powerful process manager for Node.js, essential for managing your Node applications. It ensures that your processes are restarted every time your server boots, providing stability and reliability.

2. Setting up DNS Records:

  • Login to your domain provider website.
  • Navigate to Manage DNS.
  • Add the following records:
  Type    Host/Name    Value
  A       @            Your Remote Server IP
  A       www          Your Remote Server IP
  AAAA    @            Your Remote Server IPv6
  AAAA    www          Your Remote Server IPv6

3. Pushing Project to GitHub:

  • Open your project on VS Code.
  • Add a .gitignore file and create a .env.example file.
  • Push your project to your GitHub account as a private repository.

4. Accessing Remote Server via SSH:

  • SSH into your remote server using the command:

5. Verifying Software Installation:

  • Check that all required software is installed:
  apache2 -v
  node -v
  npm -v
  pm2 --version
  mongod --version
  git --version

6. Installing Apache and Node.js:

  • Install Apache and Node.js on your server:
  sudo apt install apache2
  curl -fsSL | sudo -E bash - &&\
  sudo apt-get install -y nodejs

7. Installing PM2:

  • Install PM2 globally on your server:
  sudo npm install -g pm2@latest

8. Adding PM2 Process on Startup:

  • Ensure PM2 starts on server boot:
  sudo pm2 startup

9. Installing MongoDB:

  • Install MongoDB on your server (follow installation instructions).

10. Setting Up GitHub SSH Key:

  • Generate SSH keys on your server and add them to your GitHub account.

11. Clone Project from GitHub:

  • Clone your project from GitHub to your server:
  git clone https_repo_path

12. Moving Project to Web Server Directory:

  • Move your project folder to the web server’s public directory:
  sudo mv project_folder_name /var/www

13. Setting Up Apache Virtual Host:

  • Create a virtual host file for your domain:
  sudo nano /etc/apache2/sites-available/your_domain.conf

14. Configuring Apache Virtual Host:

  • Add configuration for your domain in the virtual host file.

15. Enabling Virtual Host and Restarting Apache:

  • Enable the virtual host and restart Apache:
  sudo a2ensite your_domain.conf
  sudo service apache2 restart

16. Starting Node Express Application with PM2:

  • Start your Node Express application using PM2:
  cd /var/www/project_folder_name
  sudo NODE_ENV=production pm2 start app.js --watch --update-env --ignore-watch="user_upload_path"

17. Automating Deployment with GitHub Actions:

  • Create deployment scripts and workflows for GitHub Actions.

18. Finalizing Deployment:

  • Test the deployment and ensure everything is working correctly.

By following this comprehensive guide, you can successfully deploy your Node Express project on an Apache web server using VPS hosting, with seamless integration with GitHub for automated deployment. Enjoy hassle-free deployment and focus on building amazing applications!