PHP Command Line Process

As a PHP developer, this question has come to me a few times, how do I go about creating a command in Linux that I can write in PHP? Very handy for PHP developers who don’t want to worry about shell scripting…..

1. Write your PHP script, remember it can be executed from any directory, so keep that in mind when writing.
2. Make the first line in your script #!/usr/local/bin/php -q That line tells the computer to use PHP in quiet mode to execute the script.
For example:
#!/usr/local/bin/php -q
<?php
//PHP code Here
?>
3. Now you have two options:
a. Go to /usr/local/bin and save your script there, with no .php, so if you have script.php make it script
b. Go to /usr/local/bin and create a sym link from that directory to your script, so ln -s /path/to/script.php script
4. Set your permissions on the script with the chmod command. Type man chmod if you are not familiar.