Step 5: Update and redeploy your WordPress application - Amazon CodeDeploy
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Step 5: Update and redeploy your WordPress application

Now that you've successfully deployed your application revision, update the WordPress code on the development machine, and then use CodeDeploy to redeploy the site. Afterward, you should see the code changes on the Amazon EC2 instance.

Set up the WordPress site

To see the effects of the code change, finish setting up the WordPress site so that you have a fully functional installation.

  1. Type your site's URL into your web browser. The URL is the public DNS address of the Amazon EC2 instance plus a /WordPress extension. For this example WordPress site (and example Amazon EC2 instance public DNS address), the URL is http://ec2-01-234-567-890.compute-1.amazonaws.com/WordPress.

  2. If you haven't set up the site yet, the WordPress default welcome page appears. Choose Let's go!.

  3. To use the default MySQL database, on the database configuration page, type the following values:

    • Database Name: test

    • User Name: root

    • Password: Leave blank.

    • Database Host: localhost

    • Table Prefix: wp_

    Choose Submit to set up the database.

  4. Continue the site setup. On the Welcome page, fill in any values you want, and choose Install WordPress. When the installation is complete, you can sign in to your dashboard.

Important

During the deployment of the WordPress application, the change_permissions.sh script updated permissions of the /tmp/WordPress folder so anyone can write to it. Now is a good time to run the following command to restrict permissions so that only you, the owner, can write to it:

chmod -R 755 /var/www/html/WordPress

Modify the site

To modify the WordPress site, go to the application's folder on your development machine:

cd /tmp/WordPress

To modify some of the site's colors, in the wp-content/themes/twentyfifteen/style.css file, use a text editor or sed to change #fff to #768331.

On Linux or other systems with GNU sed, use:

sed -i 's/#fff/#768331/g' wp-content/themes/twentyfifteen/style.css

On macOS, Unix, or other systems with BSD sed, use:

sed -i '' 's/#fff/#768331/g' wp-content/themes/twentyfifteen/style.css

Redeploy the site

Now that you've modified the site's code, use Amazon S3 and CodeDeploy to redeploy the site.

Bundle and upload the changes to Amazon S3, as described in Bundle the application's files into a single archive file and push the archive file. (As you follow those instructions, remember that you do not need to create an application.) Give the new revision the same key as before (WordPressApp.zip). Upload it to the same Amazon S3 bucket you created earlier (for example, codedeploydemobucket).

Use the Amazon CLI, the CodeDeploy console, or the CodeDeploy APIs to redeploy the site.

To redeploy the site (CLI)

Call the create-deployment command to create a deployment based on the newly uploaded revision. Use the application named WordPress_App, the deployment configuration named CodeDeployDefault.OneAtATime, the deployment group named WordPress_DepGroup, and the revision named WordPressApp.zip in the bucket named codedeploydemobucket:

aws deploy create-deployment \ --application-name WordPress_App \ --deployment-config-name CodeDeployDefault.OneAtATime \ --deployment-group-name WordPress_DepGroup \ --s3-location bucket=codedeploydemobucket,bundleType=zip,key=WordPressApp.zip

You can check the status of the deployment, as described in Monitor and troubleshoot your deployment.

After CodeDeploy has redeployed the site, revisit the site in your web browser to verify the colors have been changed. (You might need to refresh your browser.) If the colors have been changed, congratulations! You have successfully modified and redeployed your site!

To redeploy the site (console)

  1. Sign in to the Amazon Web Services Management Console and open the CodeDeploy console at https://console.amazonaws.cn/codedeploy.

    Note

    Sign in with the same user that you set up in Getting started with CodeDeploy.

  2. In the navigation pane, expand Deploy, then choose Applications.

  3. In the list of applications, choose WordPress_App.

  4. On the Deployment groups tab, choose WordPress_DepGroup.

  5. Choose Create deployment.

  6. On the Create deployment page:

    1. In Deployment group, choose WordPress_DepGroup.

    2. In the Repository type area, choose My application is stored in Amazon S3, and then copy your revision's Amazon S3 link into the Revision location box. To find the link value:

      1. In a separate browser tab:

        Sign in to the Amazon Web Services Management Console and open the Amazon S3 console at https://console.amazonaws.cn/s3/.

        Browse to and open codedeploydemobucket, and then choose your revision, WordPressApp.zip.

      2. If the Properties pane is not visible in the Amazon S3 console, choose the Properties button.

      3. In the Properties pane, copy the value of the Link field into the Revision location box in the CodeDeploy console.

    3. If a message appears saying the file type could not be detected, choose .zip.

    4. Leave the Deployment description box blank.

    5. Expand Deployment group overrides and from Deployment configuration, choose CodeDeployDefault.OneAtATime.

    6. Choose Start deployment. Information about your newly created deployment appears on the Deployments page.

    7. You can check the status of the deployment, as described in Monitor and troubleshoot your deployment.

      After CodeDeploy has redeployed the site, revisit the site in your web browser to verify the colors have been changed. (You might need to refresh your browser.) If the colors have been changed, congratulations! You have successfully modified and redeployed your site!