psysh: Error: mkdir(): Permission denied
I am using psysh as part of larvel’s tinker command, however after updating to the latest version (0.8.15) I am just getting the followin error:
In Configuration.php line 352:
mkdir(): Permission denied
I am unable to get a stacktrace, so I have no clue how to debug the error, any ideas?
PHP Version info:
PHP 7.1.12-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Nov 29 2017 10:03:25) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.1.12-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2017, by Zend Technologies
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 1
- Comments: 16 (4 by maintainers)
Commits related to this issue
- shell.php: prevent permission error Avoid bobthecow/psysh#443[1] (PsySH using XDG_RUNTIME_DIR as temp directory, which is inherited by the new user when doing sudo -E but is only writable by the old ... — committed to wikimedia/mediawiki by tgr 8 years ago
- Make runtime directory optional The runtime directory used to be used internally for a bunch of things, but at this point it's mainly used as a directory to write `edit` command buffers to. Since th... — committed to bobthecow/psysh by bobthecow 2 years ago
- Make runtime directory optional The runtime directory used to be used internally for a bunch of things, but at this point it's mainly used as a directory to write `edit` command buffers to. Since th... — committed to bobthecow/psysh by bobthecow 2 years ago
- Make runtime directory optional The runtime directory used to be used internally for a bunch of things, but at this point it's mainly used as a directory to write `edit` command buffers to. Since th... — committed to bobthecow/psysh by bobthecow 2 years ago
- Make runtime directory optional The runtime directory used to be used internally for a bunch of things, but at this point it's mainly used as a directory to write `edit` command buffers to. Since th... — committed to bobthecow/psysh by bobthecow 2 years ago
This error occurs because you switch user (guessing using
su) without “dash” option.Replace
su www-datawithsu - www-dataand everything should works!psysh tries to write runtime data in “original user” folder, instead of in “current user” folder…
PS my “current user” has
XDG_RUNTIME_DIRenv defined. Switching user without -, forced www-data to use the same env variable, while www-data hasn’t write permission in that folder.I’m reposting my workaround from two days ago on issue #34 over at laravel/tinker here:
Had this for a while on a shared server but thanks to the posts by @ingria and @groovix I looked into it and a workaround (until someone knowledgeable fixes it) is to tell psysh to run in another directory where one has write access.
This can be done through either placing a config-file in
~/.config/psysh/config.phpor as.psysh.phpin the root of a Laravel-project (ref).Here’s my sample config-file (note that the psysh wiki doesn’t mention
runtimeDiras a config option but the source code lists it as a valid option):Can’t get this to work in a shared CloudLinux environment despite adding the suggested code. Any ideas?EDIT: Doh! Of course the config file needs an opening <?php tag. @TheBigK I wonder if this may fix for you too, or perhaps you are smarter than I. 😛 I’ll leave this here just in case anyone else has the issue.
@rvsth - When you are switching user; use
su - USERinstead ofsu USER. That-after su makes all the difference. Give it a try.I ran into this on a shared hosting server running CloudLinux OS where my env was:
env|grep RUNTIME XDG_RUNTIME_DIR=/run/user/1022That directory didn’t exist so i exported XDG_RUNTIME_DIR in .bashrc instead:export XDG_RUNTIME_DIR=/tmp(note that in cloudlinux with cagefs /tmp doesnt mean the shared /tmp on the server but a directory in the users homedir.) After that it worked fine for me.You can also set
XDG_RUNTIME_DIRon the fly if you do not want to create an extra config file:Or if you want to use a temp directory (though a new psysh environment is created each time):
make sure you are making a php file, meaning dont forget to put “<?php” tag at the very beginning
A quick side note from today: When I added
runtimeDirto the config options on the psysh wiki, I noticed that the runtimeDir could be overriden by specifying the environment variableXDG_RUNTIME_DIR. In my case with my shared server, it was set to/run/user/1011, which didn’t exist on and nor did my user have the neccessary permissions to create it either.So I believe this was the culpit at least in my case.
Maybe a fix could be to catch the ‘Permission denied’ on Configuration.php:L352 and revert to using
sys_get_temp_dir()as a fallback? This is already done in ConfigPaths.php:L149 so maybe could be moved to it’s own method for falling back on?Just thinking out loud - take it with a grain of salt =).
@BafS That directory’s existence used to be necessary for PsySH to run, but at this point I believe it’s only used for the
editcommand. I just pushed a branch that (should) make a writable runtime directory optional, and the only weirdness (should) be if you try to useeditand your system can’t find a suitable fallback temp directory. Wanna give that branch a shot?Thanks @alberto-bottarini!
I’m facing this issue as well. In my case, even adding
in the laravel root directory didn’t work. Would really appreciate a fix.