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

<p>Following the documentation on <a href="https://serverpilot.io/docs/how-to-fix-file-permissions?origin_team=T02KF3GFU" rel="nofollow noreferrer">ServerPilot Permissions</a>, via SSH with Terminal, I was able to correct the file and directory ownership.</p>

<p>Thanks for your help Brad.</p>

CC BY-SA 4.0
2019-07-20T11:23:56.343Z
2019-07-20T11:23:56.343Z
Allan
<p>When trying to add assets in the live admin I get the following error:</p>

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

<p>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.</p>

<p>From the web.log file:</p>

<pre><code>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-&gt;handleError(2, 'fopen(assets/im...', '/srv/users/serv...', 158)
#1 [internal function]: craft\web\ErrorHandler-&gt;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-&gt;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-&gt;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-&gt;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-&gt;_relocateFile()
#7 /srv/users/serverpilot/apps/yvonnemosquito-craft/vendor/craftcms/cms/src/services/Elements.php(645): craft\elements\Asset-&gt;afterSave(true)
#8 /srv/users/serverpilot/apps/yvonnemosquito-craft/vendor/craftcms/cms/src/controllers/AssetsController.php(118): craft\services\Elements-&gt;saveElement(Object(craft\elements\Asset))
#9 [internal function]: craft\controllers\AssetsController-&gt;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-&gt;runWithParams(Array)
#12 /srv/users/serverpilot/apps/yvonnemosquito-craft/vendor/craftcms/cms/src/web/Controller.php(187): yii\base\Controller-&gt;runAction('save-asset', Array)
#13 /srv/users/serverpilot/apps/yvonnemosquito-craft/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller-&gt;runAction('save-asset', Array)
#14 /srv/users/serverpilot/apps/yvonnemosquito-craft/vendor/craftcms/cms/src/web/Application.php(298): yii\base\Module-&gt;runAction('assets/save-ass...', Array)
#15 /srv/users/serverpilot/apps/yvonnemosquito-craft/vendor/craftcms/cms/src/web/Application.php(565): craft\web\Application-&gt;runAction('assets/save-ass...', Array)
#16 /srv/users/serverpilot/apps/yvonnemosquito-craft/vendor/craftcms/cms/src/web/Application.php(277): craft\web\Application-&gt;_processActionRequest(Object(craft\web\Request))
#17 /srv/users/serverpilot/apps/yvonnemosquito-craft/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application-&gt;handleRequest(Object(craft\web\Request))
#18 /srv/users/serverpilot/apps/yvonnemosquito-craft/public/index.php(21): yii\base\Application-&gt;run()
#19 {main}
2019-07-15 17:13:52 [-][1][-][info][application] $_GET = [
    'p' =&gt; 'admin/actions//assets/save-asset'
]
</code></pre>

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

CC BY-SA 4.0
2019-07-15T21:42:24.730Z
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
CC BY-SA 4.0
2019-07-16T08:33:08.877Z
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
CC BY-SA 4.0
2019-07-18T23:37:09.073Z
Guessing the owner and group should be set to whatever user:group your webserver is running as.
Brad Bell
CC BY-SA 4.0
2019-07-19T12:13:12.530Z
Thanks Brad, you're right, that's what was happening. The following link helped me get back on track: https://serverpilot.io/docs/how-to-fix-file-permissions?origin_team=T02KF3GFU – if anyone has the same issue
Allan
CC BY-SA 4.0
2019-07-19T18:58:27.593Z
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
<craft3><assets><admin><permissions>
Upload failed, fopen – failed to open stream: Permission denied
# Upload failed, fopen – failed to open stream: Permission denied

(Asked by: username_0 on 2019-07-15)

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.

**Tags:** craft3, assets, admin, permissions

> **Comments:**
> **username_1**: 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?  
> **username_0**: 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.  
> **username_1**: Guessing the owner and group should be set to whatever user:group your webserver is running as.  
> **username_0**: Thanks Brad, you're right, that's what was happening. The following link helped me get back on track: https://serverpilot.io/docs/how-to-fix-file-permissions?origin_team=T02KF3GFU – if anyone has the same issue  
> **username_1**: Glad you're all sorted... can you add your solution as an official answer in case it ends up helping someone in the future?  

---

## 1 answers

### Answer by username_0 on 2019-07-20. Score: 2 | Accepted answer

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](https://serverpilot.io/docs/how-to-fix-file-permissions?origin_team=T02KF3GFU), via SSH with Terminal, I was able to correct the file and directory ownership.

Thanks for your help Brad.


---

