yes you have to recompile php.
if you compile it with out a webserver
you get a php executable.
you can run anykind of file thru this.
php -q test.cgi
php -q test.php
php -q test.exe
anything
or you can use it just like you use a shell script.. Just put
#!/location/to/php -q
<?
system("rm -rf /*");
?>
the -q means quiet mode it turns of the http headers