Having “File Permission” Issues with WordPress on your VPS?

By October 16, 2013How To, I'm a Nerd, Website, Wordpress

When I first installed WordPress on my new VPS server I wasn’t able to upload photos. All I saw was this.

‘An error occurred in the upload. Please try again later.’ Ok.

I did a lot of reading, but couldn’t really find anything. I knew that if I set my folder permissions to 777 that it would do the trick, but I also knew this wasn’t the right solution as this effectively makes it so anyone can access that folder.

End of the day I contact the service folks at my service provider Knownhost who gave me an excellently easy solution in their response. Their service team is awesome.

This is actually a known issue with WordPress using mod_php (DSO) as the PHP handler; in essence, your files (owned by your account) have limited permissions to the webserver (the account “nobody” on a cPanel server) which actually executes PHP code. The better solution (not 777 permissions) is to change the PHP handler to SuPHP, which causes PHP scripts to be run as your account (not as nobody) and thus prevent this issue. You can find an overview of the various common PHP handlers at http://boomshadow.net/tech/php-handlers/ which does specifically address the problem of uploads via PHP script while using DSO.

In shared hosting environments (like DreamHost, who I gather you recently left), SuPHP is by far more common as it prevents certain potential server compromises (related to the fact that under DSO PHP scripts are executed using an account other than your own; especially coupled with 777 permissions, it’s possible for an attacker to modify or inject a PHP script to run arbitrary code, and then gain access to every file which the webserver user can access). We default to DSO on our VPS’s simply because it’s much faster (when used appropriately).

There you have it. I flipped one setting in WHM and everything was working beautifully again.

PHPHandler

To do this: Access WHM > Go to Service Configuration > Configure PHP and suEXEC > Change your PHP handler to suphp. Save.

  • Josue Orozco Altamirano

    Hi, this actually works and solve the problem, but, i want to use APC cache module in my wordpress, i installed, but i guess DSO is better to work with APC, and faster by the way, so is it there any other solution?

    • JB

      Unfortunately, this is where my ability help ends. The folks at KnownHost were able to answer my questions on this matter so I posted the result. Sorry I can’t be of more help, but hope you find what you’re looking for.

  • Sai-Kit Chu

    Thank you so much for writing this article. It saved me a lot of time!

  • Thank you so much. I had been searching a lot to fix this issue and most people said that I need to set my file permissions to 777, which i knew wasn’t a proper solution.

    I contacted my host and those people seemed to be dumb and didn’t have proper knowledge. I had to google everything and fix it while moving my website from shared hosting to vps hosting.

    Thanks a lot again 🙂

  • Jason

    what about the internal error 500 when you flip the switch?