by Devin Yang
(This article was automatically translated.)

Published - 3 years ago ( Updated - 3 years ago )

This is the full record of manually changing the fpm owner on my Nas.

1. First download the latest image I want to use. In this article, 7.4.13 is the new version of php I want to use.
​​​​​​​docker pull deviny/fpm:7.4.13
The actual screen is as follows:


2. Enter the D-Laravel directory, and modify the php service of docker-compose.yml to use the latest php (deviny/fpm:7.4.13) version.
cd /volume1/docker/dlaravel
vi docker-compose.yml

Operation screen (I use vi editor):


3. In the yaml file, modify the paragraph of the container service php, and adjust it to the fpm version just downloaded.
### PHP-FPM container ##################################
php:
image: deviny/fpm:7.4.13
volumes:
The actual screen is as follows:



4. Leave after archiving and restart the container. At this time, run the new version of php.
You can use docker-compose to remove and restart, or the bash provided by D-Laravel.
./console restart
#We can also use the docker-compose command to restart, the result is equivalent to the above command, and the meaning is the same:
#docker-compose down --remove-orphans
#docker-compose up -d
After the restart is complete, we execute the command to check. You will see that the user running the container is 1000, which is the default user uid of D-Laravel.
Why do I need to replace it, because I execute it with the admin account on the NAS, which will cause php to have no permission to write to the container folder, so I need to replace it with the same uid (1024) as admin.
admin@CCC:/volume1/docker/dlaravel$ docker-compose exec php id
uid=1000(dlaravel) gid=1000(dlaravel) groups=1000(dlaravel)

5. How to query what your own uid is, just execute id.
admin@CCC:/volume1/docker/dlaravel$ id
uid=1024(admin) gid=100(users) groups=100(users),0(root),101(administrators)
Actual operation screen:

Or, if I want to change the uid of other users, I can also use the id command to query.
admin@CCC:/volume1$ id -u devin
1027
As shown above, devin's uid is 1027.

6. Adjust permissions of etc/php-fpm.d/www.conf
user = 1024
group = 100
The content of my file is as follows:


7. Before starting to adjust the container uid, we can confirm again that the container php service is started.
./console ps
#Alternatively, docker-compose can also be used to check whether the php/fpm permission is enabled.
docker-compose ps php
Actual operation execution screen:


You can also use the docker-compose command to view, port 9000 is the service of php fpm, and the status is Up, which means the container is running.
doesn't work how do we change the permissions inside the container right? :)


Eighth, the main event is here, because the container is Up, so we can execute the instructions in the container on the host side, and issue instructions to adjust the permissions of the user uid, gid and home directory in the container. The instructions are as follows:
#容器中使用者的uid
docker-compose exec -uroot php usermod -u 1024 dlaravel
#The gid of the user in the container
docker-compose exec -uroot php usermod -g 100 dlaravel
# directory permissions in the container
docker-compose exec -uroot php chown -R 1024 /home/dlaravel
In the above command, 1024 is the uid of my admin, you should adjust it according to the uid you want to change.

9. After completing the adjustment, remember to save (commint) the container we changed, we can get the running container id through the following command.
docker ps|grep php
# or docker-compose command
docker-compose exec php hostname
To obtain the container id, you can use the ./console command provided by D-Laravel, or you can use dockr-compose, and the execution results are the same.
In the actual execution screen below, I deliberately use ./console and docker-compose to execute each once.


10. Continuing from the previous step, my container id is 47fcd589fc2b, here I set a new name admin/fpm:7.4.13.
After executing the following command, a new image can be created, and the content is the image we have adjusted uid and gid.
docker commit 47fcd589fc2b admin/fpm:7.4.13


11. After finishing, remember to modify our own docker-compose.yml to use the modified image.


12. After changing the image of the new version, restart and verify whether the uid in the container has changed.
#重啟
./console restart
# enter the container
./console
# check container user id
id

Thirteen, take a look, the dlaravel uid in the container has been changed from 1000 to the 1024 we specified :).


Remarks, the /tmp directory in your container will save the old PHP session. You need to log in to the container as root, empty it and commit the container again.
These old sessions have uid 1000, which will cause the new admin permission to be 1024 and cannot write changes, so the old sessions need to be cleared, if there are users who have logged in to the website during the adjustment process.

1. Log in to the php container as root
admin@CCC:/volume1/docker/dlaravel$ docker-compose exec -uroot php bash
root@0d7682041752:/var/www/html#
2. Clear all files with uid 1000 under /tmp, because here my new uid is 1024, not the default 1000.
find /tmp -uid 1000 -name sess* -exec rm -f {} \;

#Or don't want any session to be committed, cleared without distinction, all users will be logged out, anyway, I want to restart the container :).
rm -rf /tmp/sess*

3. After performing the adjustment, remember to commit the changed version again.


We can pass a file to the public directory and test it. The actual operation screen:


Open the webpage to see, it is 1024 instead of the original 100.


 

Tags: docker container laravel

Devin Yang

Feel free to ask me, if you don't get it.:)

No Comment

Post your comment

Login is required to leave comments

Similar Stories


laravel,oauth2

My most used Laravel passport directives

Laravel provides quite a lot of useful packages, such as Passport is one of them, when the website needs to set up its own OAuth2 authentication host, it really saves time and effort. Take this site as an example, because the front-end and back-end separation mechanisms are adopted (there are two different Laravel projects), and I verify them through the front-end WEB. Basically, I have many other different projects, and they all rely on OAuth2 provided by Laravel to handle cross-domain authentication.

laravel

Laravel 5.7 new feature dump-server.

In Laravel 5.7.x, the artisan command starts to support and integrate Symfony's dump-server. Through the artisan command, start the dump-server, and we can display the dump data on the console.

laravel

In Laravel 5.5, easy to use basic routing

Especially for friends who are studying SEO, we should know that sometimes we need to redirect 301 pages, which is provided in Laravel 5.5 The function of Route::redirect is quite simple. In addition, using Route::view is also very useful for the layout of static pages.