I've always found it useful to be able to run PHP applications from the command line: not only does it allow me to quickly view the output of my code from the command line - where I do the majority of my developing - but it also allows me to make proper command line applications from within PHP. Okay, quite a lot of stuff is not possible, but it's still fun. This applies to Unix only, I believe.
The first way (the old way):
Run this from bash:
That's not an application, as it is just telling
php to run
To be able to run it simply by typing the file name, follow these steps:
whereis php in a terminal and copy what it prints.
2. Add the following code to the top of your php file:
/usr/bin/php is what
whereis php gave me, replace it with what it gave you. Basically, this is telling the command line the location to PHP, and where to run the application. It is called a hashbang due to the
3. Make the application an application by running the following code in the command line (where index.php is your application):
chmod +x index.php
You can then run your application by running the following:
It's that simple!
# This is an <h1> tag ## This an <h2> tag ###### This is an <h6> tag Inline markup: _this text is italic_, **this is bold**, and `code()`. [Link text](link URL "Optional title") [Google](http://google.com/ "Google!") ![Alt text](image URL) ![This is a fish](images/fish.jpg) 1. Ordered list item 1 2. Ordered list item 2 * Unordered list item 1 * Unordered list item 2 * Item 2a * Item 2b And some code: // Code is indented by one tab echo 'Hello world!'; Horizontal rules are done using four or more hyphens: ---- > This is a blockquote
Inline markup: this text is italic, this is bold, and
And some code:
// Code is indented by one tab echo 'Hello world!';
Horizontal rules are done using four or more hyphens:
This is a blockquote