Setting Up GitHub Webhook on GCP VM


1. Clone the Repository to the Server

Goal: Get the files into /var/www/html.

Commands:

cd ~
git clone <https://github.com/USERNAME/REPONAME.git>
sudo mv ~/LAMPTest/* ~/LAMPTest/.* /var/www/html/
sudo chown -R www-data:www-data /var/www/html

Why: Initial SSH attempts ([email protected]:...) failed with Permission denied (publickey), so I used HTTPS and moved the contents directly into /var/www/html.


2. Set Up Apache and PHP (Should be done previously)

Goal: Ensure the LAMP stack serves the PHP files.

Commands:

sudo systemctl start apache2
sudo systemctl enable apache2
sudo apt update
sudo apt install php libapache2-mod-php php-mysql

Why: The repo contains PHP files (e.g., index.php). Confirmed working with curl localhost and browser access after firewall setup.


3. Configure GCP Firewall (Depends on user/Set up previously)

Goal: Allow external access to the site.

gcloud compute firewall-rules create allow-http --direction=INGRESS --priority=1000 --network=default --action=ALLOW --rules=tcp:80 --source-ranges=0.0.0.0/0

Why: The site at http://IP-ADDRESS wasn’t reachable until HTTP traffic (port 80) was allowed.