PHP File /tmp/ Does Not Exist
Jan 23, 2017 · 2 minute readCategory: PHP
Recently I ran into an issue with a upload issue in Akeneo when trying to include an image with a product, however the issue could happen with any PHP script.
I had provided a file path of /path/to/file.jpg in the upload, but was getting an error message of Attribute or field "picture" expects a valid pathname as data, "/tmp/path/to/file.jpg" given (for setter media)
I was surprised to see that the path had been changed to /tmp/path/to/file.jpg, but a put a copy of the file into the /tmp/ directory and tried again. This produced the same error message.
At this point I assumed that the issue had to be permissions related, so as the PHP and Nginx user made sure that I could read the file. Slightly stumped I made sure that I was working on the correct container and found that I was.
I then inserted an extra bit of debugging code to write the exception to a file in /tmp/uploadError.txt. I tried the upload again, got the same error, but could not find the newly created file.
After confirming that this logging was in the right place, I decided to scan the entire file system to see where the file had been saved, and got the following result:
root@desktop-container$ find / -type f -iname 'uploadError.txt'
/tmp/systemd-private-c5c2073fc98d4581bb08fe6013321d9e-php-fpm.service-i9QqcK/tmp/uploadError.txt
A bit of googling indicated that this is a security feature of systemd. It can be disabled, if necessary, by editing the PHP service file ( found here /usr/lib/systemd/system/php-fpm.service
and setting PrivateTmp to false.
After doing this you’ll need to reload the systemd daemon by running systemctl daemon-reload
and restart PHP.