Installing WordPress

You now have the PaaS infrastructure to support a high-available instance of WordPress. Let’s go ahead and install WordPress onto our App Service.

One of the benefits of using the Linux App Service is that most of the system prerequisites, including the basic PHP libraries, are already available to us.  Additionally, apache has already been configured.  Unless we are using some obscure WordPress plugins, you won’t need to rebuild PHP and we can leverage what has already been supplied to us by the Azure team.

Connect to the Remote Terminal

Most of the next steps are accomplished through the remote terminal (SSH) of our Web App.

  1. Navigate to your Web App (App Service) blade.
  2. 3/4 of the way down on the left menu of the blade, you’ll see SSH.  Click on it.
  3. In the SSH blade, you’ll see a link that reads Go.  The current version of the WebSSH client has some issues with browsers in standard mode.  If you are using Edge, right-click on the link and select Open in new InPrivate window.  If you are using Chrome, right-click on the link and select Open link in incognito window.

Download WordPress

Change into a temporary directory and then download the compressed release:

Extract the compress file to create the WordPress directory structure:

We will move these files over to the main web site root folder in a bit.  But, before we do, let’s add an .htaccess file and set it’s permissions.

Using the .htaccess, we can override some of PHP’s default environment variables so that our WordPress instance’s performance is optimized.

Using vim open up the .htaccess and add the following content (you may need to read up on how to use the editor):

Let’s copy over the sample configuration file to the filename that WordPress actually needs:

We’ll also make the upgrade directory so that WordPress doesn’t run into permissions issues when trying to do this on it’s own following an update to the software:

Now, we’re ready to copy our WordPress over to the working directory:

Finally, let’s delete Azure’s default landing page:

Configure the WordPress Directory Permissions

We will set the setgid bit on each of the directories within the document root.  This causes new files created within these directories to inherit the group of the parent directory instead of the creating user’s primary group.  This just makes sure that whenever we create a file in the directory on the command line, the web server will still have group ownership over it.

We can set the setgid on every directory in our installation by typing:

There are a few other fine-grained permissions we’ll adjust.  First, we’ll give group write access to the wp-content directory so that the web interface can make theme and plugin changes:

As part of this process, we will give the web server write access to all of the content in these two directories:

This should be sufficient right now.  Some plugins and/or procedures made need some additional tweaks.

Configuring WordPress

We’ll now need to make some changes to the main WordPress configuration file.

We we open the file, we’ll first need to add some secret keys in order to protect our installation.  WordPress provides a secure generator for these values so that you do not have to try to come up with good ones on your own.  These are only used internally, so the more complex, the safe you are.

To grab secure values from the WordPress secret key generator, type:

You will get back unique values that look something like this (Warning: Do not copy mine below. Copy the values from your terminal.)

Again, copy these (highlight, right-click and copy) so that you can paste them into the WordPress configuration file.

Now, let’s edit the configuration file using vim.

Find the section that contains the dummy values for those settings above.  It will look something like this:

Delete those lines and paste in the values you copied from the command line.

The other settings in this file reflect what we configured for our database and App Service in Azure.  Find the appropriate settings and update accordingly.  The settings for my particular database and App Service are reflected below.  Your’s will be different.

Finally, find the line define('WP_DEBUG', false);.  After this line, add the following two lines:

These two lines will allow WordPress to write to the filesystem directly as it needs and increases the allocation for WordPress memory consumption, respectively.

Save and close the file when you are finished.

Complete Installation

Now that the server configuration is complete, we can complete the installation through the web interface.

In your web browser, navigate to your Web App (your’s will be different than mine):

Select the language you would like to use:

Next, you will come to the main setup page.

Select a name for your WordPress site and choose a username (don’t choose something like “admin” for security purposes). A strong password is generated automatically, but you can choose your own.  Enter your email address and select whether you want to discourage search engines from indexing your site:

When you click Install WordPress, you will be taken to a page that prompts you to log in:

Once you log in, you will be taken to the WordPress administration dashboard:

Configure Mail

By default, WordPress attempts to use the built-in PHP mail libraries for sending email.  However, Azure does not allow the ability to send mail from its environments in order to prevent SPAM.  Instead, Azure requires you to use a third-party SMTP relay server – either your’s or a provider.

For my SMTP relay scenarios, I use SendGrid.  Luckily, I’m grandfathered into SendGrid’s free tier.  However, SendGrid does have some cheap options for sending emails.  Feel free to use whichever provider you are most comfortable with.  For this demo, I show you how to incorporate SendGrid.

  1. From within your WordPress administration portal (login if you’ve not yet done so), click on Plugins in the left menu.
  2. You’ll see a list of default plugins.  It is recommended that you activate Akismet Anti-Spam to cut down on the amount of SPAM comments in your blog (you will need to setup a free Akismet account, but it’s self explanatory).  You can safely delete the Hello Dolly plugin.
  3. At the top, next the the Plugins title, click Add New.
  4. In the left portion of the screen, there’s a search box.  Search for WP Mail SMTP.
  5. You should see the plugin returned as the first option, click Install Now.
  6. Once installed, the same button you just clicked, will turn blue and read Activate.  Click it.
  7. You will be returned to the plugins page.  Under WP Mail SMTP, click Settings.
  8. Now, you’ll be able to configure your SMTP relay server.  Notice that the default is, again, PHP.  You’ll need to change it to one of the other options, including a custom SMTP relay server, should you have the appropriate settings.
  9. Once configured, click Save Settings.
  10. If you’d like to test your configuration, feel free to click the Email Test menu item at the top of this page.