How to Fix File Permissions
If your PHP or WordPress app is having problems creating or writing to files or directories, the problem is almost always incorrect file ownership.
All of your app's files should be owned by the app's system user. Most likely, you've created files for your app while SSH'd in as root or SFTP'd files to your app using root. Because PHP does not run as root, it can't write to those files or directories.
Correcting File and Directory Ownership
Be very, very careful running the command below. If you type or copy-and-paste this command incorrectly, you could mess up your entire server beyond repair!
Take a server snapshot before following the instructions in this article.
To correct the file ownership for all of the apps belonging to the default serverpilot system user, log in to your server as root and run the following command:
sudo chown -R serverpilot:serverpilot /srv/users/serverpilot/apps
If you are having permissions problems with apps belonging to other system users, replace serverpilot in the command above with the name of the system user.
Examples of Errors Indicating File Permission Problems
The following are some of the errors you may receive for file permission problems.
Warning: copy(/srv/users/serverpilot/apps/wordpress/wp-admin/menu.php) [function.copy]: failed to open stream: Permission denied in /srv/users/serverpilot/apps/wordpress/wp-admin/includes/class-wp-filesystem-direct.php on line 122 Could not copy file: /srv/users/serverpilot/apps/wordpress/wp-admin/includes/wp-rdf.php
Downloading update from https://downloads.wordpress.org/release/wordpress-3.9.zip… Unpacking the update… Could not create directory.
Downloading update from http://wordpress.org/extend/themes/download/responsive.3.4.6.zip. Unpacking the update. Installing the latest version. Enabling Maintenance mode. Removing the old version of the theme. Could not create directory. /srv/users/serverpilot/apps/wordpress/wp-content/themes/responsive/ Theme upgrade Failed.
Warning: move_uploaded_file(images/robot.jpg): failed to open stream: Permission denied in /srv/users/serverpilot/apps/myapp/process.php on line 78
JFolder::create: Could not create directoryPath: /srv/users/serverpilot/apps/joomla/ Warning: Failed to move file!
ErrorException: Warning: mkdir(): Permission denied in /srv/users/serverpilot/apps/symfony/Symfony/Component/HttpKernel/Profiler/FileProfilerStorage.php line 42 at ErrorHandler->handle('2', 'mkdir(): Permission denied', '/srv/users/serverpilot/apps/Symfony/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Profiler/FileProfilerStorage.php', '42', array('dsn' => 'file:/home/howard/Symfony/app/cache/dev/profiler'))
Warning: Your Magento folder does not have sufficient write permissions.
ErrorException: Warning: file_put_contents( /srv/users/serverpilot/apps/laravel-develop/app/config/../storage/meta/services.json): failed to open stream: Permission denied in /srv/users/serverpilot/apps/laravel-develop/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php line 77