How to check PHP syntax using the command line

How to check PHP syntax using the command line

  • by Tyler (231)
  • Time to complete: 1 minute

If you're using PHP for web developoment, you may often want to check the syntax of your file without opening it in a browser. Checking syntax is quite easy from the command line.

1

If you're on a Mac you can open Terminal which is located in: Applications/Utilities

2

You can navigate to your project folder by using the change directory or cd command followed by the directory. For me it is: cd /Users/josephtylerjones/Developer/scripts/

3

Now you can check the syntax of your script by running php -l followed by the file name. For me it is: php -l testfile.php This command will detect any syntax errors in your script!