Closed tomalec closed 1 year ago
What helped me a little:
cd
to env folder..containers/php-fpm
add RUN chmod u+x /etc/msmtprc
docket-compose build
What helped me a little:
cd
to env folder.- Edit
.containers/php-fpm
addRUN chmod u+x /etc/msmtprc
- run
docket-compose build
How can you verify that this change actually worked? I did the modification shown in step 2 but if I rebuild the image and restart the container, I'm still unable to make the emails work.
@tomalec OK, I figured this out.
The docker image used for the phpfpm
container is the 10up/wp-php-fpm. This image has an entrypoint.sh
file, which I'm assuming is executed every time the instance boots.
If you check this file closely, you will notice that very early on this file, on line 3, the script attempts to write to the /etc/msmtprc
file, which generates that error mentioned in your (and my) logs.
phpfpm_1 | /entrypoint.sh: line 3: /etc/msmtprc: Permission denied
So, apparently, the script cannot write to the /etc/msmtprc
file due to wrong permissions.
Following your suggestion, I had to edit .containers/php-fpm
and add RUN chmod a+x /etc/msmtprc
. So to give a full walkaround I did the following:
cd
to the env
folder.containers/php-fpm
and add RUN chmod a+x /etc/msmtprc
docker-compose build
I'm also trying to get MailCatcher to work with no luck. I'm using Windows 11, WP Local Docker v3.0.2 and WSL 2. Here's what I tried:
.containers/php-fpm
RUN touch /usr/local/etc/msmtprc && chown ${CALLING_USER} $_
I added RUN chmod a+x /etc/msmtprc
. I also tried RUN chmod a+x /usr/local/etc/msmtprc
with no luck.docker compose build
, then 10updocker stop all
, then 10updocker start
.Any ideas on where to go from here? If there are error logs I should be looking at please let me know where to find them. Thanks a ton for the help.
@jg314 if you do cat /etc/msmtprc
is the file empty? If it is then the command on the 3rd line of the entrypoint.sh
script is failing to write to the file. If it's not empty, then something else must be wrong.
If I run cat /etc/msmtprc
in the WSL 2 terminal I get a No such file or directory
error. Is that what you were running into before you added RUN chmod a+x /etc/msmtprc
to the php-fm
file?
I'm using Linux and I believe I'm facing the same or similar issue faced by @jg314. When an email is sent, I get this error in the log file: sendmail: account default not found in /etc/msmtprc
.
I can confirm that the /etc/msmtprc
file is empty by running and getting an empty output:
docker exec CONTAINER_NAME-test_phpfpm_1 sh -c "cat /etc/msmtprc"
Other than that, if I try to run the same command in entrypoint.sh to write the default account:
docker exec CONTAINER_NAME-test_phpfpm_1 sh -c "cat > /etc/msmtprc <<EOF
account default
host ${MAILER_HOST:-mailcatcher}
port ${MAILER_PORT:-1025}
auto_from on
EOF"
I get: cannot create /etc/msmtprc: Permission denied
if we take a look at the permissions of the /etc/msmtprc
file, we can see that the ownership (www-data instead of root) is different from the other files:
-rw-r--r-- 1 root root 72029 Mar 21 2022 /etc/mime.types
-rw-r--r-- 1 root root 744 Jan 8 2022 /etc/mke2fs.conf
-rw-r--r-- 1 www-data www-data 56 Apr 16 14:01 /etc/msmtprc
So, maybe it's necessary to change the /etc/msmtprc
file's ownership before trying to write the default account or run the command with sudo
in the entrypoint.sh file.
To "fix" this issue I run the command with sudo
(replace CONTAINER_NAME-test_phpfpm_1
with the appropriate container name, you can figure it out by running docker ps
):
docker exec CONTAINER_NAME-test_phpfpm_1 sudo sh -c "cat > /etc/msmtprc <<EOF
account default
host ${MAILER_HOST:-mailcatcher}
port ${MAILER_PORT:-1025}
auto_from on
EOF"
After running the command above, the content of the /etc/msmtprc
file should be:
account default
host mailcatcher
port 1025
auto_from on
In the .containers/php-fpm file for your project, can you add, under the last RUN line:
RUN chown ${CALLING_USER} /etc/msmtprc
Then rebuild the image. Let me know if this resolves the problem for you.
Thank you
It fixed :tada:
Add the command RUN chown ${CALLING_USER} /etc/msmtprc
to .containers/php-fpm
file:
...
RUN chown ${CALLING_USER} /run/php-fpm
RUN chown ${CALLING_USER} /var/log/php*log
RUN chown ${CALLING_USER} /etc/msmtprc
...
Run docker-compose build
Thanks @dustinrue :heart:
@Rahmon and @dustinrue this is the php-fpm
file I ended up using
ARG PHP_IMAGE=10up/wp-php-fpm-dev:7.4-ubuntu
FROM ${PHP_IMAGE}
ARG CALLING_USER=www-data
ARG CALLING_UID=33
LABEL "com.10up.wp-local-docker"="user-image"
USER root
RUN useradd ${CALLING_USER} -u ${CALLING_UID}
RUN mkdir -p /run/php-fpm
RUN chown ${CALLING_USER} /run/php-fpm
RUN chown ${CALLING_USER} /var/log/php*log
# Section start - Fix email sending issues
RUN chmod a+w /etc/msmtprc
# Section end
# Section start - Fix "permission denied issue" when executing the "entrypoint.sh" script.
RUN chmod a+w /etc/php-fpm.d/www.conf
# Section end
# Section start - Fix nvm installation issues
# Image "10up/wp-php-fpm-dev:7.4-ubuntu" installs nvm for the "www-data" user so
# it also needs to be "installed" for the "CALLING_USER".
RUN mkhomedir_helper ${CALLING_USER}
RUN cp -a /home/www-data/. /home/${CALLING_USER}
RUN chown -R ${CALLING_USER}:${CALLING_USER} /home/${CALLING_USER}/.
# Section end
USER ${CALLING_USER}
Then I had to run docker-compose build
to rebuild the image.
Troubleshooting
Describe the bug
Sending emails does not work. Fails with an error
PHP Mailer - Could not instantiate mail function.
.10updocker logs
shows:MailCatcher is completely empty
Steps to Reproduce
10updocker upgrade
and10updocker create
with all the defaultsScreenshots, screen recording, code snippet
Environment information
No response
Code of Conduct