How to Host and Scale Your WordPress Site with Azure Cloud?

Sunil Nagar
9 min readOct 11, 2023

Leveraging Azure Cloud for Your WordPress Site: A Step-by-Step Guide — 2023

About WordPress:

WordPress, an influential content management system (CMS), powers over 40% of the internet. This versatile platform is the foundation of countless websites, blogs, and applications. When it comes to hosting WordPress, Microsoft’s Azure Cloud offers a range of services that can efficiently cater to your needs.

These services include:

  1. Azure App Service
  2. Virtual Machines (VMs)
  3. Azure Kubernetes Service (AKS)

Azure App Service emerges as the most straightforward option for deploying WordPress, especially for those seeking simplicity and speed. With its intuitive interface and robust infrastructure, Azure App Service allows you to launch and configure your WordPress website within minutes, eliminating complex setup procedures.

(a) How to Host a WordPress Site in Azure Cloud Using Azure App Service?

How to Host a WordPress Site in Azure Cloud Using Azure App Service?

Step 1: Create an Azure account

If you don’t already have one, you need to create a Microsoft Azure account. You can sign up at the Azure website. Microsoft offers a 30-day free trial with $200 credit.

Step 2: Create a new Web App

  1. Log in to the Azure portal.
  2. Click on “+ Create a resource” button on the top left of the Azure portal.
  1. In the “New” window, search for “WordPress”.
  2. In the search results, select “WordPress” offered by WordPress. (WordPress on App Service)
  3. Click the “Create” button to start the creation process.

Step 3: Configure your Web App

Here are several options you’ll encounter while configuring your resource:

1. App name: Assign an internal name for easy identification of this WordPress installation.
2. Subscription: Keep this as the default setting.
3. Resource Group: This will automatically populate based on your App name.
4. Database Provider: Retain the default selection — Azure Database for MySQL.
5. App Service plan/Location: Click to select the data center that’s geographically closest to your WordPress site’s primary audience.
6. Database: Click to input the database credentials. Ensure you remember these credentials as they’re essential for direct database access in the future.
7. Application Insights: Maintain this as the default setting.

Step 4: Database Configuration

  1. Under “Database Provider”, select “Azure Database for MySQL” as it is the recommended option for better scalability and flexibility.
  2. For “App Service plan/Location”, either create a new one or use an existing one. This is where you define the location and scale of your app.
  3. Click on “Pricing tier” to choose the capacity of your database. The pricing details will be displayed for each option.

Step 5: Application Settings

In the ‘Basics’ tab, under the ‘Project details’ section, ensure that the appropriate subscription is selected. Next, choose a resource group. If you don’t already have one, you can establish a new resource group by clicking on “Create new”. Input ‘wpdemo’ as the name and hit ‘OK’.

  1. In the “Application Insights” section, select your preferred settings.
  2. In the “Monitoring” section, you can enable Application Insights for monitoring your app. It’s optional but recommended for production apps.

Step 6: Review and Create

  1. After filling in all the details, click the “Review + create” button at the bottom of the page.
  2. Review your settings and click the “Create” button to start the deployment process.

Under Hosting details, type a globally unique name for your web app. App name: It should be unique and will be part of the domain name (app-name.azurewebsites.net) and for the name and select a Region you want to serve your app from for example East US

The deployment may take about 5–10 minutes.

Step 7: Setting Up WordPress

After a successful deployment, go to “Resource groups” located on the Azure portal sidebar. From the list of resource groups, select the one you’ve created for your WordPress site. Or, you can always search for your resource by name using the search box at the top of the Azure dashboard.

Setting Up WordPress

Step 8: Access Your WordPress Site

  1. Inside the resource group, click on your web app resource.
  2. On the overview page, you’ll find the URL of your website under the “URL” section. Click on the URL to open your website.
  3. You’ll see the familiar WordPress installation screen. Choose your language and click “Continue”.
  4. On the next screen, fill in the site title, username, password, and email for your new WordPress website.
Access Your WordPress Site

