Category: PHP

How to use PHPMyadmin for your Azure Web App

Azure Web Apps provides an array of tools through the Site extension Gallery. One such tool is PHPMyadmin which allows you to access your database. Once you log on to the Azure Management portal, browse to your web app and view the application settings to link your MySQL database with your web app.

Add a connection string under Web App Settings as shown below.


Continue reading “How to use PHPMyadmin for your Azure Web App”

Enabling Azure App Insights Analytics to your Drupal web app

Enabling Azure App Insights Analytics to your Drupal web app

Drupal uses themes to change the look and feel of your web application. Microsoft Azure offers Visual Studio Application Insights service which allows you to get key application telemetry data out of the box, including usage and requests for PHP applications. In this blog post you will learn how to enable Application insights service in your Drupal web application.

Step1: Create an Application Insights service resource in Azure preview portal and get the JavaScript code to inject within your application. This code will allow Application insights service to track and monitor your application. To learn more, see How to get code to monitor your web pages

Continue reading “Enabling Azure App Insights Analytics to your Drupal web app”

Profiling PHP application on Azure Web Apps

Zend Z-Ray is a debugging/profiling solution offered by Zend technologies. Azure App service team has partnered with them to bring their solution into Azure App service helping developers build better PHP applications on our platform.

To enabled Zend Z-ray , you must have atleast one web application on Azure Web App service. Login to Azure management portal and select your web application.


Click on Settingsà Zend Z-ray

You may select the respective tier based on what type of web app you are using. For development purposes, you should use the FREE Sku and for production websites you should use STANDARD Sku.

For this blog post I am going to use STANDARD Sku . Once you select the Sku , you need to purchase the feature (Note that this feature is in preview mode and hence free to use until they are in preview mode. )

If you browse your website now, you will see a status bar for Z-ray that shows all information you need to debug your applications

Once the feature has been successfully enabled , click on Z-Ray Management dashboard to configure the profiler to show up in the browser status bar only if admin of the website and not your end users .

Use the secured mode to allow only admin/developer of your site to access the profile on your site

Click on the Tokens tab on the left side menu to create a new token

Specify the IP address restriction or URL based restriction for your website

To use the token, add the token URL as a GET parameter to the page URL. For example:<token-string&gt;

To remove an access token, click the Remove Token button under the Actions column in the Tokens list. To expired an access token without removing it, click the Expire Token button .

Z-Ray Live

You can view real-time info on all the requests being made to the Web server, including non-browser based requests, such as APIs, Web services, and mobile requests. Click on Z-Ray Live! On the left side menu . When using an Access token , only URLs with the access token will be displayed with Z-Ray Live !



WordPress Troubleshooting Techniques on Azure Websites

WordPress is one of the popular Web Application 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 trouble shoot them. Here are some common issues discussed below with techniques to resolve them:

How 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(); ?>

Now browse this file and search for upload_max_size


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 if your website storage , move all you media content in the uploads folder to Azure Storage (which costs $0.048 per GB) and use a 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 a 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 , where you need to enter the Azure CDN name for example

How to setup SSL for my WordPress site

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

Can I use mod-rewrite on Azure Websites?

Azure Websites uses 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:

<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" />
<action type="Rewrite" url="index.php" />

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

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

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 to 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 enabled 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 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:

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

  • 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:

//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';

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)”?

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 to resolve 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 to resolve 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:

    Restart your websites.

Related Links

WordPress Troubleshooting Guide
WordPress Support

10 Ways to Speed up your WordPress site on Azure websites

WordPress needs no introduction and is the fastest growing Open source CMS solution which allows you to quickly create dynamic website. The more plugins, content and customizations you add to your WordPress site, can start slowing your WordPress site. Slow page load times can impact your target user audience and discourage them from visiting your website again. A lot of search engines consider page load times as well when ranking results and can impact the visibility of your website on their search engine results. If you are running your WordPress website on Azure Websites and want to optimize it to obtain fast page load time, then consider implementing these quick and easy steps mentioned below to speed up your WordPress site.


When running your WordPress site on Azure Websites, make sure your database and website are in the same datacenter. Network latency can increase the page load time for your site if the website needs to go around the world to make a call to the database. Keeping the site and database components in the same datacenter will reduce the network latency and improve the page load time for your website.


If you are developing the site, you can use the Free MYSQL database that come with WordPress install from the Websites Application Gallery. But this is not ideal for a production level site. The FREE database has:

  • Max 20MB storage for Database
  • Allows up to 4 connections ( max_connections)
  • Low performance

We recommend to use to a database that can handle your estimated user traffic from the various other options supported by ClearDB as seen here. To learn how to provision a database using Clear DB from Azure Store, click here. If ClearDB database option does not meet your needs, you can always setup an Azure VM running MySQL and use that server for your database. To learn how to install MySQL on an Azure VM, click here.


WordPress auto-saves everything but the disadvantage with this is that your database gets filled with a lot of post revisions, trackbacks, pingback, comments and trash items quickly which needs to be cleaned up manually on a regular basis. With the database plan you are using with your Website there will be limitation to the storage size allocated to your database and you may hit this limit as well if the database is not cleaned up regularly.

WP-Optimize is a great plugin which allows you to routinely clean up your database making the database more efficient and filled only with what needs to be kept. It saves you a lot of time without doing manual queries to optimize and clean up your database. Continue reading “10 Ways to Speed up your WordPress site on Azure websites”