2

When trying to add assets in the live admin I get the following error:

Upload failed. The error message was: “fopen(assets/images/general/IMG-2483_190715_161352.jpeg): failed to open stream: Permission denied”

Have tried updating permissions for the assets folder, and making sure other folders have the correct permissions as per docs, but can't seem to get past this issue.

From the web.log file:

2019-07-15 17:13:53 [-][1][-][error][craft\controllers\AssetsController::actionSaveAsset] An error occurred when saving an asset: fopen(assets/images/general/IMG-2483_190715_161352.jpeg): failed to open stream: Permission denied
2019-07-15 17:13:53 [-][1][-][error][yii\base\ErrorException:2] yii\base\ErrorException: fopen(assets/images/general/IMG-2483_190715_161352.jpeg): failed to open stream: Permission denied in /srv/users/serverpilot/apps/yvonnemosquito-craft/vendor/league/flysystem/src/Adapter/Local.php:158
Stack trace:
#0 /srv/users/serverpilot/apps/yvonnemosquito-craft/vendor/craftcms/cms/src/web/ErrorHandler.php(81): yii\base\ErrorHandler->handleError(2, 'fopen(assets/im...', '/srv/users/serv...', 158)
#1 [internal function]: craft\web\ErrorHandler->handleError(2, 'fopen(assets/im...', '/srv/users/serv...', 158, Array)
#2 /srv/users/serverpilot/apps/yvonnemosquito-craft/vendor/league/flysystem/src/Adapter/Local.php(158): fopen('assets/images/g...', 'w+b')
#3 /srv/users/serverpilot/apps/yvonnemosquito-craft/vendor/league/flysystem/src/Filesystem.php(87): League\Flysystem\Adapter\Local->writeStream('IMG-2483_190715...', Resource id #37, Object(League\Flysystem\Config))
#4 /srv/users/serverpilot/apps/yvonnemosquito-craft/vendor/craftcms/cms/src/base/FlysystemVolume.php(77): League\Flysystem\Filesystem->writeStream('IMG-2483_190715...', Resource id #37, Object(League\Flysystem\Config))
#5 /srv/users/serverpilot/apps/yvonnemosquito-craft/vendor/craftcms/cms/src/elements/Asset.php(1500): craft\base\FlysystemVolume->createFileByStream('IMG-2483_190715...', Resource id #37, Array)
#6 /srv/users/serverpilot/apps/yvonnemosquito-craft/vendor/craftcms/cms/src/elements/Asset.php(1293): craft\elements\Asset->_relocateFile()
#7 /srv/users/serverpilot/apps/yvonnemosquito-craft/vendor/craftcms/cms/src/services/Elements.php(645): craft\elements\Asset->afterSave(true)
#8 /srv/users/serverpilot/apps/yvonnemosquito-craft/vendor/craftcms/cms/src/controllers/AssetsController.php(118): craft\services\Elements->saveElement(Object(craft\elements\Asset))
#9 [internal function]: craft\controllers\AssetsController->actionSaveAsset()
#10 /srv/users/serverpilot/apps/yvonnemosquito-craft/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#11 /srv/users/serverpilot/apps/yvonnemosquito-craft/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#12 /srv/users/serverpilot/apps/yvonnemosquito-craft/vendor/craftcms/cms/src/web/Controller.php(187): yii\base\Controller->runAction('save-asset', Array)
#13 /srv/users/serverpilot/apps/yvonnemosquito-craft/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction('save-asset', Array)
#14 /srv/users/serverpilot/apps/yvonnemosquito-craft/vendor/craftcms/cms/src/web/Application.php(298): yii\base\Module->runAction('assets/save-ass...', Array)
#15 /srv/users/serverpilot/apps/yvonnemosquito-craft/vendor/craftcms/cms/src/web/Application.php(565): craft\web\Application->runAction('assets/save-ass...', Array)
#16 /srv/users/serverpilot/apps/yvonnemosquito-craft/vendor/craftcms/cms/src/web/Application.php(277): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#17 /srv/users/serverpilot/apps/yvonnemosquito-craft/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
#18 /srv/users/serverpilot/apps/yvonnemosquito-craft/public/index.php(21): yii\base\Application->run()
#19 {main}
2019-07-15 17:13:52 [-][1][-][info][application] $_GET = [
    'p' => 'admin/actions//assets/save-asset'
]

This is when using local files and folders for the assets, rather than Amazon S3.

  • What are the permissions on the assets/images/general folder, what user:group owns it and what user:group is your web server running PHP as? – Brad Bell Jul 15 '19 at 21:42
  • Thanks Brad. I'm new to server stuff, which is probably why I'm in this mess. But Transmit tells me the permissions are set to 775, the "owner" and "group" are set to "root". And ServerPilot is running PHP 7.3. Thanks again for your help. – Allan Jul 16 '19 at 8:33
  • 1
    Guessing the owner and group should be set to whatever user:group your webserver is running as. – Brad Bell Jul 18 '19 at 23:37
  • Thanks Brad, you're right, that's what was happening. The following link helped me get back on track: serverpilot.io/docs/… – if anyone has the same issue – Allan Jul 19 '19 at 12:13
  • Glad you're all sorted... can you add your solution as an official answer in case it ends up helping someone in the future? – Brad Bell Jul 19 '19 at 18:58
1

This turned out to be an issue with changing permissions on my "root" server. The user/group was then running "root" instead of "serverpilot".

Following the documentation on ServerPilot Permissions, via SSH with Terminal, I was able to correct the file and directory ownership.

Thanks for your help Brad.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.