# Problem with python scripts ran by apache

## iverasp

Hi. I recently installed TorrentFlux (PHP interface for a python bittorrent client (BitTornado in my case)) on my server . However, it doesnt work. I have no other clue than that it has something to do with apache not being able to run the python scripts that came with TorrentFlux. I've already made a post at the TorrentFlux forum, so ill just copy'paste from there:

Hi. I've just set up TorrentFlux on my server. When I try to upload a torrent and start it, it just states "Torrent Died" under Estimated Time. First I searched with google, and then the forum. I tried the trick of adding sleep(2); to the index.php, but it didnt work then either (I could notice the delay, so I had done it right). I've tried with both BitTorrent and BitTornado, and with TorrentFlux v1,5 and 2,0. Here's some info about my system:

O/S: Gentoo Linux (kernel 2.6.11-r :Cool: 

TorrentFlux Version: Both 1,5 and 2,0

TorrentFlux Addons: None but the default

PHP version: 4.4.0

MySQL version: 12.22

Python version: 2.3.5

Error Messages: 

Heres the last lines of apaches error_log:

sh: cannot redirect standard input from /dev/null: Permission denied

sh: /dev/null: Permission denied

sh: /usr/local/TF_BitTornado/btshowmetainfo.py: Permission denied

sh: cannot redirect standard input from /dev/null: Permission denied

sh: /dev/null: Permission denied

sh: cannot redirect standard input from /dev/null: Permission denied

sh: /dev/null: Permission denied

sendmail: Cannot open mail:25

sh: /usr/local/TF_BitTornado/btshowmetainfo.py: Permission denied

sh: /usr/local/TF_BitTornado/btshowmetainfo.py: Permission denied

sh: /usr/local/TF_BitTornado/btshowmetainfo.py: Permission denied

sh: /usr/local/TF_BitTornado/btshowmetainfo.py: Permission denied

sh: cannot redirect standard input from /dev/null: Permission denied

sh: /dev/null: Permission denied

sendmail: Cannot open mail:25

sh: cannot redirect standard input from /dev/null: Permission denied

sh: /dev/null: Permission denied

sh: cannot redirect standard input from /dev/null: Permission denied

sh: /dev/null: Permission denied

sh: cannot redirect standard input from /dev/null: Permission denied

sh: /dev/null: Permission denied

I've now chmod'd +x the whole /usr/local/TF_BitTornado directory, and disabled mailsending ... still nothing works.

It seems that after I've chmod'd /dev/null to 777, error_log now says "Error opening terminal: unknown." I tried to use ctorrent instead, but it too made the torrents die right after I launch them.

If I run btdownloadheadless.py from the commandline (as root) it works flawlessly.

The output of apache2 -V:

Server version: Apache/2.0.54

Server built: Jul 11 2005 00:23:10

Server's Module Magic Number: 20020903:9

Architecture: 32-bit

Server compiled with....

-D APACHE_MPM_DIR="server/mpm/prefork"

-D APR_HAS_SENDFILE

-D APR_HAS_MMAP

-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)

-D APR_USE_SYSVSEM_SERIALIZE

-D APR_USE_PTHREAD_SERIALIZE

-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT

-D APR_HAS_OTHER_CHILD

-D AP_HAVE_RELIABLE_PIPED_LOGS

-D HTTPD_ROOT="/usr"

-D SUEXEC_BIN="/usr/sbin/suexec2"

-D DEFAULT_PIDLOG="/var/run/httpd.pid"

-D DEFAULT_SCOREBOARD="logs/apache_runtime_status"

-D DEFAULT_LOCKFILE="/var/run/accept.lock"

-D DEFAULT_ERRORLOG="logs/error_log"

-D AP_TYPES_CONFIG_FILE="/etc/apache2/conf/mime.types"

-D SERVER_CONFIG_FILE="/etc/apache2/conf/apache2.conf"

The server is updated every midnight, so every program should be up-to-date.

I tried running apache as root, but then it would start 'cos of the security risc. Then I tried running it as my user, and still got the same errors.

Please, could someone help me with this?

----------

## LoDown

I don't know how to solve this, but hopefully I can help you understand the problem better.  I believe that in your /etc/apache2/conf/commonapache2.conf file, you will find a line that says 'User apache'.  If you look in your /etc/passwd file, you will see that the user 'apache' is given the login shell /dev/null.  Nothing can be interpreted using this shell, so it is the most secure one to give a process like a web server, however, it can cause problems like what you are seeing.  If you were to replace that with /bin/bash (the default user shell) it may solve your problems, but bring up security concerns...

----------

## xenome

Hello,

after "emerge -u world" i have the same problem, but i can't find any solution. 

message in apache error log:

 *Quote:*   

> sh: /dev/null: Permission denied
> 
> sh: /dev/null: Permission denied
> 
> sh: /dev/null: Permission denied
> ...

 

the versions are:

apache = 2.0.54-r31

php = 4.4.0-r3

now the strange thing, i have testet the same (shell_exec("test.sh >/dev/null &")) on another system, the only difference is the php version (4.4.0-r2) the apache and php config files are identical, and there it works, no "sh: /dev/null: Permission denied" message in error log.

where can i found the difference why it works on system B but not on system A?

Greets,

Daniel

----------

