Steps to Deploy Project on VPS

Share:

Steps to Deploy Project
1. Clone the Repository
Navigate to the home/ubuntu
directory and clone your project repository:
cd /home/ubuntu
git clone https://github.com/sabbirsami/sales-sync-up.git
2. Install Dependencies
Move into the project directory and install dependencies using npm
:
cd sales-sync-up
npm i
3. Build the Project
Run the build command to generate the production-ready files:
npm run build
4. Start the Application
Start the application on port 3005
:
npm start -p 3005
5. Set Up PM2 for Process Management
Use PM2 to manage your application process:
pm2 start npm --name sales -- start
Save the PM2 process list to ensure it persists after reboots:
pm2 save
Set up PM2 to start on system boot:
pm2 startup
6. Configure NGINX
1. Install NGINX (if not already installed):
sudo apt install nginx -y
2. Create an NGINX Configuration File:
- Create a new file in
/etc/nginx/sites-available/sales
:
sudo nano /etc/nginx/sites-available/sales
- Add the following configuration (replace
krishijaat.com
with your domain):
server {
server_name sales.baitsbd.com;
gzip on;
gzip_proxied any;
gzip_types application/javascript application/x-javascript text/css text/javascript;
gzip_comp_level 5;
gzip_buffers 16 8k;
gzip_min_length 256;
location /_next/static/ {
alias /home/ubuntu/sales-sync-up/.next/static/;
expires 365d;
access_log off;
}
location / {
proxy_pass http://127.0.0.1:3005;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
3. Enable the Configuration: Create a symbolic link to the sites-enabled
directory:
sudo ln -s /etc/nginx/sites-available/sales /etc/nginx/sites-enabled/
4. Test and Restart NGINX: Test the NGINX configuration:
sudo nginx -t
Restart NGINX to apply changes:
sudo systemctl restart nginx
7. Set Up SSL with Certbot
1. Install Certbot:
sudo apt install certbot python3-certbot-nginx -y
2. Obtain an SSL Certificate: Run Certbot to enable HTTPS for your domain:
sudo certbot --nginx -d sales.baitsbd.com
3. Test Certificate Renewal: Perform a dry run to ensure automatic renewal works:
sudo certbot renew --dry-run
8. Verify Deployment
1. Check NGINX Status: Ensure NGINX is running:
sudo systemctl status nginx
2. Restart PM2 Process: Restart your application using PM2:
pm2 restart sales
Additional Notes
- Ensure your domain (
sales.baitsbd.com
) points to the server's IP address (62.72.30.40
). - Replace
sales.baitsbd.com
with your actual domain in the NGINX configuration. - If you encounter permission issues with Git, ensure your SSH keys are correctly configured.
NGINX Configuration Template
Here's the NGINX configuration template for reference:
server {
server_name yourdomain.com www.yourdomain.com;
gzip on;
gzip_proxied any;
gzip_types application/javascript application/x-javascript text/css text/javascript;
gzip_comp_level 5;
gzip_buffers 16 8k;
gzip_min_length 256;
location /_next/static/ {
alias /home/ubuntu/sales-sync-up/.next/static/;
expires 365d;
access_log off;
}
location / {
proxy_pass http://127.0.0.1:3005;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
Troubleshooting
- Permission Denied (Public Key): Ensure your SSH key is added to your GitHub account.
- NGINX Syntax Errors: Use
sudo nginx -t
to test the configuration. - PM2 Not Starting: Check logs using
pm2 logs sales
.