WordPress Troubleshooting Techniques on Azure Websites

WordPress is one of the popular Web Applications that is offered with Azure Websites Gallery to build dynamic websites. You may run into some issues with your WordPress websites and might want to troubleshoot them. In this post, we will review some common issues and discuss the best techniques to resolve them.

How do I update PHP INI configuration for my WordPress site?

Your WordPress site may require specific changes to PHP.INI based on requirements for your application such as allowing users to upload a file up to 12 MB which is higher than the default limit 8MB .

You can enable a user-defined PHP configuration, by creating a file called .user.ini at the site root (D:\home\site\wwwroot folder) and add the following:

upload_max_filesize = 12M

 

Now, restart your website. To verify if your changes were overwritten, create a PHP file called phpinfo.php with the following text and save it in the site root folder.

<?php phpinfo(); ?>

 

Next, browse this file and search for upload_max_size:

phpinfo

My Media content (uploads folder) is 10GB in size and my Web Application is 1GB in size. Which Tier will give me ample storage ?

The Storage supported for Shared is 1 GB, Basic is 10GB and Standard is 50GB. If you want to make the most of your website storage , you can move all of your media content into the uploads folder to Azure Storage (which costs $0.048 per GB) and use an Azure Storage plugin to manage media content in your WordPress site. This allows you to isolate your media content from your Web Application.

You can also create an Azure CDN endpoint for the Azure Storage account you used to serve your media content. In the plugin settings page, you’ll see a CNAME property setting. This is where you will need to enter the Azure CDN name for example http://az628210.vo.msecnd.net/.

How to setup SSL for my WordPress site

Only Standard and Basic Tiers offer SSL support. To add SSL support to your website :

  • <a href=”http://azure.microsoft.com/en-us/documentation/articles/web-sites-configure-ssl-certificate”>Configure SSL support for Azure Website
  • Update WordPress to use SSL

Can I use mod-rewrite on Azure Websites?

Azure Websites use the IIS web server and hence does not work with mod_rewrite which is an Apache module. Url Rewrite module is enabled by default on Azure websites and you can create your rewrite or redirect rules using a web.config.

Open the Web.config file located at the site root (D:\home\site\wwwroot). If you do not have a Web.config file in the directory, create it.

Copy and paste the following XML section into the system.webServer element:

<rewrite>
<rules>
<rule name="Main Rule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>

This rule matches any requested URL; if the URL does not correspond to a file or a folder on a file system, then the rule rewrites the URL to Index.php and determines which content to serve based on the REQUEST_URI server variable that contains the original URL before it was modified by the rule.

To learn more about creating URL rewrite rules ,see 10 URL rewriting Tips and Tricks

How to resolve 404.3 “Mime Type missing” errors when dependent requests on .woff files ?

.woff extension is not enabled by default on Azure Websites. If you are using WordPress or any application that uses .woff files, include a web.config file at the site root folder and add the following under <system.webServer> section:

<configuration>
<system.webServer>
<staticContent>
   <mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />     </staticContent>
</system.webServer>
</configuration>

Now, restart your website.

How to resolve slow page load time for WordPress site running on Azure ?

If your WordPress site is slow then check for these:

  • Are you running on Free Tier?

If yes, then Free tier is not sufficient for running a production site and hence you need to upgrade to Shared, Basic or Standard Tier. Check out the features supported for each tier and select the appropriate Tier, Azure Websites Pricing per tier.

  • Is your website and database in the same data center?

If your website is setup in say West US and your database is setup in say East US ; then this can impact performance of the website as both these components are in different datacenters and network latency for the database calls can add to your page load time. Make sure your website and database are in the same regions/data centers.

  • Are your using a Free ClearDB MySQL database?

The Free ClearDB MySQL database is not production website. Check out the ClearDB plans for Azure and How to purchase it from the Store.

How do I get diagnostics for PHP errors?

Websites allows you to turn on Webserver diagnostics such as Web Server logging, Detailed Error messages and Failed Request Tracing. To learn more about getting error information, see PHP diagnostics for Azure Websites

Our new Diagnostics as a Service (DaaS for short), attempts to interpret these logs in a way that it either helps me resolve the issue or provides prescriptive guidance. To learn more, DaaS – Diagnostics as a Service for Azure Web Sites

How to enable advanced WordPress Debugging?

WordPress provides various options to debug your WordPress site. WordPress uses a constant WP_DEBUG to turn ON debugging for your WordPress site. By default it is turned OFF in wp-config.php file

define('WP_DEBUG', false);

To enable it, you need to set it to TRUE

define('WP_DEBUG', true);

Note that debugging should be turned be turned OFF after debugging an issue. For more advanced options for debugging WordPress, see Debugging in WordPress.

How do I enable Email service with my WordPress site?

