If you’re like the majority of people in the world, you do not have shell access to your webserver to execute commands such as chmod, chown, find, or even rm. This can be frustrating at times. Well, there is an easy fix for it – sort of a work around. I recently posted how to do this for a specific command, but wanted to reiterate that this is possible for any and all commands that PHP is allowed to execute on your server. Be careful though, because you can still do damage, just as though you were actually logged in with shell access, if you do not know what you are doing. Be careful and ask questions if you are not sure. Anyways, here goes.

To execute shell commands using PHP, enter the following code into a file and save it as “foo.php” and FTP it up to the root directory of your webserver (the one that has your index file).

<?php
$output = shell_exec('$DESIRED_COMMAND_HERE');
echo "<pre>$output</pre>";
?>

And then go to http://www.YOUR_DOMAIN.com/foo.php and your all set. All results of the command are posted to your web browser!

Please remember, anyone will be able to access these files. So if you place an rm command in there, and someone else accesses it, and it deletes something you don’t want deleted, it’s not my fault. Just use caution and the biggest thing to remember is to delete the file after you have done what you need to do.

Have fun!