Before running deployment script, ensure EC2 already has:
Target deployment directory:
/var/www/html/
Inside Jenkins Job:
Configure → Build Steps → Execute Shell
Paste this script:
#!/bin/bash
set -e
echo "Removing old website files..."
sudo rm -rf /var/www/html/*
echo "Copying new website files..."
sudo cp -R * /var/www/html/
echo "Setting correct permissions..."
sudo chown -R www-data:www-data /var/www/html/
sudo chmod -R 755 /var/www/html/
echo "Restarting Nginx..."
sudo systemctl restart nginx
echo "Deployment completed successfully"
Save job → Click Build Now
Website will be live at:
<http://EC2-PUBLIC-IP>