PHP programmers mostly stay in an IDE like PHP Storm, the command line is rather the exception. Nevertheless, there are many tips and tricks that are very helpful and make everyday life easier. But let's start at the beginning. We want to build a website. What do we need? Of course a webserver. Now you could install a nginx or Apache locally or mess around with Docker. And for bigger projects this is really useful, but if you just want to try something small, then you should use the web server built into PHP.
php:server:start Starting the built-in web server
$ php -S localhost:8000
try on your machine
explain this command
But it doesn't always have to be a webserver that you start. You can also use PHP on the command line to execute various commands without having to learn Bash or Shell.
php:code:run Run PHP code (Notes: Don't use tags; escape double quotes with backslash).
$ php -r "${code}"
try on your machine
explain this command
Another wonderful feature of PHP on the command line is the linter. We can use it to check scripts for sytactical correctness. Just like an IDE. Why is that important when IDEs can all do that? Well, you don't always have an IDE at hand. For example during deployment or on the CI/CD pipeline.
php:lint Check for syntax errors in php files (linting)
$ php -l ${filename}
try on your machine
One thing that might also be worth mentioning here is the configuration on the command line. You don't always have to edit PHP.ini to try something out, most things can be done with a simple parameter. As an example we will take the mother of all problems and configurations. The memory limit. If you just want to turn it up for a call, it's easy to do.
php:script:run:memory_limit Run a PHP CLI script with a defined memory limit
$ php -d memory_limit=${limit_in_megabyte}M ${filename}
try on your machine
explain this command
Of course there is much more you can do with PHP on the command line, but we will discuss that in another article.