Been years since I fiddled a lot with IIS & Windows Server. But when you had to do it, you do get a thrill by dirtying your hands when debugging a problem in production and solving it.
Today, it started for me when I upgraded the server I run #Wordpress from PHP7.4 to 8.0, new posts were not showing uploaded images. I was getting a 500.50 HTTP error.
After hours of debugging which involved:
- Disabling and enabling every single plugin in WordPress,
- Enabling Debugging in PHP & IIS,
- Eliminate any file format issues with the ImageMagick CLI utilities that I use to resize the images and add my blog logo; I did this by opening the uploaded media files in Adobe Photoshop and resaving them,
- Disabling URL Rewrite feature in IIS,
- Combing through IIS web.config file for any problems, then reverting to an earlier version from backup,
- Comparing the production PHP.INI to the one from the backup taken before the upgrade.
The last step and then a Google search helped me spot the problem. Somehow the PHP.INI had got changed during the upgrade process, maybe the PHP Manager in IIS had done something I am not sure about. But the solution was to change the upload_tmp_dir setting in php.ini to a folder under wwwroot or any other (non-systems) folder where IUSR has permissions, and all worked well.
What was happening was the default settings for the temp folder in php.ini was set to C:\Windows\Temp which has different permissions compared to the wwwroot folder and the newly uploaded files were being copied from here to the WordPress content folder along with the folder permissions of windows\temp folder. This meant the IIS User (ISR) was being denied sufficient rights to access the new media files uploaded.
;;;;;;;;;;;;;;;; ; File Uploads ; ;;;;;;;;;;;;;;;; ; Whether to allow HTTP file uploads. ; http://php.net/file-uploads file_uploads = On ; Temporary directory for HTTP uploaded files (will use system default if not ; specified). ; http://php.net/upload-tmp-dir ;upload_tmp_dir = ; Maximum allowed size for uploaded files. ; http://php.net/upload-max-filesize upload_max_filesize = 50M ; Maximum number of files that can be uploaded via a single request max_file_uploads = 30