failed to open stream: Permission denied for WordPress plugin

I'm installing my website on a new hosting company. All WordPress directories are chmod to 775 and the owner (plus group) is my account username, the same owner as when I create new files manually.

Files created by a a non WordPress related PHP script gets another owner ID, I'm guessing that's the webbserver? If I manually create a file and want the same script to write in that I also get this permission denied. Should the WordPress installation have the webbserver owner? Can I change this?

On a side note, WordPress also asks for FTP credentials every time a new theme installs or a plugin updates. If I specify define( 'FS_METHOD', 'direct' ); I get "Installation failed: Could not create directory." instead.

This is the full message:

Warning: file_put_contents(/home/vhosts/www.website.com/wordpress/wp-content/plugins/myplugin/logfile.log): failed to open stream: Permission denied in /home/vhosts/www.website.com/wordpress/wp-content/plugins/myplugin/myplugin.php on line 24

Topic permissions ftp Wordpress

Category Web


  • All files should be owned by the actual user's account, not the user account used for the httpd process.
  • Group ownership is irrelevant unless there are specific group requirements for the web-server process permissions checking. This is not usually the case.
  • All directories should be 755 or 750.
  • All files should be 644 or 640. Exception: wp-config.php should be 440 or 400 to prevent other users on the server from reading it.
  • No directories should ever be given 777, even upload directories. Since the PHP process is running as the owner of the files, it gets the owners permissions and can write to even a 755 directory.

You can use

chown www-data:www-data  -R * 
find . -type d -exec chmod 755 {} \;  
find . -type f -exec chmod 644 {} \;  

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.