By doing this project, you will learn how to automate the deployment of the WordPress application on the Amazon EC2 cloud using Cloudify.
Write a Cloudify blueprint for automating the installation of WordPress on the Amazon EC2 cloud. Perform the test on your Amazon EC2 account.
The blueprint should be written based on this topology: 
 
 
You may have a look at example blueprint from cloudify-nodecellar-example which we have used in the previous tutorial. The blueprint is based on TOSCA standard. You may have a look at this document.
Email your ip address of your WordPress site to the instructors. walid.gaaloul@telecom-sudparis.eu
You can use the following script to associate with your topology:
#!/bin/bash -e sudo apt-get update sudo apt-get -y install apache2
#!/bin/bash -e sudo apt-get update sudo apt-get -y install php5 php5-mysql libapache2-mod-php5 php5-mcrypt sudo sed -i.bak "s/index.html index.cgi index.pl index.php/index.php index.html index.cgi/g" /etc/apache2/mods-enabled/dir.conf sudo service apache2 restart
#!/bin/bash -e
 
sudo apt-get update
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password password 123456'
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password 123456'
sudo apt-get -y install mysql-server
 
sudo sed -i.bak "s/bind-address/#bind-address/g" /etc/mysql/my.cnf
sudo service mysql restart
 
Q1="CREATE DATABASE wordpress;"
Q2="CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'password';"
Q3="CREATE USER 'wordpressuser'@'%' IDENTIFIED BY 'password';"
Q4="GRANT ALL ON *.* TO 'wordpressuser'@'localhost';"
Q5="GRANT ALL ON *.* TO 'wordpressuser'@'%';"
SQL="${Q1}${Q2}${Q3}${Q4}${Q5}"
 
mysql -h localhost -uroot -p123456 -e "${SQL}"
#!/bin/bash
 
set -e
 
function download() {
 
 url=$1
 name=$2
 
 if [ -f "`pwd`/${name}" ]; then
 ctx logger info "`pwd`/${name} already exists, No need to download"
 else
 # download to given directory
 ctx logger info "Downloading ${url} to `pwd`/${name}"
 
 set +e
 curl_cmd=$(which curl)
 wget_cmd=$(which wget)
 set -e
 
 if [[ ! -z ${curl_cmd} ]]; then
 curl -L -o ${name} ${url}
 elif [[ ! -z ${wget_cmd} ]]; then
 wget -O ${name} ${url}
 else
 ctx logger error "Failed to download ${url}: Neither 'cURL' nor 'wget' were found on the system"
 exit 1;
 fi
 fi
 
}
 
 
function untar() {
 
 tar_archive=$1
 destination=$2
 
 if [ ! -d ${destination} ]; then
 inner_name=$(tar -tf "${tar_archive}" | grep -o '^[^/]\+' | sort -u)
 ctx logger info "Untaring ${tar_archive}"
 tar -zxvf ${tar_archive}
 
 ctx logger info "Moving ${inner_name} to ${destination}"
 mv ${inner_name} ${destination}
 fi
}
 
TEMP_DIR='/tmp'
WORDPRESS_TARBALL_NAME='latest.tar.gz'
 
WORDPRESS_ROOT_PATH=${TEMP_DIR}/$(ctx execution-id)/wordpress
WORDPRESS_PATH=~/wordpress
mkdir -p ${WORDPRESS_ROOT_PATH}
 
cd ${TEMP_DIR}
download http://wordpress.org/${WORDPRESS_TARBALL_NAME} ${WORDPRESS_TARBALL_NAME}
untar ${WORDPRESS_TARBALL_NAME} ${WORDPRESS_PATH}
 
cp ~/wordpress/wp-config-sample.php ~/wordpress/wp-config.php
sudo rsync -avP ~/wordpress/ /var/www/html/
cd /var/www/html
sudo chown -R www-data:www-data *
 
sudo mkdir /var/www/html/wp-content/uploads
sudo chown -R www-data:www-data /var/www/html/wp-content/uploads
 
export MONGO_HOST=$(ctx instance runtime_properties mysql_ip_address)
 
#replace default database setting with your setting
sed -i.bak "s/define('DB_HOST', 'localhost');/define('DB_HOST', '${MYSQL_HOST}');/g" /var/www/html/wp-config.php
sed -i.bak "s/database_name_here/wordpress/g" /var/www/html/wp-config.php
sed -i.bak "s/username_here/wordpressuser/g" /var/www/html/wp-config.php
sed -i.bak "s/password_here/password/g" /var/www/html/wp-config.php
#!/bin/bash -e cd ~/wordpress sudo rsync -avP ~/wordpress/ /var/www/html/ cd /var/www/html sudo chown -R www-data:www-data * sudo mkdir /var/www/html/wp-content/uploads sudo chown -R www-data:www-data /var/www/html/wp-content/uploads
When you want to uninstall your deployment but it’s not possible because there is a running task. Use the following commands:
# to see all events $ cfy executions list -d wordpress # cancel the event $ cfy executions cancel -e YOUR_EVENT_ID
After that, you can uninstall your deployment and remove your deployment and blueprint:
cfy executions start -w uninstall -d wordpress --force cfy deployments delete -d wordpress cfy blueprints delete -b wordpress