Up: Task 3---Connect to an Amazon Lightsail Database   [Contents][Index]


3.5.1 Reconfigure the front end to point at the new Lightsail database

  1. From the horizontal menu in the Lightsail console home page, click ‘Databases’.
  2. Click todo-db.
  3. Under the ‘Connections details’, copy the ‘Endpoint’; it will look something like:
    ls-966d5bf6be8ee5178432a633398bf4256bfcab69.cucxkvhp11zu.us-west-2.rds.amazonaws.com
    
  4. In the SSH-window, create an environment variable named LS_ENDPOINT to hold the value of the endpoint of your database:
    LS_ENDPOINT=$(pbpaste)
    
  5. Create an environment variable for the default user name (dbmasteruser) and the password (taskstasks):
    LS_USERNAME=dbmasteruser
    LS_PASSWORD=taskstasks
    
  6. Verify the environment variables are set correctly:
    echo "Endpoint ="$LS_ENDPOINT
    echo "Username ="$LS_USERNAME
    echo "Password ="$LS_PASSWORD
    
  7. Create a new configuration file that points to the Lightsail database:
        cat /opt/bitnami/apache2/configs/config.php.bak | \
        sed "s/<endpoint>/$LS_ENDPOINT/; \
        s/<username>/$LS_USERNAME/;
        s/<password>/$LS_PASSWORD/;" \
        >> /opt/bitnami/apache2/configs/config.php.lightsail_db
    
  8. Verify that the file was modified properly:
    cat /opt/bitnami/apache2/configs/config.php.lightsail_db
    
  9. Activate the new configuration
    cp /opt/bitnami/apache2/configs/config.php.lightsail_db /opt/bitnami/apache2/configs/config.php
    
  10. Verify:
    cat /opt/bitnami/apache2/configs/config.php
    
  11. In a new browser tab run the install.php script to configure the database:
    http://<IP-address>/install.php
    
  12. Test the new database:
    http://<IP-address>
    

    There should not be any tasks displayed.

    Migrate the data out of your local MySQL database and into the Lightsail database. This is accomplished using two command line utilities: mysqldump and mysql. mysqldump extracts the content from the local database and pipes it into mysql, which loads the input into the Lightsail database.

        mysqldump -u root \
          --databases tasks \
          --single-transaction \
          --compress \
          --order-by-primary  \
          -p$(cat /home/bitnami/bitnami_application_password) \
          | mysql -u $LS_USERNAME \
          --port=3306 \
          --host=$LS_ENDPOINT \
          -p$LS_PASSWORD
    

    You will see two warnings regarding supplying a password via the command line. These warnings can safely be ignored, but note that, in production, you shouldn’t supply passwords via the command line, especially in scripts.

  13. Refresh the web page, and you should see that the tasks you originally created are now present in the database that’s managed by Lightsail.

Up: Task 3---Connect to an Amazon Lightsail Database   [Contents][Index]