I need to use a function to start and stop Tor via web interface. For some reason the following instruction doesn't work (no Tor process was spawned):
if ($_GET['tor'] == 'start') {
shell_exec('/usr/bin/tor > /dev/null 2>&1 &');
...
But it works when I run the exact same string via shell:
$ php -r "shell_exec('killall tor > /dev/null 2>&1 &');"
How to solve the problem?
Thanks in advance. K
The problem was related with /var/tor directory permissions. Since its being spawned by apache user, which doesn't have any home/.tor, he tries to create var/tor. I was only able to get tor's output when starting tor using python (os.system("tor")).
Tor needs write permission to the home directory of the user running tor. This is often not the case for the user running the PHP script.
Try the echo $output; approach mentioned above. You might see this line:
[warn] Failed to parse/validate config: Couldn't access/create private data directory "/var/www/.tor"
Also make sure the path to Tor really is /usr/bin/tor on your system and not /usr/sbin/tor