How to make simple php cli application

These are only notes, it is not finished

CLI - Command-line interface Wikipedia

You need to have installed PHP to be available globally. Type php -v in terminal to check you have it.

Add hash bang on the beginning of the file.

#!php
<?php

echo "Hello" . $argv[1];

Make it executable

chmod +x /path/to/hello.php

And add it to the bin folder, so you can access it from everywhere.

Make a link so changes to the original will be reflected to the global file.

ln -s /path/to/hello.php /usr/local/bin/hello

... or copy the file

cp /path/to/hello.php /usr/local/bin/hello

Run hello ", how are you?" and you will get output Hello, how are you.

Author

I plan to write more articles about common laravel components. If you are interested let’s stay in touch.
comments powered by Disqus