As a follow up to my article about Installing WordPress on IIS, here are a few tips on fixing common problems with running WordPress on Windows Server.
Slow Page Loading
If you think your pages load slowly especially without catching turned on you can try to change the following settings. I would recommend that you make this change regardless of whether you think it makes a difference or not. Open the wp-config.php file in the root of the WordPress installation folder. Locate the following line of code:
define(‘DB_HOST’, ‘localhost’);
Change this code to the following:
define(‘DB_HOST’, ‘127.0.0.1’);
As an alternative, you can modify your host file and do the same thing. Right click on notepad, or your favorite text editor, and “Run as Administrator”. Now go to “File – Open” and browse to C:\windows\system32\drivers\etc and open hosts. You will need to change your file selection drop-down in notepad from *.txt to *.* so you will see hosts.
Find the two lines below and remove the # from the beginning of these two lines to make them active and save the file.
# 127.0.0.1 localhost
# ::1 localhost
Your file should now have these two lines at or close to the bottom of the file. There will be a lot of lines at the top that starts with #. Do NOT remove the # from these lines.
127.0.0.1 localhost
::1 localhost
The reason for the increase in speed is because by default the hosts file in most Windows installations has the mapping 127.0.0.1 to localhost disabled, so it has to hit DNS each time and figure out the IP address that localhost resolves to. The 127.0.0.1 is for IPV4 and ::1 is for IPV6.
Some installations may have this file named hosts.sam. If yours is named this then you must rename it to hosts as hosts.sam is a sample file and is NOT read by Windows. Change your file explorer view to “show extensions for known file types” or browse to this directory via a CMD prompt to make sure you have this correct.
Maximum File Upload Size
If you tried to upload an image or file to your WordPress site you may have run into an error like “File too large!” or “Upload failed” or “This file exceeds the maximum upload size for this site”. If you have not yet encountered this error, chances are you will at some point. Your max upload and posts size are usually very small unless you or a plugin has modified them already. The defaults for a lot of people is set to 2 megabytes. For most users, this is insufficient. This is also an easy fix.
Locate the folder PHP was installed in. Open php.ini and locate the following line:
upload_max_filesize = 2M (This 2M may be something else).
Change it to the following:
upload_max_filesize = 128M (or whatever size you need it to be)
Also, find the following line:
post_max_size = 2M (This 2M may be something else).
Change it to the following:
post_max_size = 128M (or whatever size you need it to be)
Restart your server or IIS service for these changes to take effect. Now your max upload and post size have been increased to whatever you specified on those two lines.
IIS Folder Permissions
There are a couple of folder permissions that can cause a variety of errors with WordPress on a Windows server. Let’s check those and change them if needed.
Open Windows Explorer and locate the root folder where you have WordPress installed. Right-click this folder, select Properties and click the Security tab. Check and see if IIS_IUSRS exists and that they have the three permissions listed below. If it is not there, choose Edit then Add. If you have trouble adding IIS_IUSRS see further down for help.
If you try to add IIS_IUSRS you may run into the following error.
If so, click on the Locations button and choose the server that is listed at the top of the box.
Click OK and you should be able to add this user now and set the appropriate permissions.
WordPress will need special permissions in order to update itself, install plugins and themes, upload pictures, remove session information, and other file writing functions.
Open Windows Explorer and locate the root folder that WordPress is installed in and find the wp-content folder. Right-click this folder, select Properties and click the Security tab. Check and see if IUSR exists and that they have the permissions listed below. You should NOT NEED Full control selected. If it is not there, choose Edit then Add.
Once you have done that, you will need to give the IIS_IUSRS group Read permissions on your “C:\Windows\Temp” folder.
Note: If you have edited your php.ini file and change the upload temp directory then you will need to give IIS_IUSRS group read permissions on that folder instead.
Under some conditions, you may need to give the IIS_IUSRS group modify rights to the “C:\windows\temp” folder or the folder specified in your PHP file. Don’t do this unless there is a need to!
Changing Permalinks Cause 500 Error – “500 (Internal Server) Error”
If you changed your permalinks in WordPress/Settings/Permalinks from default to Post Name and saved your changes you may get a message at the top of the page.
“Permalink structure updated. Remove write access on web.config file now!”
You may have read quite a few articles about changing the .htaccess file and tried in vain to fix it that way. Well, IIS does not use that file and this method won’t fix your problem if you are running Windows Server. You will need to find your web.config file and fix the issue or rename it (don’t delete it) and create a new one. This file should be in the root of your WordPress folder. A plain web.config is listed below. This should get you back into your site, but more than likely there are setting in your current file that you need such as rewrite rules.
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <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> </system.webServer> </configuration>
If you are using the Rewrite module then this web.config may work for you.
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <defaultDocument> <files> <clear/> <add value="index.php"/> <add value="default.php"/> </files> </defaultDocument> <rewrite> <rules> <rule name="WordPress Rule 1" stopProcessing="true"> <match url="^index\.php$" ignoreCase="false" /> <action type="None" /> </rule> <rule name="WordPress Rule 2" stopProcessing="true"> <match url="^wp-admin$" ignoreCase="false" /> <action type="Redirect" url="wp-admin/" redirectType="Permanent" /> </rule> <rule name="WordPress Rule 3" stopProcessing="true"> <match url="^" ignoreCase="false" /> <conditions logicalGrouping="MatchAny"> <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" /> </conditions> <action type="None" /> </rule> <rule name="WordPress Rule 4" stopProcessing="true"> <match url="^(wp-(content|admin|includes).*)" ignoreCase="false" /> <action type="Rewrite" url="{R:1}" /> </rule> <rule name="WordPress Rule 5" stopProcessing="true"> <match url="^([_0-9a-zA-Z-]+/)?(.*\.php)$" ignoreCase="false" /> <action type="Rewrite" url="{R:2}" /> </rule> <rule name="WordPress Rule 6" stopProcessing="true"> <match url="." ignoreCase="false" /> <action type="Rewrite" url="index.php" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
Incorrect time on your site
First, make sure your server has the correct time. Second, go to your Admin Dashboard and click on Settings then General. Next, locate the Timezone drop-down button and set it to the correct timezone. You will see the current date and time below so you can make sure you select the correct one. Be sure to save your settings at the bottom of the page.
403 – Forbidden: Access is Denied
The URL Rewrite module can cause issues with your Distribution Points in SCCM. If you receive this error make sure to check your sites in IIS and remove any Rewrite rules under your Distribution Point’s folders. Click on each path on the left and click on URL Rewrite and delete any rewrite rule you find.
MySQL Bin Files Eating Lots of Disk Space
Q. I get a large number of bin files in the MySQL data directory called “server-bin.n” or mysql-bin.00000n, where n is a number that increments. What is MySQL Binary Log? How do I stop these files from being created?
A. Usually /var/lib/mysql stores the binary log files. (ProgramData\MySQL\MySQL Server 8.0\data on Windows) The binary log contains all statements that update data or potentially could have updated it. For example, a DELETE or UPDATE which matched no rows. Statements are stored in the form of events that describe the modifications. The binary log also contains information about how long each statement took that updated data.
Disable MySQL bin logging
If you are not replicating, you can disable bin logging by changing your my.ini or my.cnf file. Open your my.ini or /etc/my.cnf (/etc/mysql/my.cnf) (ProgramData\MySQL\MySQL Server 8.0\ on Windows).
Find a line that reads “log_bin” or “log-bin” and remove or comment out the line. Then add the line disable_log_bin and save it.
#log_bin = /var/log/mysql/mysql-bin.log disable_log_bin |
You also may want to remove or comment the following lines:
#expire_logs_days = 10 #max_binlog_size = 100M |
Close and save the file.
Delete the bin files to reclaim your space.
Finally, restart mysql server: