ManticMoo.COM -> Jeff's Articles -> Programming Articles -> Running php from the commandline

Running php from the commandline

by Jeffrey P. Bigham

Running php from the commandline can be a useful way to test your programs without going through the webserver, and, if you're an experienced, php programmer you may find it a preferential language for writing shell scripts as compared to the more traditional Perl or shell. For me, I was used to interacting with a MySQL database with php and so when it came time to insert a bunch of data that I had I used php to route it to the proper tables. Unfortunately, I had so much data that it timed out on the web. The best solution to my problem would have been to interact directly with the database by writing a sql script or perhaps using a different language, but this was easiest.

Determining where php is on your machine

php can be installed either as a separate program or integrated directly into the apache webserver. Unfortunately, if the latter, then you can't run php scripts without the webserver. If this is the case for you and you have administrative access on the machine of interest, then you can just recompile without the --with-apxs or --with-apache options during configuration and you'll be all set. After you run make you'll get a php binary to do with as you please.