Up: Task 2---Deploy a Monolithic LAMP Application   [Contents][Index]


3.4.1 Deploy a LAMP Stack Application

In this task, you will deploy the application code into your Lightsail instance, as well as configure the connection between the PHP application and the locally running MySQL database.

The following steps are performed from the LAMP instance command line by using either your own SSH client, or the web-based SSH access provided by Lightsail.

  1. SSH into the LAMP instance.
  2. The LAMP Bitnami image has some default web pages installed, and you must remove them so you can deploy the PHP application. Move into the Apache directory and remove the default web site installed by Lightsail
    cd /opt/bitnami/apache2/htdocs
    rm -rf *
    
  3. Use the application wget to download the application code as a Zip file and then unzip:
    wget https://s3-us-west-2.amazonaws.com/us-west-2-aws-training/awsu-spl/spl-220/scripts/todo.zip -O /tmp/todo.zip
    unzip /tmp/todo.zip
    
  4. This PHP application uses a config file called config.php to configure how the frontend talks to the database (hostname, username, password). That file needs to live in the configs/ directory. You need to create this directory and set its owner to bitnami, which is the user and group that the Apache web server runs as, so that it will then be able to read the configs/ file:
    sudo mkdir /opt/bitnami/apache2/configs
    sudo chown bitnami:bitnami /opt/bitnami/apache2/configs
    

    *As a best practice, never store sensitive information in the document root of your web server. Ideally, in production, you would use a secrets management solution, such as AWS Secrets Manager.*

  5. Copy the default config.php file into the configs/ directory:
    sudo cp config.php ../configs
    ls ../configs
    
  6. Set environment variables to aid in editing the configuration file. The default password for the instance database is stored in a file in the ‘home’ directory (‘/home/bitnami/bitnami_application_password’).
    ENDPOINT=localhost && \
    USERNAME=root && \
    PASSWORD=$(cat /home/bitnami/bitnami_application_password)
    
  7. Verify the environment variables:
    echo "Endpoint = "$ENDPOINT
    echo "Username = "$USERNAME
    echo "Password = "$PASSWORD
    
  8. Make a backup of the config.php file:
    cp /opt/bitnami/apache2/configs/config.php /opt/bitnami/apache2/configs/config.php.bak
    
  9. Create a new configuration file to work with the locally installed database. The command below uses sed to go through the configuration file and replace the placeholder values with the values of the environment variables you set in the previous step. It writes these values into a new file (config.php.monolithic).
cat /opt/bitnami/apache2/configs/config.php | \
sed -i ".monolithic" -e "s/<endpoint>/$ENDPOINT/; \
s/<username>/$USERNAME/; \
s/<password>/$PASSWORD/;"
  1. Verify that the values are correct:
    cat /opt/bitnami/apache2/configs/config.php
    
  2. The config.php is now in production.
  3. After the configuration file is updated, the PHP application should connect to the local database engine.
  4. Prepare the database by installing it using an install.php script.

    In a real-world application, you would have defined processes on how to prepare the database for production. In the case of the demonstration application, you need to run a PHP script.

  5. Navigate to the running application:
    http://<IP-address>/
    
  6. Use the ‘Add Task’ button to add a few tasks.

Up: Task 2---Deploy a Monolithic LAMP Application   [Contents][Index]