I have a bunch of python scripts that start with this shebang line:
#!/usr/bin/env python3
When attempting to run the scripts at the command line, all works as expected. When using Apache, I get the "Internal Server Error" message. Inspecting the error logs, Apache reports:
env: python3: No such file or directory.
At first I thought that this could be related to the env command. However, using a perl script with this shebang line:
#!/usr/bin/env perl
works fine!
I believe this may be due to how the PATH is setup in Apache. When I output Apache's environment using the working perl script, the PATH is reported as /usr/bin:/bin:/usr/sbin:/sbin
. On my machine, both env
and perl
are listed in /usr/bin
, but python3
is located at /usr/local/bin
, which is not included in Apache's path as shown above.
I figured I needed to add /usr/local/bin
to Apache's PATH and have have tried using both SetEnv
and PassEnv PATH
as described in Apache's documentation here:
https://httpd.apache.org/docs/2.4/mod/mod_env.html
However, these don't appear to have any affect as the issue persists.
What am I doing wrong?
PS - When I change the shebang line to #!/usr/local/bin/python3
the script runs as expected. However I'd like to preserve the env
method for portability purposes.