Install and Configure Git on Amazon Lightsail, and Deploy Your Website in Minutes! (Freebie Inside)

Written by thebriangraf | Published 2022/10/12
Tech Story Tags: vps | git | web-development | aws | amazon-lightsail | easy | html | vscode

TLDRDeploy a web server with Git, Apache, and your website in less than 5 minutes on Amazon Lightsailvia the TL;DR App

People want to get their websites or applications up and running as quickly as possible. With Amazon Lightsail, we are able to deploy our web server, install & configure Git, clone our GitHub repo, and enable our web services with less than 2 minutes of work. Don’t believe me? Check this out!

First, what is Amazon Lightsail?

Amazon Lightsail is an easy-to-use service that provides Virtual Private Servers (VPS) with CPU, Memory, Storage, and Data Transfer Allowances at a predictable monthly price, with the cheapest being $3.50/month!

Another benefit of Lightsail is that you can choose either a bare Operating System or an application blueprint to help you get up and running faster. Some application blueprints offered include: WordPress, PrestaShop, GhostCMS, Adobe Magento, LAMP stack, MEAN stack, etc.

Let’s Do this in less than 2 minutes!

  • Next, and this part is what saves us a LOT of time, we’ll use a Launch Script. This is a run-once script that will be executed after Lightsail deploys your instance. In this case with Amazon Linux 2 we use the following script:
sudo yum update -y
sudo yum install -y git
sudo yum install -y httpd.x86_64
sudo systemctl start httpd.service
sudo systemctl enable httpd.service

git clone https://github.com/lightsail-demo-environment/dimension-public

sudo mv ./dimension-public/* /var/www/html/

This script updates the packages library, installs Git, installs apache, starts the apache service, adds it to run on startup in case our instance is rebooted, clones my website repo, and then moves the files into my web directory.

If your GitHub repo is private, You’ll need to authenticate to your private repo in the CLI to clone the files. Will create a post about that another day.

  • We then choose an instance size. As you saw in the first image under ‘What is Amazon Lightsail’ you’ll notice that Lightsail has 7 different instance sizes. Depending on the needs of your site, you can choose the corresponding instance size. (You can always upgrade to a bigger size later if needed).
  • Give your instance a name and add any tags you’d like. Tags are meant to help identify workloads depending on your needs.
  • Click ‘Create Instance’

  • Your Website will begin deploying. Once it’s deployed you’ll see that it is ‘Running’ and has an IP address. This is not a static IP, but a static IP can easily be attached in the next (optional) step

(Optional) Add a Static IP to your website

If you want to add a static IP, Lightsail makes it easy to generate the IP and attach it to your instance. Once you click on your instance, click the ‘Networking’ tab

  • Click ‘Attach static IP’
  • Click ‘Create Static IP’

  • Give your static IP a name, then click ‘Create’

Your static IP is now created and assigned to your instance. We can then copy-and-paste the IP address into our browser and see that our website is up and running.

FREEBIE

As I said in the title, there is a freebie here too if this is your first time trying Amazon Lightsail. Head on over and sign up to use the service and get your first 3-months free (if you choose one of the associated instance types). Let me know what you think!


Written by thebriangraf | Senior Developer Advocate @ AWS Dad of lots of kids. Love the outdoors, love coding, love travel
Published by HackerNoon on 2022/10/12