IIS WordPress Uploaded Files 500 Error

 

therI cannot believe I ran into the same problem I blogged about 3 years ago.  So I am add more symptoms and more details to the problem.  I hope it will save many people using IIS WordPress hours of troubleshooting.

Symptoms:

  • You are running WordPress on IIS
  • You cannot even upload a file or image to WordPress Media Library
  • After you upload a file or image to WordPress Media Library, you cannot access the file via URL.  For example, http://www.xxxx.com/wp-content/uploads/2017/04/xxxx.pdf would only return a server 500 error.  Or if you have an uploaded image, you may see a broken image icon in WordPress.
  • You can across this problem after you upgrade your WordPress site to a new or different version of PHP.

Causes:

This is caused by configuration of

  • IIS configuration of PHP and the NTFS permissions set on specific folders.

Quick Fix:

    1. Add {serveranme}/IIS_IUSRS with read permission to the file, or uploads folder or wp-content folder.  Obviously, if you choose wp-content, you can propagate the permission down to subfolder and files.
    2. This only fixes the uploaded files in the WordPress site.  You may still get the same problem with future uploaded files.

Solution:

  1. Locate your php.ini.  For example, C:\Program Files (x86)\PHP\vX.X
  2. Always check your php.ini to see the setting value for “upload_tmp_dir”.  The default value is probably “C:\Windows\Temp”.  It is critical that you verify this.  In fact, I recommend you create a new folder and use it exclusively for PHP upload temp directory.  For example, you can create a “C:\PHP_upload_temp”
  3. Now you need to apply the appropriate permissions to 2 folders with 2 users:
  wp-content (or uploads) PHP upload temp directory (C:\PHP_upload_temp)
IUSR Modify Modify
{servername}/IIS_IUSRS Read Read
  • The above suggestions should work.  You may reduce the permission to see if it works for you.
  • NTFS uses inherited permissions.  You should use Properties/Security/Advanced to view the permissions.
  • The permissions must be set property in PHP upload temp directory first.  The uploaded file will be uploaded to that directory before it is copied to the wp-content/uploads folder.
  • If you see “Parent Object’’” under “Inherited from”, it may indicate some orphaned permission.
  • “When you upload a file, PHP sends the file to a temporary directory on the hard drive (for me it is C:\Windows\Temp) and then copies it over to it’s intended directory.  Once the file has landed in the temporary directory, it is assigned the permissions of that directory. The problem is when Windows copies that file, it keeps the temporary directory’s permissions and doesn’t inherit your web directory’s permissions.”

Reference:

Again, the following 3 articles really help:

http://www.howyoudo.info/index.php/how-to-fix-windows-server-upload-file-inherit-permissions-error/

http://www.amixa.com/blog/2011/04/29/iis-wordpress-images-500-error/

http://chris.wastedhalo.com/2011/01/wordpress-upload-permissions-on-iis-7-fix/

note: I don’t think creator owner plays a part in this problem.

The Iron Giant: Signature Edition (Blu-ray) for $5.99

I used to watch the classic animation often with my kids on Amazon Video until they discontinued it.

Now I can buy the Blue-ray version for $5.99 at amazon.  Sweet.

https://www.amazon.com/gp/product/B01DJVT53O/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&tag=amazh-20&camp=1789&creative=9325&linkCode=as2&creativeASIN=B01DJVT53O&linkId=eb7345fb907c92db501046312bbb3e7b

Philips Hue

I am going to test out some smart home products to see how smart they are:

TP-Link N300 Wireless Wi-Fi Router

It is most useful in a situation when you need to set up a local network with a Broadband internet connection (i.e. phone tethering).  The fact it has 2 LAN ethernet port makes it useful to hook up with other smart home devices requiring wire.

https://www.amazon.com/gp/product/B01CVOLGOG/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&tag=amazh-20&camp=1789&creative=9325&linkCode=as2&creativeASIN=B01CVOLGOG&linkId=15972c0c6abaa4b074a6c83d545e3908

Philips Hue Starter Kit

The changing light scene and music/movie sync makes the most visual impact.  Wow! Cool!

https://www.amazon.com/gp/product/B01KJYSO68/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&tag=amazh-20&camp=1789&creative=9325&linkCode=as2&creativeASIN=B01KJYSO68&linkId=988bac350a164cab891fefa70f160e5f

Philips Hue Lightstrip Plus

You need the lightstrip for accent lighting: behind bed board, under kitchen counter, under entertainment cabinets, behind TV, etc.

https://www.amazon.com/gp/product/B014H2OXYU/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&tag=amazh-20&camp=1789&creative=9325&linkCode=as2&creativeASIN=B014H2OXYU&linkId=59a8951806cf23a5b11e502c3410d629

Amazon Echo Dot

What is a smart home without voice command?

https://www.amazon.com/gp/product/B01DFKC2SO/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&tag=amazh-20&camp=1789&creative=9325&linkCode=as2&creativeASIN=B01DFKC2SO&linkId=64b578a31881380e75f25136caeb5ad4

Tapes

Scotch tapes

Smart Home for Newbie

If you know nothing about smart home and you want to learn about it the easy way, I will tell you how:

Just book an appointment with Amazon Smart Home Consultation.

Go to: http://amazon.com/smart and click on “Smart Home Consultation”.  I was able to schedule an in home visit the next day.

When the guy showed up, he showed me some products.  Then I was able to bombard him with questions like cost, standard, use scenarios.

My opinions include:

  • Smart homes stuff are expensive.  If you think you can reduce your monthly bill (electricity, gas, etc), you need to be creative. 
  • Smart homes may fetch you a better home selling price if done right.
  • The current 3 major players are Google Home, Apple Home Kit, Amazon Alex.
  • The lack of a universal standard makes it hard to integrate every devices easily.
  • Smart homes offer you some minor convenience, turn things (light, garage door, door, etc) on/off
  • Smart home is cool.  You can control everything in your house using voice.  The light setting, sound system, TV are all fun to play with.
  • The foundation of smart home is a wireless network that covers your whole house.  So you will need a good home wifi router or a good mesh network like Google Wifi or Eero.
  • If you want voice commands, then you can buy Amazon Echo / Dot with Alexa or Google Home.
  • Then you can get smart lights, home security stuff, TV, sounds, plugs, thermostats.
  • Note that every device likes to come with their own hub. 

How to Remove Files/Folder Older than X days in Windows using Command Prompt

Problem:

Often, we need to clean up files and folders that are older than x number of days before they eat up all the disk space.  So we need a script/command to delete the old files/folder.

Solution:

   1: @echo off

   2: :: set folder path

   3: set target_path=C:\Users\xxxx\AppData\Local\Temp

   4:  

   5: :: set min age of files and folders to delete

   6: set max_days=7

   7:  

   8: :: remove files from %target_path%

   9: forfiles -p %target_path% -m *.* -d -%max_days% -c "cmd  /c del /q @path"

  10:  

  11: :: remove sub directories from %dump_path%

  12: forfiles -p %target_path% -d -%max_days% -c "cmd /c IF @isdir == TRUE rd /S /Q @path"

 

References:

https://www.howtogeek.com/131881/how-to-delete-files-older-than-x-days-on-windows/

https://elderec.org/2012/02/scripting-delete-files-and-folders-older-than-x-days/