DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Amazon EC2: Apache, Git, Website Hosting with Cloud-Init

Amazon EC2: Apache, Git, Website Hosting with Cloud-Init

Mikael Koskinen user avatar by
Mikael Koskinen
·
May. 24, 12 · Interview
Like (0)
Save
Tweet
Share
9.70K Views

Join the DZone community and get the full member experience.

Join For Free

Lately I’ve enjoyed working with static web sites. My company’s web pages were previously powered by Wordpress and now they’re just static html pages. There’s few things I especially like with a static web site when compared to other solutions:

  • Performance
  • Hosting options
  • Ease of deployment

Performance

Even though I find the Wordpress near great with all its plugins and themes, the previous web site never felt fast enough. With a static web site you usually don’t have to worry about the performance.

Hosting options

You can host the static site almost everywhere: You don’t need ASP.NET or PHP. You just need a web server like IIS or Apache. Or GitHub.The web server can be run using for example Amazon EC2.

Ease of deployment

In addition to pros mentioned above a static web site is also easy to deploy: There’s no need for a database or configuration. In my case the company web site (html, css and js) is available from a GitHub repository. To host the site on a new web server requires only a Git Clone to the correct directory.

Using Amazon EC2 to host the web site: Automating the deployment

Given that the static web site is available using Git and because we only need a web server to host the site, we can automate the site’s deployment. Here’s how we can do it using Amazon EC2:

1. Launch new instance

Start the Quick Launch Wizard and select Amazon Linux AMI:

image

Amazon Linux supports the configuration of the launch process using cloud-init. Unfortunately I haven’t found any really good examples of using the cloud-init but here’s couple sources: A thread in AWS forums and the following source.

2. Make sure that the instance’s firewall allows the web traffic through

By default the TCP port 80 is blocked. Select a security group which allows the traffic through or create a new security group:

image

3. Input the cloud-init into the “User Data” –field

Here’s a cloud-init initialization code which does the following things:

  1. Installs Apache
  2. Installs Git
  3. Starts the web server
  4. Clones the web site from GitHub into the web server’s root
#cloud-config
packages:
 - httpd
 - git
 
runcmd:
 - [ /etc/init.d/httpd, restart ]
 - [ git, clone, "-b", "gh-pages", "git://github.com/mikoskinen/softwaremkwebsite.git", "/var/www/html"]

Here’s how the cloud-init initialization code can be set when launching a new Amazon EC2 instance:

 image

And that’s it. After few minutes the Amazon EC2 is ready and hosting the static web site:

image

image

AWS Git Web server

Published at DZone with permission of Mikael Koskinen, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • What Are the Benefits of Java Module With Example
  • How Chat GPT-3 Changed the Life of Young DevOps Engineers
  • GitLab vs Jenkins: Which Is the Best CI/CD Tool?
  • Practical Example of Using CSS Layer

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: