I've been struggling with this issue for a week, after switching from Vagrant. I'll try this with my WordPress site and see how I get on. One issue I need to consider is making the nginx container be able to write to the files, eg. when installing plugins or saving permalinks etc.
Currently, my host file permissions for my files are chrisallen:chrisallen, so will I need to chown them to be chrisallen:www-data, in order for my container to have write access? Or perhaps I could try just adding my own host user to the www-data group.
Hi Chris, we have a working solution for our local development environment. We just tell Nginx and PHP-FPM to run as »chrisallen«. Below you can have a look at a simplified version of our Dockerfile.
# Define base imageFROM php:8.1-fpm-alpine# Define build argumentsARG USER_IDARG GROUP_ID# Define environment variablesENV USER_NAME=chrisallenENV GROUP_NAME=chrisallenENV USER_ID=$USER_IDENV GROUP_ID=$GROUP_IDENV USER_ID=${USER_ID:-1001}ENV GROUP_ID=${GROUP_ID:-1001}# Add group and user based on build argumentsRUN addgroup --gid${GROUP_ID}${GROUP_NAME}RUN adduser --disabled-password--gecos''--uid${USER_ID}--ingroup${GROUP_NAME}${USER_NAME}# Set user and group of working directoryRUN chown-R chrisallen:chrisallen /var/www/html
# Update and install packages# […]# Install PHP extensions# […]# Set nginx and PHP-FPM userRUN sed-ri-e"s!user nginx!user ${USER_NAME}!g" /etc/nginx/nginx.conf
RUN sed-ri-e"s!user = www-data!user = ${USER_NAME}!g" /usr/local/etc/php-fpm.d/www.conf
RUN sed-ri-e"s!group = www-data!group = ${GROUP_NAME}!g" /usr/local/etc/php-fpm.d/www.conf
# Manualy expose port 80 for outside access to nginx# […]# Copy configuration to application container# […]# Start nginx and PHP-FPM# […]
I've been struggling with this issue for a week, after switching from Vagrant. I'll try this with my WordPress site and see how I get on. One issue I need to consider is making the nginx container be able to write to the files, eg. when installing plugins or saving permalinks etc.
Currently, my host file permissions for my files are chrisallen:chrisallen, so will I need to chown them to be chrisallen:www-data, in order for my container to have write access? Or perhaps I could try just adding my own host user to the www-data group.
Did you find a workable solution for the above?
Hi Chris, we have a working solution for our local development environment. We just tell Nginx and PHP-FPM to run as »chrisallen«. Below you can have a look at a simplified version of our Dockerfile.
I hope this will help you.
Happy coding :)
This is such a huge help, thanks for the personalised script ;) I'll try it out on the next setup.