Reputation: 628
I've installed sendmail and want to pipe incoming emails to php.
Every time I send an email to my server I am getting an email back with an error message:
could not open input file: /root/fw/catcher.php 554 5.3.0 unknown mailer error 1
I think something with the permissions of catcher.php
is wrong but I couldn't figure it out by myself.
Sendmail is installed and I have added an alias:
root: "|/usr/bin/php /root/fw/catcher.php"
Permissions (after chmod 777
; I tried chmod 777
and chmod 755
but both won't work):
drwxrwxrwx 2 root root 4096 Jul 20 14:27 fw
-rwxrwxrwx 1 root root 45 Jul 20 14:27 catcher.php
catcher.php (converted line endings to Unix style):
#!/usr/bin/php
<?php echo 'Test'; exit(0); ?>
Executing my php file over cli works fine. All of these commands work:
/usr/bin/php /root/fw/catcher.php
/usr/bin/php7.3 /root/fw/catcher.php
php /root/fw/catcher.php
php7.3 /root/fw/catcher.php
I think there is a problem with the permissions of sendmail.
Upvotes: 7
Views: 1933
Reputation: 7981
Have you checked whether SELinux is enabled and enforcing? You can see this with the getenforce
command.
If this returns Enforcing
, you can fix this in a few ways. You can either disable SELinux enforcement with setenforce Permissive
, or create a policy that allows Apache to run sendmail.
To create a policy like this, the easiest way is to use the audit2allow
tool, which is part of the policycoreutils-python
- so install that if audit2allow
isn't available. Then, check /var/log/audit.log
to see if there are errors about sendmail not being able to run. These error lines can be piped to audit2allow
to create a policy file that can be enabled with semodule -i <module.pp>
.
Upvotes: 0
Reputation: 11242
The error "could not open input file" means that the file cannot be read for some reason.
Please follow these steps to check:
converted line endings to Unix style
I do not know how you check this, but you could try to redo this using dos2unix, as described in this link
dos2unix catcher.php > newcatcher.php
and then compare file sizes.
If the script is encoded in UTF-8, one may be tempted to include a BOM at the beginning. But actually the "#!" characters are not just characters. They are in fact a magic number that happens to be composed out of two ASCII characters. If you put something (like a BOM) before those characters, then the file will look like it had a different magic number and that can lead to problems.
The script will run over cli because you specifically tell it which intepreter to use: php or php7.3:
php /root/fw/catcher.php
php7.3 /root/fw/catcher.php
To remove BOM from the start of the file, try this:
dos2unix catcher.php
Try to run /root/fw/catcher.php, as a shell script without using php or php7.3 executable. From terminal, run:
./root/fw/catcher.php
Upvotes: 1