WordCamp 2018

My talk at the WordCamp conference was about practical experiences from deploying WordPress to Azure and tips/tricks for better operations.
February 23, 2018

Slides

Slides can be downloaded from my OneDrive.

Demos

Fast start:

  1. WordPress deployment template in Azure Marketplace.
  2. Automatically creates hosted MySQL database.
  3. Allows changing the PHP version and other hosting properties quickly.

Docker for development:

  1. Docker for Windows in Azure virtual machine with Windows Server 2016.
  2. docker-compose.yml -> deploy mysql & wordpress:latest container.
  3. Changes happen in the html folder and immediately show up on the site.

Git deployment:

  1. New Azure Web App with new Staging Deployment Slot.

  2. Deployment set to come from Local Git Repository.

  3. WordPress added to Git

    1. git init
    2. git remote add azure https://…. (Git deployment URL for the staging slot).
    3. git add .
    4. git commit -m “Initial commmit”
    5. git push –set-upstream azure master
  4. Doesn’t connect to database yet.

  5. Modified wp-config.php for Azure:

    // ** MySQL settings - You can get this info from your web host ** //
    
    foreach ($_SERVER as $key => $value) {
        if (strpos($key, "MYSQLCONNSTR_") !== 0) {
            continue;
        }
    
        $connectstr_dbhost = preg_replace("/^.*Data Source=(.+?);.*$/", "\\1", $value);
        $connectstr_dbname = preg_replace("/^.*Database=(.+?);.*$/", "\\1", $value);
        $connectstr_dbusername = preg_replace("/^.*User Id=(.+?);.*$/", "\\1", $value);
        $connectstr_dbpassword = preg_replace("/^.*Password=(.+?)$/", "\\1", $value);
    }
    
    /** The name of the database for WordPress */
    define('DB_NAME', $connectstr_dbname);
    
    /** MySQL database username */
    define('DB_USER', $connectstr_dbusername);
    
    /** MySQL database password */
    define('DB_PASSWORD', $connectstr_dbpassword);
    
    /** MySQL hostname */
    define('DB_HOST', $connectstr_dbhost);
    
    /** Database Charset to use in creating database tables. */
    define('DB_CHARSET', 'utf8');
    
    /** The Database Collate type. Don't change this if in doubt. */
    define('DB_COLLATE', '');
    
  6. Added custom deployment script:

    • .deployment file:

      [config]
      command = deploy.cmd
      
    • deploy.cmd file (added) - how to get the whole file is described in the docs:

      ...
    
      echo Moving configs...
      move /Y %DEPLOYMENT_TARGET%\wp-config.php %DEPLOYMENT_TARGET%\wp-config.php.local
      move /Y %DEPLOYMENT_TARGET%\wp-config-azure.php %DEPLOYMENT_TARGET%\wp-config.php
    
      ...
    
  7. git add . -> git commit -m “Deployment” -> git push

  8. Added connection string to slot’s Application Settings.

  9. Finally, swapped to production.

Operations tips

comments powered by Disqus