AWS Systems Manager Automation to Install a LAMP Web Server & Hosting a WordPress Blog on Amazon Linux or Amazon Linux 2
Tags: aws, linux, wordpress, devops
Published: 2020-02-19 02:08:57

**Background:**

_In general we follow the  **[documentation](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-tutorials.html)** 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 :

**<u>For Amazon Linux:</u>**  
-   First Execute - Automation Document Name: **[AWSDocs-InstallALAMPServer-AL](https://console.aws.amazon.com/systems-manager/automation/execute/AWSDocs-InstallALAMPServer-AL)  ---->** Basically Automates -  **[this documentation](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/install-LAMP.html) and once the Execution result is "Success"**
-   Then Execute - Automation Document Name:  **[AWSDocs-HostingAWordPressBlog-AL](https://console.aws.amazon.com/systems-manager/automation/execute/AWSDocs-HostingAWordPressBlog-AL)** ----> Basically Automates -  **[this documentation](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/install-LAMP.html)**

**<u>For Amazon Linux 2:</u>**  
-   First Execute -  Automation Document Name: **[AWSDocs-InstallALAMPServer-AL2](https://console.aws.amazon.com/systems-manager/automation/execute/AWSDocs-InstallALAMPServer-AL2)** ----> Basically Automates -  **[this documentation](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-lamp-amazon-linux-2.html)** and once the Execution result is "Success"
-   Then Execute -  Automation Document Name:  **[AWSDocs-HostingAWordPressBlog-AL2](https://console.aws.amazon.com/systems-manager/automation/execute/AWSDocs-HostingAWordPressBlog-AL2)** ----> Missing a reference as of now for documentation.

**<u>Some Important Tips Before you Start:</u>**

➜  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. **<u>If you have admin privileges , it will be great !</u>**

➜ 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](http://console.aws.amazon.com/systems-manager/automation/executions?)** or  **[CloudFormation Stack](http://console.aws.amazon.com/cloudformation/home?#/stacks/)**  details.

➜ To delete resources created you can go to [**CloudFormation Stack**](http://console.aws.amazon.com/cloudformation/home?#/stacks/)  and delete, It will automatically deletes resources.

➜ You can preserve your resources (to avoid any accidental deletion) using **[CloudFormation Stack](http://console.aws.amazon.com/cloudformation/home?#/stacks/)** 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](https://dev.to/dineshrathee12/using-aws-cli-automating-post-aws-ssm-to-setup-a-lamp-web-server-hosting-a-blog-on-it-quick-427f)**)

**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”)

****<u>Note:</u>**** 
**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](https://console.aws.amazon.com/systems-manager/automation/execute/AWSDocs-InstallALAMPServer-AL2)**

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/fqaw12f61kl7trqhpsjk.JPG)

Once you click on **"Execute"** Button the Automation  will start and you can see this as follows:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/lwhz3qsgpgi8t42awuds.JPG)

You can see the the **[CloudFormation Console](http://console.aws.amazon.com/cloudformation/home?#/stacks/)**  to see what  resources are being created by Stack:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/sa9re1zu68ft00wxwnya.JPG)

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/j16r7m2fn2rgojo2khj3.jpg)

You can Monitor the overall  **Success** in the Execution Status under **[SSM Automation Executions](http://console.aws.amazon.com/systems-manager/automation/executions?)**:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/m1pjuz1vqs5v2xenu34j.JPG)

Now, We have an **EC2 Instance** ready with required configurations:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/9y0bg48l2vpi84cu5xzc.JPG)
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](https://console.aws.amazon.com/systems-manager/automation/execute/AWSDocs-HostingAWordPressBlog-AL2)**
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/cuantrhphb8v0nqbuas2.jpg)

Once you click on **"Execute"** Button the Automation  will start performing actions on your  **Instance** you can see this as follows:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/as9c156njel2o9lmlj61.JPG)

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/o7hjiq07q2kxbs1e2k3v.jpg)

You can Monitor the overall Success in the Execution Status under **[SSM Automation Executions](http://console.aws.amazon.com/systems-manager/automation/executions?)**
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/qa84tq320iq2wu8cwkeu.JPG)

Now, <u>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..</u>

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](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/elastic-ip-addresses-eip.html)**.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/ernbj5qeccjgz2h6mqqc.jpg)

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/](http://ec2-54-194-131-54.eu-west-1.compute.amazonaws.com/) or [+]** [**http://54.xxxxxxx/**](http://54.xxxxxxxxxxxxx/)  

Also, it will automatically route you to  **"WordPress wp-admin"**  page which looks like below :
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/nxo2i9spekzxnxqwdbr6.jpg)
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](https://dev-to-uploads.s3.amazonaws.com/i/0fr670wxskmhrs8byhqg.jpg)
Please make a note of  **username** and  **password** to manage your WordPress blog. Click on  **"Install WordPress"** b  utton.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/ligl9r7g0947bgj6yw6h.jpg)
Click **Login** and use the Id and Password provided above :
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/ittrla5khe65lvxvz1s5.jpg)
Here is the **WordPress Dashboard** to manage you Blog:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/3yxu3ytj9vifvzvenp7z.jpg)

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

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/acbcfv39jae72lvzgzau.jpg)

**To delete the Resources created** 

➜ To delete resources created you can go to **[CloudFormation Stack](http://console.aws.amazon.com/cloudformation/home?#/stacks/)**  and Select your Stack and choose  **Delete**, It will automatically deletes resources.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/2dp2y4pkpsvadbk81jwm.jpg)

***<<To preserve the Resources created / Avoid Accidental deletion >>***

➜ You can go to **[CloudFormation Stack](http://console.aws.amazon.com/cloudformation/home?#/stacks/)**  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.](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-protect-stacks.html?icmpid=docs_cfn_console)**
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/p87ghta4u3kxvpd5kykq.jpg)

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/955wn9hku7qo1rbpi7tc.jpg)


## ***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](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](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](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](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](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](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](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](https://eu-west-1.console.aws.amazon.com/systems-manager/home?redirect=%2Fsystems-manager%2Fautomation%2Fexecute%2FAWSDocs-InstallALAMPServer-AL2&region=eu-west-1)  
**[+] AWSDocs-HostingAWordPressBlog-AL2 :**  [https://console.aws.amazon.com/systems-manager/home?redirect=%2Fsystems-manager%2Fautomation%2Fexecute%2FAWSDocs-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](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](https://docs.aws.amazon.com/systems-manager/latest/userguide/automation-troubleshooting.html)

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