Use Azure MySQL as the backend for KUSANAGI

Azure

KUSANAGI is a popular open-source software (OSS) as a WordPress accelerator. It is also available for deployment from the Azure Marketplace, allowing you to easily build a fast WordPress environment.

On the other hand, the Marketplace image sets up WordPress along with nginx/apache and MariaDB on a single virtual machine, which means the web server and database cannot be scaled independently according to their respective loads.

Therefore, let’s try using Azure Database for MySQL Flexible Server instead of MariaDB.

Deployment of KUSANAGI

It should not be particularly difficult. From the Azure portal, point to [Create a resource].

When you enter ‘KUSANAGI’ in the search field, a list of suggestions will appear.

Since this is for evaluation purposes, we will select the OSS version of KUSANAGI.

If you intend to use it as a production server, you should select an edition supported by Prime Strategy, the main developer of KUSANAGI. At the time of writing, the following editions are available according to the features of KUSANAGI.

  • KUSANAGI 9 for Microsoft Azure Business Edition
  • KUSANAGI 9 for Microsoft Azure Premium Edition
  • KUSANAGI Security Edition for Microsoft Azure

After that, create a VM as usual.

Once the deployment is complete, configure a DNS name for the VM using its IP address.

Deployment of Azure Database for MySQL Flexible Server

Add MySQL to the resource group where KUSANAGI was created. From the Marketplace, select [Databases] → [Azure Database for MySQL Flexible Server].

Select [Quick Create] for ‘Flexible Server’. The option to run WordPress on Azure App Service is covered in a separate blog post.

Once the MySQL deployment is complete, go to ‘Networking’ in MySQL and enable [Allow public access from any…]. For production servers, consider using VNET integration or similar options.

Configuration of KUSANAGI

Log in to the KUSANAGI VM via SSH and update the RPM packages.

dnf -y update

Next, initialize KUSANAGI.

kusanagi init --passwd PASSWORD --dbrootpass DB_PASSWORD --nophrase

Then, provision KUSANAGI.

kusanagi provision --wp --wplang ja --dbuser DB_USER --dbpass DB_PASS --dbname kusanagi-wp --fqdn your_host.japaneast.cloudapp.azure.com --email EMAIL --title 'first blog' --adminuser admin --adminpass ADMIN_PASS --adminemail ADMIN_EMAIL kusanagi1

You can check the meaning of each argument with the following command.

kusanagi provision --help

For the fqdn argument, specify the DNS name assigned to the KUSANAGI VM. In addition, the positional argument ‘kusanagi1’ is specified, which serves as the profile name for KUSANAGI.

Switch from MariaDB to MySQL

Once the WordPress provisioning is complete, /home/kusanagi/profile_name/wp-config.php will be generated. Change its permissions and open it in an editor.

chmod 755 /home/kusanagi/kusanagi1/wp-config.php

Verify that the DB account and password specified during provisioning are set, and then update/add the following two items.

  • Change DB_HOST from ‘localhost’ to the FQDN of the Azure Database for MySQL Flexible Server.
  • Add define(‘MYSQL_CLIENT_FLAGS’, MYSQLI_CLIENT_SSL);

Since Azure Database for MySQL Flexible Server requires SSL/TLS connections, it is necessary to add the corresponding constants. After finishing the edits, restore the permissions to their original state.

chmod 440 /home/kusanagi/kusanagi1/wp-config.php

Access to WordPress

When you access the FQDN of the KUSANAGI VM in a web browser, the WordPress initial setup dialog will appear. Authentication will use the account ‘kusanagi’ and the password specified during the kusanagi provision execution. From there, you can create your first blog. After that, it should work just like a regular WordPress installation.