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.
cd /opt/bitnami/apache2/htdocs rm -rf *
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
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.*
config.php file into the configs/ directory:
sudo cp config.php ../configs ls ../configs
ENDPOINT=localhost && \ USERNAME=root && \ PASSWORD=$(cat /home/bitnami/bitnami_application_password)
echo "Endpoint = "$ENDPOINT echo "Username = "$USERNAME echo "Password = "$PASSWORD
config.php file:
cp /opt/bitnami/apache2/configs/config.php /opt/bitnami/apache2/configs/config.php.bak
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/;"
cat /opt/bitnami/apache2/configs/config.php
config.php is now in production.
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.
install.php script by navigating to that website in the browser
http://<IP-address>/install.php
http://<IP-address>/