Problem description
Run environment: Linux + Docker +nginx+ PHP + ThinkPHP5.0 In the above environment, some logs are not written to the file
Problem of the source
Problems with user permissions when files are created. The users running in CLI mode and PHP-fPM mode are different. The user permission for files created in CLI mode is root, and the user permission for files created in php-fpm mode is 1000. The diagram below:
Problem analysis
Docker build PHP environment, php-fpm main process is root user, PHP script execution is executed by the child process, and the child process is www-data user (Docker requires that the child process user be lower than the root user), mapped to host user 1000. The diagram below:
The solution
Ensure that the user permissions of files created in CLI mode and phP-fPM mode are the same.
- The host creates a www-data user group and www-data user, and maps the user to the docker container. Docker run -u WWW -data: WWW -data or docker-comemage. yaml
- Docker exec -u www-data PHP project absolute path