0

I know this is a simple question, but I can't for the life of me get it to work. If I log in to my server via SSH (linux) and type in : /home/username/public_html/x/foo.cgi f=subscribe l=list [email protected] the script runs perfectly. However, if I try to run the script via PHP by the likes of : shell_exec("/home/username/public_html/x/foo.cgi f=subscribe l=list [email protected]"); nothing happens.

Can anyone point me in the right direction?

Thanks ahead of time!

Tre

3
  • is foo.cgi a php script? or just executable binary? Commented Jan 14, 2012 at 7:04
  • The webserver is unlikely to have access rights to your home directory - remember, it runs under a completely different userid than your own account. Commented Jan 14, 2012 at 7:16
  • It's a CGI script. Dada mail, to be precise. I'm kinda new to all this so unsure what I need to do Commented Jan 14, 2012 at 8:04

2 Answers 2

1

"Nothing happens" isn't a very descriptive error message. Nevertheless, three possibilities come to mind:

  1. Differences between the server-hosted environment versus the shell environment.
  2. Your server or hosting site may have disabled shell_exec or other functionality.
  3. You may need to be running PHP as the same user you SSH'd in as (or otherwise get the correct permissions).
  4. Some other piece of the stack are in disarray due to mis-configuration or misuse.

Take your pick. Check your logs. Make sure you don't leave any holes available for attackers to get in.

Sign up to request clarification or add additional context in comments.

Comments

0

If you are managing the server, most likely this is a permissions issue. Your webserver is running as www-data or some similar user. It needs execute permissions on the script file to run it. Try changing the script's owner with the chmod command or give the file you're trying to run more liberal access permissions with the chown command.

Another thing to consider is that shell_exec may be disabled if PHP is running in safe mode.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.