PHP exec(), passthru() and system() not working at all? Ubuntu LTS LAMP

Hey LQ,

For some reason I can’t seem to get exec, passthru or system to run a specific command. It will run trivial commands such as “ls -l” but it will not run

ssh -p 223 "mysqldump -u admin_db -pPassword databaseName | gzip -9 > /home/admin/sql-current/sql-current.gz"

I’ve edited the command to not contain the actual domain or password of course. This command works correctly when run from PuTTY but it doesn’t seem to do anything at all when run from a PHP script. Nor does it cause any kind of errors. I even went through the trouble of ensuring that errors were being correctly logged in /var/logs/php_errors.log and the above three php commands don’t trigger an error.

Any ideas on what’s going on here?

Hi wh33t,

I don’t believe you can actually execute such a command like SSH directly, I think what you want to use it the PECL SSH extension that allows you to open and executes commands on remote servers.

Hrm. That would explain a lot. I’ll give that a read through. Thank you.

Thanks that worked. I wonder why you can execute any command you want with exec, passthru and system except SSH stuff.

My guess would be it’s a Security thing. :wink:

You can decide for yourself whether to allow those commands if you have VPS or dedicated hosting. On shared hosting it is up to the provider whether they allow it or not and whether they allow it automatically or only if you provide them with a good reason for needing it.

I have access to the functions and they work. But they do not run or error any command with SSH in them.