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.
|About this Tutorial|
|Cost||Free Tier Eligible|
|Last Updated||September 9, 2020|
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.
b. An AWS Region and Availability Zone is selected for you. Choose Change Region and Availability Zone to create your instance in another location.
c. Under Select a Blueprint choose LAMP (PHP 7)
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.
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.
d. Scroll down and click Create Instance.
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.
b. Make a note of your instance’s IP address.
c. In your web browser, navigate to the instance’s IP address. You should see the application running.
Add a static IP address to your site:
- Assigning a static IP to your site ensures that the address does not change when the system is rebooted.
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.