Step 9: Install WordPress

  1. Click on “Install WordPress” after filling in your details.
  2. Once the installation is complete, you’ll be redirected to the login page.
  3. Enter your username and password, then click “Log In”.

To access the WordPress Admin page, browse to app-name.azurewebsites.net/wp-admin

Use the credentials you created in the WordPress settings step and login

Congratulations! You’ve successfully hosted your WordPress site on Azure Cloud. You can now start building your website using the WordPress dashboard.

(b)How to Host a WordPress Site in Azure Cloud on virtual machines (VMs)?

Step 1: Create a new Virtual Machine

  1. Log in to the Azure portal.
  2. Click on “+ Create a resource” button on the top left of the Azure portal.
  3. In the “New” window, search for “Virtual Machine”.
  4. In the search results, select “Virtual Machine” and click “Create”.

Step 2: Configure your Virtual Machine

  1. Fill in the “Subscription”, “Resource group”, “Virtual machine name”, “Region”, “Availability options”, “Image” (choose a Linux distro), and “Size” (choose according to your needs).
  2. Under “Administrator account”, choose “Password” for authentication type, and:

— Provide a “Username” for the administrator account.

— Enter a strong “Password” and confirm it in the next field.

Step 4: Inbound Port Rules

  1. Under the “Inbound port rules” section, check the boxes for “HTTP” and “HTTPS”. This will open ports 80 and 443 for web traffic.

Step 5: Review and Create

  1. Review your settings and click the “Review + create” button at the bottom of the page.
  2. After Azure validates your settings, click the “Create” button to start the deployment process.

Step 6: Connect to VM and Install LAMP Stack

  1. Once the VM is deployed, connect to it using SSH.
  2. After connecting, install Apache, MySQL, and PHP to create a LAMP stack. You can use the following commands:
sudo apt update
sudo apt install apache2
sudo apt install mysql-server
sudo apt install php libapache2-mod-php php-mysql

Step 7: Configure MySQL and Install WordPress

  1. Secure MySQL by running the following command:
sudo mysql_secure_installation

This script will guide you through the process of securing your MySQL installation. It will prompt you to configure your security settings, including changing the root password, removing anonymous users, and disallowing remote root login.

2. Log in to MySQL:

sudo mysql -u root -p

Enter the password you set during the mysql_secure_installation process.

3. Flush privileges to ensure that the current instance of MySQL uses the recent privilege changes:

i. Use the following command to flush privileges:

FLUSH PRIVILEGES;

ii. Exit the MySQL console by typing:

EXIT;

Step 8: Download and Set Up WordPress

Download the latest WordPress package and extract it:

wget https://wordpress.org/latest.tar.gz
tar -xvzf latest.tar.gz

Move the extracted files to the Apache web root directory:

sudo cp -R wordpress

Move the extracted files to the Apache web root directory:

  1. Use the following command to move the WordPress files:
