In this part of our blog series on WordPress configuration and deployment with DevOps practices, we’ll focus on configuring Azure App Service as the hosting platform for your WordPress site. We’ll walk you through the necessary steps, including creating an Azure App Service Linux resource, deploying WordPress files, and configuring the Nginx server to ensure proper site loading.

Step 1: Creating an Azure App Service Linux Resource Link to heading

  1. Log in to the Azure Portal (portal.azure.com).

  2. Click on “Create a resource” and search for “App Service.”

  3. Select “Web App” from the available options and click “Create.”

  4. Provide the necessary details, including resource group, app name, subscription, and operating system. Choose Linux as the operating system.

  5. Configure additional settings, such as the app service plan, runtime stack, and region.

  6. Click “Review + Create” and then “Create” to create the Azure App Service Linux resource.

Step 2: Deploying WordPress Files Link to heading

Assuming you have already set up a CI/CD pipeline that deploys the WordPress files to the wwwroot folder of the app service, proceed with the following steps:

  1. Ensure that your CI/CD pipeline is configured to deploy the WordPress files to the wwwroot folder of the app service. This is typically the folder where the web server looks for files to serve.

  2. Set up your pipeline triggers to automatically deploy changes to the app service whenever new commits are made to the source control repository.

Step 3: Configuring Nginx for Proper Site Loading Link to heading

By default, the out-of-the-box configuration of Azure App Service for Linux with PHP might not load the WordPress site correctly. To address this, we need to modify the Nginx configuration file.

  1. SSH into the Azure App Service Linux resource. You can use tools like PuTTY or the Azure Cloud Shell.

  2. Navigate to the home directory by running the following command:

    cd /home
    
  3. Copy the Nginx configuration file from the original location to the home directory:

    cp /etc/nginx/sites-enabled/* .
    
  4. Open the copied configuration file using a text editor:

    nano <configuration_file_name>
    
  5. Inside the Nginx configuration file, update the root directory setting to point to the wwwroot folder where your WordPress files are deployed. For example:

    root /home/site/wwwroot;
    
  6. Specify the index files for the root path. Add or modify the index directive to include common WordPress index files, such as index.php, index.html, etc. For example:

    index index.php index.html index.htm;
    
  7. Save the changes to the configuration file.

  8. Create a startup command to copy the modified configuration file back to the original location (/etc/nginx/sites-enabled/) during server restarts. This ensures that the configuration changes persist.

    • Create a startup command script (e.g., startup.sh) in the home directory:

      nano startup.sh
      
    • Add the following command to the script:

      cp /home/<configuration_file_name> /etc/nginx/sites-enabled/
      
    • Save the file and make it executable:

      chmod +x startup.sh
      

Example Nginx Configuration File Link to heading

Here’s an example of an Nginx configuration file for hosting a WordPress site on Azure App Service:

server {
    listen 80;
    server_name yourdomain.com;

    root /home/site/wwwroot;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
}

Note: The provided configuration file is a basic example and might require additional adjustments based on your specific project requirements.

Once you’ve completed the above steps, your WordPress site should load successfully on the Azure App Service, albeit with a database connection error displayed on the page. We’ll cover the database configuration in the final part of this series.

Stay tuned for Part 4, where we’ll guide you through the process of setting up the Azure Database for MySQL and connecting it to your WordPress site.

Remember, these steps and configurations are provided as a starting point and may vary based on your specific needs and preferences. Always review and apply best practices for security, performance, and scalability to ensure a robust WordPress deployment on Azure App Service.