1

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.

ajw170
  • 144
  • 1
  • 10
  • after your attempt to change the path, if you check apache's path from your perl script as you did before, does it show /usr/local/bin? – Basya Jun 18 '20 at 13:58
  • No, it stays the same. Even after I use SetEnv PATH /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin directive, the PERL script still outputs the same PATH as I originally indicated. So its seems neither SetEnv or PassEnv have any effect. – ajw170 Jun 18 '20 at 14:49
  • Then I have no idea! I hope someone else out there can help you.... – Basya Jun 18 '20 at 21:30

1 Answers1

1

Update: while I wasn't able to get the SetEnv or PassEnv directives to work, I managed to get the desired behavior by modifying Apache's envvars file with the line:

export PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin"

and then restarting the Apache service.

The location of the envvars file probably varies by installation / distribution, but you can find where it is by checking the apachectl script, which contains a line where the envvars file is referenced.

On my system it was at /etc/apache2/envvars.

ajw170
  • 144
  • 1
  • 10