sudo cp -R wordpress/* /var/www/html/

2. Adjust the permissions of the WordPress directory to allow the web server to write data into it:

sudo chown -R www-data:www-data /var/www/html/ sudo chmod -R 755 /var/www/html/

Step 9: Configure WordPress

  1. Navigate to the web root directory and rename the existing wp-config-sample.php file to wp-config.php:
cd /var/www/html/ sudo mv wp-config-sample.php wp-config.php

2. Open the wp-config.php file and fill in your database details (database name, username, and password) that you created earlier:

sudo nano wp-config.php

3. Save and close the file.

Step 10: Finalize WordPress Installation

Open a web browser and navigate to your public IP address. You should see the WordPress installation page.

Follow the steps below to finalize the installation:

  1. Choose your language and click “Continue”.
  2. On the next screen, fill in the site title, username, password, and email for your new WordPress website.
  3. Click on “Install WordPress” after filling in your details.
  4. Once the installation is complete, you’ll be redirected to the login page.
  5. Enter your username and password, then click “Log In”.

Congratulations! You’ve successfully hosted your WordPress site on Azure Virtual Machine. You can now start building your website using the WordPress dashboard.

How to Deploy WordPress app on AKS (Azure Kubernetes Service)with Azure Database for MySQL?

How to Deploy WordPress app on AKS with Azure Database for MySQL?
  1. Use the Bash environment in Azure Cloud Shell.
  2. Create a MySQL server with MySQL version 8.0 in your resource group.
  3. Provide a server admin login and a strong password.
  4. Create a firewall rule to allow all Azure-internal IP addresses to access your Server.
  5. Create the following YAML files and submit them to Kubernetes through kubectl:
  • mysql-deployment.yaml
  • wordpress-deployment.yaml

6. Verify that both MySQL and WordPress pods are up and running

Step 1: Create an Azure Account

Register for a Microsoft Azure account at the Azure website.

Step 2: Set Up Azure Database for MySQL

  1. Log in to the Azure portal.
  2. Click “+ Create a resource”, search for “Azure Database for MySQL”, and click “Create”.
  3. Fill in the details for your new database (resource group, name, server admin login name, password, location, MySQL version, and compute + storage configuration).
  4. Click “Review + create” and then “Create” to deploy your MySQL database.

Step 3: Create an Azure Kubernetes Service (AKS) Cluster

  1. In the Azure portal, click “+ Create a resource”, search for “Kubernetes Service”, and click “Create”.
  2. Fill in the details for your AKS cluster (resource group, cluster name, region, version, node size, and node count).
  3. Click “Review + create” and then “Create” to deploy your AKS cluster.

Step 4: Deploy WordPress on AKS

  1. Connect to your AKS cluster using Azure Cloud Shell or local terminal with Azure CLI installed.
  2. Use Helm, the package manager for Kubernetes, to deploy WordPress. You’ll need to provide the connection details for your Azure Database for MySQL.

Step 5: Install Helm

Helm is a package manager for Kubernetes that allows you to install and manage applications on your Kubernetes cluster. Install Helm on your local machine or Azure Cloud Shell.

Step 6: Add the Bitnami Helm repository

Bitnami provides a Helm chart to deploy WordPress on a Kubernetes cluster. Add the Bitnami repository to your Helm instance with the following command:

helm repo add bitnami https://charts.bitnami.com/bitnami

Step 7: Deploy WordPress

Now you’re ready to deploy WordPress. Replace the placeholders in the following command with your Azure Database for MySQL details:

helm install wordpress bitnami/wordpress \
--set wordpressUsername=admin \
--set wordpressPassword=password \
--set mariadb.enabled=false \
--set externalDatabase.host=YOUR_DATABASE_HOST \
--set externalDatabase.user=YOUR_DATABASE_USER \
--set externalDatabase.password=YOUR_DATABASE_PASSWORD \
--set externalDatabase.database=YOUR_DATABASE_NAME \
--set service.type=LoadBalancer

In the above command, replace YOUR_DATABASE_HOST, YOUR_DATABASE_USER, YOUR_DATABASE_PASSWORD, and YOUR_DATABASE_NAME with your Azure Database for MySQL details.

Step 8: Access WordPress

After deploying WordPress, it may take a few minutes for the LoadBalancer IP to become available. You can check the status with the following command:

kubectl get svc --namespace default | grep wordpress

Once the EXTERNAL-IP for WordPress is available, you can open it in a web browser and complete the WordPress installation.

Conclusion:

Microsoft Azure provides a versatile and robust platform for hosting WordPress websites. Whether you choose Azure Web Apps for a fully managed platform, Azure Virtual Machines for more control and customization, or Azure Kubernetes Service for containerized applications, Azure caters to a wide range of hosting needs.

Each method has its own strengths. Azure Web Apps is a quick and hassle-free way to deploy WordPress for those who prefer a managed solution. Azure Virtual Machines offer more control over the hosting environment, and Azure Kubernetes Service is perfect for those who are looking at a containerized approach.

The choice between these methods depends on your specific requirements, technical expertise, and the scale of your operations

--

--

Sunil Nagar

Blogger: #Artificial Intelligence #data #chatbot #Automation #UI #frontend #CMS #WordPress #Web Development #business analyst #Product Develpoment