Deploy a LAMP stack application

to Amazon Lightsail

Amazon Lightsail is the easiest way to get started on AWS. It offers virtual servers, storage, databases and networking, plus a cost-effective, monthly plan.

In this tutorial you deploy a LAMP (Linux Apache MySQL PHP) stack application onto a single Lightsail instance.

You start by deploying a new Lightsail instance that includes Apache, MySQL, and PHP preinstalled. Then, you add the demo application code. When you're done, you will have a solid understanding of how to use Lightsail to quickly standup a multi-tier web application.

Get started with Lightsail for free.

About this Tutorial
Time 10 minutes                                           
Cost Free Tier Eligible
Use Case Compute
Products Amazon Lightsail
Audience Developer
Level Beginner
Last Updated March 20, 2020

1. Create an Amazon Lightsail account

This tutorial is free tier eligible. 

If you don’t have one already, create a free Amazon Web Services account. Then sign into your account, and navigate to the Lightsail home page

 

Already have an account? Sign-in

2. Create an Amazon Lightsail instance

In this section you start the instance creation process by choosing the AWS Region where you want your demo application to run. Additionally, you also choose the LAMP Blueprint. Blueprints are preconfigured instance templates that include the core services your application needs to run – in this case: Apache, MySQL, and PHP.


a. Click on Create instance on the Instances tab of the Lightsail homepage. 

amazon-wordpress-tutorial-05

b. An AWS Region and Availability Zone is selected for you. Choose Change Region and Availability Zone to create your instance in another location. 

amazon-wordpress-tutorial-02

c. Under Select a Blueprint choose LAMP (PHP 7)

mike1

3. Install the application code

In this section you use a launch script to install the demo application. Launch scripts run the first time an instance boots up, and are used to do any initial configuration on an instance.


a. Click +Click Launch Script.

mike2

b. Paste the script below into the launch script text window.

The script performs the following actions:

  • Removes the default Apache website
  • Clones the application code from GitHub into the htdocs directory
  • Ensures the configuration file is writeable
  • Uses sed to read the local database password from a file on the disk and insert it into the configuration file
  • Runs an SQL script to setup the application’s database
# remove default website
#-----------------------
cd /opt/bitnami/apache2/htdocs 
rm -rf *

# clone github repo
#------------------
git clone -b loft https://github.com/mikegcoleman/todo-php .

# set write permissons on the settings file
#-----------------------------------
chown bitnami:daemon connectvalues.php
chmod 666 connectvalues.php

# inject database password into configuration file
#-------------------------------------------------
sed -i.bak "s/<password>/$(cat /home/bitnami/bitnami_application_password)/;" /opt/bitnami/apache2/htdocs/connectvalues.php

# create database
#----------------
cat /home/bitnami/htdocs/data/init.sql | /opt/bitnami/mysql/bin/mysql -u root -p$(cat /home/bitnami/bitnami_application_password)

c. Choose the free tier instance plan.

A plan includes a low, predictable cost, machine configuration (RAM, SSD, vCPU), and data transfer allowance. You can try the $3.50 USD Lightsail plan without charge for one month (up to 750 hours). AWS credits one free month to your account.

mike3

d. Scroll down and click Create Instance.

image9

4. Test the application

In this final section youmaccess the running application to ensure everything is running properly.


a. It will take 2-3 minutes for your instance to start up. Once the status is Running move on to the next step.

Note: You may need to refresh your web browser to see the updated status.

mike4

b. Make a note of your instance’s IP address.

mike5

c. In your web browser, navigate to the instance’s IP address. You should see the application running.

mike6

Congratulations

You used Amazon Lightsail run a LAMP stack application.

Amazon Lightsail is great for developers, WebPros, and anyone looking to get started on AWS in a quick and cheap way. You can launch instances, databases, SSD-based storage, transfer data, monitor your resources, and so much more in a managed way.&nbsp;&nbsp;

Was this tutorial helpful?

Thank you
Please let us know what you liked.
Sorry to disappoint you
Is something out-of-date, confusing or inaccurate? Please help us improve this tutorial by providing feedback.