← ServerPilot Docs

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

This is serious stuff!
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 a user named testuser, log in to your server as root and run the following command:

sudo chown -R testuser:testuser /srv/users/testuser/apps

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/testuser/apps/wordpress/wp-admin/menu.php)
    [function.copy]: failed to open stream: Permission denied in
    /srv/users/testuser/apps/wordpress/wp-admin/includes/class-wp-filesystem-direct.php on line 122
Could not copy file: /srv/users/testuser/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/testuser/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/testuser/apps/myapp/process.php on line 78
JFolder::create: Could not create directoryPath: /srv/users/testuser/apps/joomla/
Warning: Failed to move file!
ErrorException: Warning: mkdir(): Permission denied in
    /srv/users/testuser/apps/symfony/Symfony/Component/HttpKernel/Profiler/FileProfilerStorage.php line 42

at ErrorHandler->handle('2', 'mkdir(): Permission denied', '/srv/users/testuser/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/testuser/apps/laravel-develop/app/config/../storage/meta/services.json):
    failed to open stream: Permission denied in
    /srv/users/testuser/apps/laravel-develop/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php line 77
Last updated: July 24, 2018

Launch your first site in 5 minutes