diff --git a/_includes/command-line-interface.md b/_includes/command-line-interface.md new file mode 100644 index 0000000..1998407 --- /dev/null +++ b/_includes/command-line-interface.md @@ -0,0 +1,45 @@ +# Command Line Interface + +PHP was created primarily to write web applications, but it's also useful for scripting command line interface (CLI) programs, too. Command line PHP programs can help you automate common tasks like testing, deployment, and application administrativia. + +CLI PHP programs are powerful because you can use your app's code directly without having to create and secure a web GUI for it. Just be sure not to put your CLI PHP scripts in your public web root! + +Try running PHP from your command line: + + > php -i + +The `-i` option will print your PHP configuration just like the [`phpinfo`][0] function. There are a number of other useful [command line options][1], too. + +Let's write a simple "Hello, $name" CLI program. To try it out, create a file named `hello.php`, as below. + + php hello.php + Usage: php hello.php [name] + > php hello.php world + Hello, world + +## Built-in, command line web server + +Starting with PHP 5.4, you can develop locally on a PHP-enabled web server without the hassle of installing and configuring a full-fledged web server. To start the server, from your web root: + + > php -S localhost:8000 + + * [Learn about running PHP from the command line][5] + * [Learn about the built-in, command line web server][4] + +[0]: http://php.net/manual/en/function.phpinfo.php +[1]: http://www.php.net/manual/en/features.commandline.options.php +[2]: http://php.net/manual/en/reserved.variables.argc.php +[3]: http://php.net/manual/en/reserved.variables.argv.php +[4]: http://www.php.net/manual/en/features.commandline.webserver.php +[5]: http://php.net/manual/en/features.commandline.php diff --git a/_layouts/default.html b/_layouts/default.html index 4c1db35..071531e 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -39,6 +39,7 @@