Slow Performance with WordPress and MySQL on Windows Server 2019 with IIS

Updated April 8th, 2023 with OPCache optimization

After installing WordPress on a Windows Server host with IIS installed, I noticed a slow initial response time loading webpages. When I tested PHP by itself everything seemed to run very fast. Connecting to MySQL and running some queries directly also seemed to run pretty well.

It seems that the problem lies with DNS name resolution. In your WordPress config file instead of setting the database host localhost use the local ip address instead.

define('DB_HOST','localhost');

Change this to 127.0.0.1

define('DB_HOST','127.0.0.1');

You’ll notice an immediate boost in speed and a higher Google PageSpeed score! The reason for this is because the system has to figure out each time which IP address localhost resolves to. By using the IP address, we skip this lookup meaning the server responds much more quickly.

The second reason you might experience slow performance is that you may not have enabled OPcache.

Enabling OPcache on your production server will optimize any sequential execution of a PHP resulting in enormous improvements.

How to activate PHP OPcache?

  1. First, open your PHP.INI file in notepad or another text editor. It might be in the program files under the PHP version depending on how PHP was installed, but it might be simpler to just find it.
  2. Then make sure extension dir is set to ensure that the extension directory is configured. This line should typically read: extension_dir = "ext"
  3. Add zend_extension=php_opcache.dll on a new line at the end of the PHP code.
  4. Then restart Apache or IIS
  5. Finally, PHP is now faster.

The simplest way to verify that the aforementioned has been successful is to create a PHPinfo file and check to see if “with Zend OPcache” is displayed under the Zend Engine line. Additionally, further down the page, the “Zend OPcache” section ought to be present and display “Up and Running”.



Leave a Reply