-rw-r--r-- user group index.php | -rw-r--r-- 1000 1000 index.php
drwxrwxr-x user group tmp/ | drwxrwxr-x 1000 1000 tmp/
If your web application now wants to create some temporary files (via the PHP-FPM process) inside
the ``tmp/`` directory, it will fail due to lack of permissions.
The solution
============
To overcome this problem, it must be made sure that the PHP-FPM process inside the container runs
under the same uid/gid as your local user that mouns the volumes and also wants to work on those
files locally. However, you never know during Image build time what user id this would be.
Therefore it must be something that can be changed during startup of the container.
This is achieved in the Devilbox's containers by two environment variables that can be provided
during startup in order to change the uid/gid of the PHP-FPM user prior starting up PHP-FPM process.
..code-block:: bash
$ docker run -e NEW_UID=1000 -e NEW_GID=1000 -it devilbox/php-fpm:7.2-work
[INFO] Changing user 'devilbox' uid to: 1000
root $ usermod -u 1000 devilbox
[INFO] Changing group 'devilbox' gid to: 1000
root $ groupmod -g 1000 devilbox
[INFO] Starting PHP 7.2.0 (fpm-fcgi) (built: Oct 30 2017 12:05:19)
When ``NEW_UID`` and ``NEW_GID`` are provided to the startup command, the container will do a
``usermod`` and ``groupmod`` prior starting up in order to assign new uid/gid to the PHP-FPM user.
When the PHP-FPM process finally starts up it actually runs with your local system user and making
sure permissions will be in sync from now on.
..note::
To tackle this on the PHP-FPM side is only half a solution to the problem. The same applies to a web server Docker container when you offer **file uploads**. They will be uploaded and created by the web servers uid/gid. Therefore the web server itself must also provide the same kind of solution.