I have found in my experiences with WordPress installations that sometimes they work like a dream, yet at other times, or on other web hosts they seem to work fine until you try to upload an image to the Media library or try to update a plugin automatically without FTP. I decided to try to solve this issue once and for all.
The web host I was using was NearlyFreeSpeech, they are a web host that charge you based on what you use as opposed to a monthly fee which can drive down costs dramatically, I suggest you check them out.
NearlyFreeSpeech have a great blog post that outlines how their permissions and security work on their server. You can find the article here.
The main points to note from the article are:
- The files you upload are owned by a user called ‘me’ and a group called ‘me’. The user that the webserver runs under belongs in a group called ‘web’.
- Your FTP user is the ‘me’ user, all files and folders are set to read, write and execute for the user, which makes sense because you want to be able to manage your files via FTP.
- The webserver user or its ‘web’ group don’t own your files so it has to fall back on the permissions for other/everyone as to whether it can read/write/execute. We can’t set these permissions to write for security reasons.
- By changing the group owner of your files to ‘web’ the webserver’s user will follow the group permissions, which can have the write permission.
- Nearlyfreespeech uses safe_mode in php and with that you are restricted to the directories you can manipulate because of open_basedir. We will have to prevent WordPress using the /tmp directory which is outside of the /public folder on NearlyFreeSpeech.
- Upload your WordPress files via SFTP
- Create your WordPress database
- SSH into your server using a program like Putty for windows
- Navigate to your /public folder in Putty and run this command to change the group owner on all files to ‘web’:
chgrp -R web *
You can run ls -l to check the group owner on your files. - You may need to go up a directory and change the group owner on the public folder itself :
chgrp web public
This way WordPress can create files inside the public folder. - In your FTP software create a folder called ‘tmp’ inside your public folder
- Add this code to your wp-config.xml file:
if ( !defined('WP_TEMP_DIR') )
define('WP_TEMP_DIR', dirname(__FILE__) . '/tmp/');
This will tell WordPress to use the new tmp folder. - Add this code to your wp-config.xml file:
define ('FS_METHOD', 'direct');
This will override WordPress’ permission checks on the server and force WordPress to use ‘direct’ for updates (automatic without FTP) - Check your file permissions, the user and group should have write access, other/everyone should not (Definately no 777 permissions allowed!)
- Run your WordPress Install script
- Done!
The only thing to note is that newly added files are not automatically added to the web group, so its possible you will need to set the group owner again for your files, but this is now just a single command.
Thanks for posting this – you helped me out a ton tonight. I’m setting up a dev site on NFS to demo a WP theme I’ve been working on and I kept running into these issues. In the past I’ve tried FLEX mode and even 777 (gasp!) to get NFS and WP to play well together but this solution worked best. Plus you explained everything clearly and concisely. Cheers!
Pingback: Now hosted on nearlyfreespeech.net | justinwhite.net
Getting this error when adding the tmp folder code listed above:
Warning: Division by zero in /f5//public/wp-config.php on line 18
Warning: Division by zero in /f5//public/wp-config.php on line 18
Warning: Cannot modify header information – headers already sent by (output started at /f5//public/wp-config.php:18) in /f5//public/wp-includes/pluggable.php on line 866
Any ideas?
It may be that you copied the code exactly from my post, there were a few incorrect quote characters, I have corrected them now however. Could you try again? Let me know if you have any further issues.
That did the trick. I still get the FTP prompt every time I try to install a plugin or theme, but I’m just uploading it manually. Thanks for the guide. Let me know if you know of a trick to auto-install plugins.
Thanks!
Did you add the code from point 8? That should override WordPress trying to use FTP for plugin or theme updates.
I updated it again with the code you posted (I actually hadn’t updated step 8 since you updated the post) and it’s now working
Thanks Joe!
Pingback: Pace Ricciardelli » Setup for Wordpress on NearlyFreeSpeech.NET