DEV Community

Cover image for AWS Systems Manager Automation to Install a LAMP Web Server & Hosting a WordPress Blog on Amazon Linux or Amazon Linux 2
Dinesh Rathee
Dinesh Rathee

Posted on • Updated on

AWS Systems Manager Automation to Install a LAMP Web Server & Hosting a WordPress Blog on Amazon Linux or Amazon Linux 2

Background:

In general we follow the documentation to get started. Now, we have SSM Service which can do this in an automated fashion which is quicker and does all your job without any direct user interaction on OS level.

Which SSM Automation Documents you can use ?

You can use below Automated Documents to achieve this task :

For Amazon Linux:

For Amazon Linux 2:

Some Important Tips Before you Start:

➜ Please note that these documents may not be available in one of the regions you've targeted. I've checked their presence in - (us-east-1,us-east-2,us-west-1,us-west-2,ca-central-1,eu-central-1,eu-west-1,eu-west-2,eu-west-3,sa-east-1,ap-northeast-1). Please choose your region and proceed.

➜ To know more on these documents and what they usually do, you can click on the Hyperlinks above.

➜ To run the following Automation documents, you must have permissions to run Automation workflows and create the resources mentioned there. The Automation workflow runs in the context of the current AWS Identity and Access Management (IAM) user. If you have admin privileges , it will be great !

➜ You should follow the sequence for executing it successfully as mentioned above and I am also explaining an example below

➜ To track any Progress or Failure, You can navigate to SSM Automation Execution or CloudFormation Stack details.

➜ To delete resources created you can go to CloudFormation Stack and delete, It will automatically deletes resources.

➜ You can preserve your resources (to avoid any accidental deletion) using CloudFormation Stack by choosing - "Stack Actions" -> "Edit Termination Protection" --> Choose - "Enabled" & Save


Now, we will see how to use AWS Systems Manager Automation Documents .. I will be taking an Example for "Amazon Linux 2"

- Use Case :- " I want to Install LAMP over Amazon Linux 2 based Instance and want to host a WordPress Blog on it "
You can do it either using Console (steps below) or using AWS CLI (check my post)

Steps Using Console:

As I've mentioned - I will follow the sequence for executing – 1st Doc (“AWSDocs-InstallALAMPServer-AL2”) and then check if “Success” , then will Execute 2nd Doc ( “AWSDocs-HostingAWordPressBlog-AL2”)

*Note:*
Please make sure you're in the right AWS region where you want to deploy your blog.

1). Click on below quick-link to Execute 1st Doc (“AWSDocs-InstallALAMPServer-AL2”) :

[+] https://console.aws.amazon.com/systems-manager/automation/execute/AWSDocs-InstallALAMPServer-AL2

Alt Text

Once you click on "Execute" Button the Automation will start and you can see this as follows:
Alt Text

You can see the the CloudFormation Console to see what resources are being created by Stack:
Alt Text

Alt Text

You can Monitor the overall Success in the Execution Status under SSM Automation Executions:

Alt Text

Now, We have an EC2 Instance ready with required configurations:
Alt Text
We've confirmed the Execution Status - "Success" for first doc, Now, we can proceed further for our next step..

2). Click on below quick-link to Execute 2nd Doc ( “AWSDocs-HostingAWordPressBlog-AL2”) :

[+] https://console.aws.amazon.com/systems-manager/automation/execute/AWSDocs-HostingAWordPressBlog-AL2
Alt Text

Once you click on "Execute" Button the Automation will start performing actions on your Instance you can see this as follows:
Alt Text

Alt Text

You can Monitor the overall Success in the Execution Status under SSM Automation Executions
Alt Text

Now, We've confirmed the Execution Status - "Success" for second doc as well, Now, we can proceed further for our next step for final touch on WordPress..

3). Attached an EIP (Elastic IP) to the Instance to make sure the IP doesn't change in future. To know more on EIP allocation and Assignment , please refer here.
Alt Text

4). Once the Automation has completed, you will be able to navigate to the WordPress blog dashboard by entering public DNS /EIP address (or the public IP address) of the launched instance in your browser :

For example: (in my use-case)

[+] http://ec2-54-194-131-54.eu-west-1.compute.amazonaws.com/ or [+] http://54.xxxxxxx/

Also, it will automatically route you to "WordPress wp-admin" page which looks like below :
Alt Text
Click Continue and Just fill in the information below and you’ll be on your way to using wordpress to manage your blog :
Alt Text
Please make a note of username and password to manage your WordPress blog. Click on "Install WordPress" b utton.

Alt Text
Click Login and use the Id and Password provided above :
Alt Text
Here is the WordPress Dashboard to manage you Blog:
Alt Text

Checking my New WordPress blog created :
[+] http://ec2-54-xxxxxxxxx4.eu-west-1.compute.amazonaws.com/ or [+] http://54.xxxxxxxxx/

Alt Text

To delete the Resources created

➜ To delete resources created you can go to CloudFormation Stack and Select your Stack and choose Delete, It will automatically deletes resources.
Alt Text

<>

➜ You can go to CloudFormation Stack and Select your Stack and choose - "Stack Actions" -> "Edit Termination Protection" --> Choose - "Enabled" & Save

This will basically will avoid your resources being deleted accidentally by CloudFormation action. To know more on this, please check Public Documentation.
Alt Text

Alt Text

**Want to see something more Interesting ?? **

Check out below post ---
How to Perform Above Steps Using AWS CLI, Please check --- Post:
[+] https://dev.to/dineshrathee12/using-aws-cli-automating-post-aws-ssm-to-setup-a-lamp-web-server-hosting-a-blog-on-it-quick-427f

**

References:

[+] Tutorials for Amazon EC2 Instances Running Linux: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-tutorials.html
[+] Tutorial: Install a LAMP Web Server with the Amazon Linux AMI: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/install-LAMP.html

[+] AWSDocs-InstallALAMPServer-AL : https://eu-west-1.console.aws.amazon.com/systems-manager/automation/execute/AWSDocs-InstallALAMPServer-AL?region=eu-west-1

[+] Tutorial: Hosting a WordPress Blog with Amazon Linux : https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/hosting-wordpress.html

[+] AWSDocs-HostingAWordPressBlog-AL : https://console.aws.amazon.com/systems-manager/automation/execute/AWSDocs-HostingAWordPressBlog-AL

[+] Tutorial: Install a LAMP Web Server on Amazon Linux 2: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-lamp-amazon-linux-2.html

[+] AWSDocs-InstallALAMPServer-AL2 : https://eu-west-1.console.aws.amazon.com/systems-manager/home?redirect=%2Fsystems-manager%2Fautomation%2Fexecute%2FAWSDocs-InstallALAMPServer-AL2®ion=eu-west-1

[+] AWSDocs-HostingAWordPressBlog-AL2 : https://console.aws.amazon.com/systems-manager/home?redirect=%2Fsystems-manager%2Fautomation%2Fexecute%2FAWSDocs-HostingAWordPressBlog-AL2

[+] Troubleshooting AWS CloudFormation : https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/troubleshooting.html
[+] Troubleshooting Systems Manager Automation: https://docs.aws.amazon.com/systems-manager/latest/userguide/automation-troubleshooting.html

[+] WordPress : https://wordpress.com/start/?ref=create-lp

Latest comments (0)