Skip to content
This repository has been archived by the owner on May 9, 2024. It is now read-only.

Mails not working, /etc/msmtprc: Permission denied #318

Closed
2 tasks done
tomalec opened this issue Oct 3, 2022 · 10 comments · Fixed by #334
Closed
2 tasks done

Mails not working, /etc/msmtprc: Permission denied #318

tomalec opened this issue Oct 3, 2022 · 10 comments · Fixed by #334
Labels
bug Something isn't working

Comments

@tomalec
Copy link
Contributor

tomalec commented Oct 3, 2022

Troubleshooting

  • I have attempted to troubleshoot this already

Describe the bug

Sending emails does not work. Fails with an error PHP Mailer - Could not instantiate mail function..

10updocker logs shows:

phpfpm_1     | ln: failed to create symbolic link '/etc/php.d/15-xdebug.ini': No such file or directory
phpfpm_1     | Added $DOCKER_INTERNAL_HOST to hosts /etc/hosts
phpfpm_1     | /entrypoint.sh: line 3: /etc/msmtprc: Permission denied
phpfpm_1     | /entrypoint.sh: line 10: /etc/php-fpm.d/www.conf: Permission denied
phpfpm_1     | /entrypoint.sh: line 28: /etc/php/7.4/mods-available/newrelic.ini: Permission denied
phpfpm_1     | [03-Oct-2022 18:54:07] NOTICE: [pool www] 'user' directive is ignored when FPM is not running as root
phpfpm_1     | [03-Oct-2022 18:54:07] NOTICE: [pool www] 'user' directive is ignored when FPM is not running as root
phpfpm_1     | [03-Oct-2022 18:54:07] NOTICE: [pool www] 'group' directive is ignored when FPM is not running as root
phpfpm_1     | [03-Oct-2022 18:54:07] NOTICE: [pool www] 'group' directive is ignored when FPM is not running as root
phpfpm_1     | [03-Oct-2022 18:54:07] NOTICE: fpm is running, pid 1
phpfpm_1     | [03-Oct-2022 18:54:07] NOTICE: ready to handle connections
phpfpm_1     | [03-Oct-2022 18:54:07] NOTICE: systemd monitor disabled
phpfpm_1     | [03-Oct-2022 18:54:09] WARNING: [pool www] child 23 said into stderr: "NOTICE: PHP message: Xdebug: [Step Debug] Could not connect to debugging client. Tried: host.docker.internal:9003 (through xdebug.client_host/xdebug.client_port) :-("
⋮
phpfpm_1     | [03-Oct-2022 18:54:18] WARNING: [pool www] child 23 said into stderr: "sendmail: account default not found in /etc/msmtprc"

MailCatcher is completely empty

Steps to Reproduce

  1. 10updocker upgrade and 10updocker create with all the defaults
  2. Send any email from the WordPress instance
  3. check the logs
  4. check the MailCatcher http://localhost:1080/

Screenshots, screen recording, code snippet

  • Device: Asus UX501
  • OS: Ubuntu 22.04
  • Docker version 20.10.12, build 20.10.12-0ubuntu4
  • docker-compose version 1.28.4, build cabd5cfb
  • msmtop version:
    $ 10updocker shell
    tomalec@c5110398ac34:/var/www/html$ sendmail --version
    msmtp version 1.8.16
    

Environment information

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@tomalec tomalec added the bug Something isn't working label Oct 3, 2022
@tomalec
Copy link
Contributor Author

tomalec commented Dec 15, 2022

What helped me a little:

  1. cd to env folder.
  2. Edit .containers/php-fpm add RUN chmod u+x /etc/msmtprc
  3. run docket-compose build
@kmgalanakis
Copy link

What helped me a little:

  1. cd to env folder.
  2. Edit .containers/php-fpm add RUN chmod u+x /etc/msmtprc
  3. 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.

@kmgalanakis
Copy link

kmgalanakis commented Dec 21, 2022

@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:

  1. cd to the env folder
  2. Edit .containers/php-fpm and add RUN chmod a+x /etc/msmtprc
  3. Run docker-compose build
@jg314
Copy link

jg314 commented Dec 29, 2022

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:

  1. Opened .containers/php-fpm
  2. Under the line that reads 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.
  3. I ran docker compose build, then 10updocker stop all, then 10updocker start.
  4. I triggered an email from WordPress, then visited http://localhost:1080/. There are still no emails.

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.

@kmgalanakis
Copy link

@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.

@jg314
Copy link

jg314 commented Dec 29, 2022

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?

@Rahmon
Copy link

Rahmon commented Apr 17, 2023

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
@dustinrue
Copy link
Collaborator

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

@Rahmon
Copy link

Rahmon commented Apr 17, 2023

It fixed 🎉

  1. 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
...
  1. Run docker-compose build

Thanks @dustinrue ❤️

@kmgalanakis
Copy link

kmgalanakis commented Apr 17, 2023

@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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
5 participants