Azure Websites does not support Email/SMTP and hence you would need to purchase SendGrid from the Azure Store. SendGrid offers a Free plan (up to 25,000 emails per month) which might be sufficient for your WordPress site. You can learn about SendGrid Plans for Azure here if the Free plan does not meet your needs.

To learn more, How to Use SendGrid Email Service.

How do I backup and restore my WordPress site?

Azure Websites offers automatic Backup and Restore feature. To learn more check out How to back up your Azure Website and How to restore your Azure Website.

Can I edit my WordPress site online?

Websites comes with an online editor with the goodness of Visual Studio. To learn more, see Edit Azure Website online with Monaco.

How to Fix the Error Establishing a Database Connection in WordPress?

You get this error when WordPress is unable to establish a database connection. The following reasons could be the reason why the issue occurs:

  • Database information in wp-config.php file may be incorrect

Use MySQL Client to access your database with the information in wp-config.php to verify this.

  • Check if both the front end and back end of your WordPress site are returning the different errors

If you are getting a different error on the wp-admin page for instance something like “One or more database tables are unavailable. The database may need to be repaired”, then you need to repair your database. To do this add the following wp-config.php file:

define('WP_ALLOW_REPAIR', true);

Once you have done that, you can see the settings by visiting this page: http://www.yoursite.com/wp-admin/maint/repair.php

The user does not need to be logged in to access this functionality when this define is set. This is because its main intent is to repair a corrupted database, Users can often not login when the database is corrupt. So once you are done repairing and optimizing your database, make sure to remove this from your wp-config.php.

  • wp-config.php file may be corrupted

Retouch wp-config.php file so that the last modified time stamp for the file is changed.

  • If this error occurs intermittently when your site is on high user load

Use Persistent connections with WordPress by editing wp-includes/wp-db.php file as shown below:

For WordPress with PHP version <=5.4

//remove line 1147
//$this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags );
//Add the line below

$this->dbh = mysql_pconnect( $this->dbhost, $this->dbuser, $this->dbpassword,  $client_flags );
if ( false !== $error_reporting ) {
error_reporting( $error_reporting );
}
} else {
//remove line 1152
//$this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags );
//Add the line below
$this->dbh = @mysql_pconnect( $this->dbhost, $this->dbuser, $this->dbpassword,  $client_flags );
}

For WordPress 3.9.1 with PHP >=5.5

//Line 1378
if ( WP_DEBUG ) {
     //Add prefix 'p:' to $host
     mysqli_real_connect( $this->dbh, 'p:'.$host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags );
              }
      else {
      //Add prefix 'p:' to $host
     @mysqli_real_connect( $this->dbh, 'p:'.$host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags );
            }

Note that if WordPress Automatic are ON, this file can be overwritten and your changes can be lost. I would recommend to use a WebJob that can watch if the file was modified and make these changes if they don’t exist in wp-db.php file. You can download the Web Job from here if your WordPress is using PHP version < 5.5 , if you are using PHP 5.5 you can download the WebJob from here.

  • Check if your Website Service is able to connect to the database

To verify if you can connect to the database, create a new file called testdbconnection.php and paste the following code in it:

<?php
//Modify the hostname, user, password for mysql_connect with the your
//database connection information
$link = mysql_connect('localhost', 'username', 'password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>

Run this page in the browser .If you see “Connected successfully” message than Website service can connect to the database. If you see “Could not connect” message than read the MySQL error to identify the cause of the issue. Contact Azure Support if you still see “Could not connect” message and unable to resolve it.

How to resolve the error “1203 SQLSTATE: 42000 (ER_TOO_MANY_USER_CONNECTIONS)”?

This depends on what MySQL server you are using .

  • If you are using ClearDB MySQL database, it has limitations on max_user_connections for the database based on the database plan you are using. Check out the details here. When you hit the limit you will run into this error, so to resolve this upgrade your database plan.
  • If you are using MySQL Azure VM to host your database for your WordPress site, then edit my.ini (on Windows Machine) or my.cnf (Linux Machine) configuration
max_connections = 250

Setting the max_connections too high will cause MySQL server to crash with an “Out of memory” error. Choose this value carefully depending on the RAM for your MySQL server VM.

How do I resolve a White Screen/Blank page?

If you see a White Screen or a blank page when you access your website, the cause could either be plugin or theme related issue. Try to isolate the theme or plugin causing this issue. Check out the step by step guide here.

How do I resolve a Memory Size Exhausted error ?

The default limit is 128MB. You can increase the Memory limit either using:

  • by adding this to wp-config.php:
    define('WP_MEMORY_LIMIT', '128M');
  • by adding .user.ini at the site root (D:\home\site\wwwroot) with:
    memory_limit=256M

    Restart your websites.

 

I want to share feedback on a feature or documentation for Azure Websites

You can share your feedback about additional/missing documentation or new/existing features with our engineering team on User voice

Related Links

WordPress Troubleshooting Guide
WordPress Support