Python script is run through shell_exec
command, but produces no output.
By no output I mean no errors, and when directed to output to file, the file is created, but is blank.
What does work:
- Running this script as any other user
- Running this script as apache using
sudo -u apache ...
- Other
shell_exec
commands run as apache - Other Python scripts run as apache in the same originating directory
- Other Python scripts run using
shell_exec
in the same PHP script that output to the same folder
The only difference between the scripts that work and the one that doesn't is the use of import
to load modules.
UPDATE: Looks like it's a permissions issue, but I can't figure out why
/usr/local/bin/python2.7: can't open file '/var/www/scripts/script.py': [Errno 13] Permission denied
Script location: /var/www/scripts
/var
drwxrwxr-x. 20 root apache 4096 Oct 26 00:04 var
/var/www
drwxrwxr-x. 8 root apache 4096 Oct 13 13:55 www
/var/www/scripts
drwxrwxrwx. 2 apache apache 4096 Oct 27 01:26 scripts
/var/www/scripts/script.py
-rwxrwxrwx. 1 apache apache 1315 Oct 27 09:25 script.py
UPDATE: F*****g SELinux.
Temporarily disabling SELinux with setenforce Permissive
resolves the issue. What is the best approach to make SELinux let Apache run this script from this directory permanently?