{"id":20371556,"url":"https://github.com/atulkamble/ec2-webserver-git-setup","last_synced_at":"2025-07-10T06:07:22.570Z","repository":{"id":254649001,"uuid":"847156669","full_name":"atulkamble/ec2-webserver-git-setup","owner":"atulkamble","description":"Comprehensive guide and code for setting up a web server on an AWS EC2 instance using Git. Includes steps for launching an instance, configuring a web server, setting up Git for automatic deployment, and securing the site with SSL/TLS.\"  Here's a comprehensive guide for setting up a web server project on an EC2 instance using Git","archived":false,"fork":false,"pushed_at":"2024-08-31T04:05:15.000Z","size":22,"stargazers_count":0,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-03T13:28:01.331Z","etag":null,"topics":["ec2","git","webserver"],"latest_commit_sha":null,"homepage":"http://linkedin.com/in/atuljkamble","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/atulkamble.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-25T02:38:49.000Z","updated_at":"2024-08-31T04:05:18.000Z","dependencies_parsed_at":"2024-08-26T09:14:04.363Z","dependency_job_id":null,"html_url":"https://github.com/atulkamble/ec2-webserver-git-setup","commit_stats":null,"previous_names":["atulkamble/webserver-git-ec2","atulkamble/ec2-webserver-git-setup"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/atulkamble/ec2-webserver-git-setup","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atulkamble%2Fec2-webserver-git-setup","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atulkamble%2Fec2-webserver-git-setup/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atulkamble%2Fec2-webserver-git-setup/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atulkamble%2Fec2-webserver-git-setup/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/atulkamble","download_url":"https://codeload.github.com/atulkamble/ec2-webserver-git-setup/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atulkamble%2Fec2-webserver-git-setup/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264537408,"owners_count":23624420,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ec2","git","webserver"],"created_at":"2024-11-15T01:08:31.105Z","updated_at":"2025-07-10T06:07:22.552Z","avatar_url":"https://github.com/atulkamble.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"### EC2 Web Server Setup with Git\nComprehensive guide and code for setting up a web server on an AWS EC2 instance using Git. Includes steps for launching an instance, configuring a web server, setting up Git for automatic deployment, and securing the site with SSL/TLS.\n\nHere's a comprehensive guide for setting up a web server project on an EC2 instance using Git, with the necessary code and step-by-step instructions.\n\n### 1. *Launch an EC2 Instance*\n\n1. *Login to AWS Console*:\n   - Go to the EC2 dashboard and launch a new instance.\n\n2. *Select AMI*:\n   - Choose Amazon Linux 2023 or Ubuntu.\n\n3. *Instance Type*:\n   - Choose t2.micro (free tier eligible).\n\n4. *Configure Instance*:\n   - Keep default settings or adjust as needed.\n\n5. *Add Storage*:\n   - Use the default 8 GB or increase as per your needs.\n\n6. *Configure Security Group*:\n   - Allow SSH (port 22) and HTTP (port 80).\n   - Optionally, allow HTTPS (port 443) for SSL later.\n\n7. *Key Pair*:\n   - Create or choose an existing key pair for SSH access.\n\n8. *Launch the Instance*:\n   - Start the instance and note the public IP.\n\n### 2. *Connect to the EC2 Instance*\n\n1. *SSH into Instance*:\n   - Use the following command on your local machine:\n     ```\n     ssh -i /path/to/your-key.pem ec2-user@your-ec2-public-ip\n     ```\n   - For Ubuntu:\n     ```\n     ssh -i /path/to/your-key.pem ubuntu@your-ec2-public-ip\n     ```\n\n### 3. *Install Git and Web Server*\n\n1. *Update the Instance*:\n   - Run the following commands to update the package lists:\n     ```\n     sudo yum update -y    # Amazon Linux\n     sudo apt-get update -y # Ubuntu\n     ```\n\n2. *Install Git*:\n   - Install Git by running:\n     ```\n     sudo yum install git -y    # Amazon Linux\n     sudo apt-get install git -y # Ubuntu\n     ```\n\n3. *Install Apache or Nginx*:\n   - For Apache:\n     ```\n     sudo yum install httpd -y    # Amazon Linux\n     sudo apt-get install apache2 -y # Ubuntu\n     ```\n   - For Nginx:\n     ```\n     sudo yum install nginx -y    # Amazon Linux\n     sudo apt-get install nginx -y # Ubuntu\n     ```\n\n4. *Start the Web Server*:\n   - Start the web server:\n     ```\n     sudo systemctl start httpd    # Apache\n     sudo systemctl start apache2  # Apache on Ubuntu\n     sudo systemctl start nginx    # Nginx\n     ```\n\n5. *Enable Web Server on Boot*:\n   - Ensure the web server starts on reboot:\n     ```\n     sudo systemctl enable httpd    # Apache\n     sudo systemctl enable apache2  # Apache on Ubuntu\n     sudo systemctl enable nginx    # Nginx\n     ```\n\n### 4. *Set Up a Git Repository for the Web Server*\n\n1. *Navigate to Web Directory*:\n   - Apache:\n     ```\n     cd /var/www/html\n     ```\n   - Nginx:\n     ```\n     cd /usr/share/nginx/html\n     ```\n\n2. *Initialize a Git Repository*:\n   - Run:\n     ```\n     sudo git init\n     ```\n\n3. *Configure Git User*:\n   - Set up Git user information:\n     ```\n     git config --global user.name \"Your Name\"\n     git config --global user.email \"your.email@example.com\"\n     ```\n\n### 5. *Add and Commit Web Content*\n\n1. *Create a Basic HTML File*:\n   - Apache:\n     ```\n     echo \"\u003ch1\u003eHello, World!\u003c/h1\u003e\" | sudo tee index.html\n     ```\n   - Nginx:\n     ```\n     echo \"\u003ch1\u003eHello, World!\u003c/h1\u003e\" | sudo tee index.html\n     ```\n\n2. *Stage and Commit the File*:\n   - Run:\n     ```\n     sudo git add index.html\n     sudo git commit -m \"Initial commit with index.html\"\n     ```\n\n### 6. *Set Up a Remote Git Repository (Optional)*\n\n1. *Create a Repository on GitHub*:\n   - Log in to GitHub and create a new repository.\n\n2. *Link to Remote Repository*:\n   - Connect your local repository to GitHub:\n     ```\n     sudo git remote add origin https://github.com/username/repository.git\n     sudo git branch -M main\n     sudo git push -u origin main\n     ```\n\n### 7. *Set Up a Post-Receive Hook for Automatic Deployment*\n\n1. *Create a Post-Receive Hook*:\n   - Navigate to the Git hooks directory:\n     ```\n     cd /var/www/html/.git/hooks    # Apache\n     cd /usr/share/nginx/html/.git/hooks # Nginx\n     ```\n\n2. *Create the post-receive Hook*:\n   - Create the hook script:\n     ```\n     sudo nano post-receive\n     ```\n   - Add the following content to the script:\n     ```\n     #!/bin/bash\n     GIT_WORK_TREE=/var/www/html git checkout -f   # Apache\n     GIT_WORK_TREE=/usr/share/nginx/html git checkout -f # Nginx\n     ```\n   - Save and exit.\n\n3. *Make the Hook Executable*:\n   - Run:\n     ```\n     sudo chmod +x post-receive\n     ```\n\n### 8. *Push Changes from Your Local Machine*\n\n1. *Clone the Repository Locally*:\n   - Clone the GitHub repository to your local machine:\n     ```\n     git clone https://github.com/username/repository.git\n     cd repository\n     ```\n\n2. *Make Changes to the Website*:\n   - Modify index.html or other files locally.\n\n3. *Commit and Push Changes*:\n   - Stage, commit, and push the changes:\n     ```\n     git add .\n     git commit -m \"Updated website content\"\n     git push origin main\n     ```\n\n4. *Deploy Changes Automatically*:\n   - The changes will be automatically deployed to your EC2 instance thanks to the post-receive hook.\n\n### 9. *Access Your Website*\n\n1. *View Your Website*:\n   - Open a web browser and navigate to http://your-ec2-public-ip to view your deployed website.\n\n### 10. *Set Up HTTPS with SSL/TLS (Optional)*\n\n1. *Install Certbot*:\n   - Install Certbot for Apache or Nginx:\n     ```\n     sudo yum install certbot python3-certbot-apache -y   # Apache\n     sudo yum install certbot python3-certbot-nginx -y    # Nginx\n     ```\n\n2. *Run Certbot*:\n   - Obtain and install the SSL certificate:\n     ```\n     sudo certbot --apache    # Apache\n     sudo certbot --nginx     # Nginx\n     ```\n\n3. *Follow the Prompts*:\n   - Certbot will guide you through securing your website with HTTPS.\n\nThis step-by-step guide should help you set up a web server project on an EC2 instance using Git, complete with automatic deployment and optional HTTPS setup.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatulkamble%2Fec2-webserver-git-setup","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fatulkamble%2Fec2-webserver-git-setup","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatulkamble%2Fec2-webserver-git-setup/lists"}