I'm trying to create a folder in php and the code kind of fails each it is used with /tmp/...
as path:
exec("mkdir -p /tmp/test/ 2>&1", $output, $return_code);
// $output is empty, $return_code is 0
//mkdir("/tmp/test/"); // Alternative to above
is_dir("/tmp/test/"); // returns true
is_readable("/tmp/test/"); // returns true
But if i check the /tmp
-Folder there is no such directory and all subsequent write or read operations on the folder fail, because the folder does not exist. The permissions for /tmp
are correct (root:root with 777) and i can do sudo -u http mkdir -p /tmp/test
without problems. If I use tmp/test
for example, the code will run fine and create a folder within the directory of the php-skript (Which lies in a folder which belongs to me, not the http-user ... )
Any ideas as to why php fails to create a folder under /tmp/
but reports it as being there?
Edit: To specify read- and write-actions: Those actions are not from within my own script, but rather external skripts which get called by the php-script to execute different tasks. Once all of them succeeded, the folder gets zipped and copied somewhere else.
Edit:
Right after running exec("mkdir -p /tmp/testfolder");
[daishy@littlezombie tmp]$ pwd
/tmp
[daishy@littlezombie tmp]$ ls -al
insgesamt 8
drwxrwxrwt 21 root root 440 3. Aug 18:56 .
drwxr-xr-x 20 root root 4096 10. Jun 16:49 ..
drwxrwxrwt 2 root root 40 3. Aug 09:42 .font-unix
drwxr-xr-x 2 daishy users 60 3. Aug 14:40 hsperfdata_daishy
drwxrwxrwt 2 root root 60 3. Aug 09:42 .ICE-unix
drwx------ 2 daishy users 60 3. Aug 12:35 kde-daishy
drwx------ 2 daishy users 140 3. Aug 18:49 ksocket-daishy
drwx------ 3 root root 60 3. Aug 18:54 systemd-private-5rIfGj
drwx------ 3 root root 60 3. Aug 09:42 systemd-private-HGNW9x
drwx------ 3 root root 60 3. Aug 09:42 systemd-private-od4pyY
drwx------ 3 root root 60 3. Aug 09:42 systemd-private-qAH8UK
drwxrwxrwt 2 root root 40 3. Aug 09:42 .Test-unix
drwx------ 4 daishy users 80 3. Aug 16:55 .Trash-1000
-r--r--r-- 1 root root 11 3. Aug 09:42 .X0-lock
drwxrwxrwt 2 root root 60 3. Aug 09:42 .X11-unix
drwxrwxrwt 2 root root 40 3. Aug 09:42 .XIM-unix
Edit:
As it turns out, this is not a problem with php, but rather with systemd / apache. In short: systemd creates a private tmp-folder for apache while running, which resides under /tmp/systemd-private-XYZ. So the real /tmp
is not viewable by the php-skript, but rather the private one.
See http://blog.oddbit.com/post/private-tmp-directories-in-fedora for more infos.