Using the Symfony Installer Command Line On Windows

Posted in Symfony
symfony installer error

If you are following the official documentation to use the symfony installer on Windows then it is very likely that you will run into the error:

'symfony' is not recognized as an internal or external command,
operable program or batch file.

Here's how to fix it.

Firstly, I have found that using the supplied command to write the symfony file can save the file with the wrong encoding. Using the command from the GitHub repository saves it as utf8 which seems to fix that issue:

php -r "file_put_contents('symfony', file_get_contents(''));"

When you want to use the command globally, the official docs tell you to move the symfony file to a folder in your system path, however, this can never work. Windows will look for either an .exe or .bat file for any command that does not end in an extension, so simply running 'symfony' will cause an error since no symfony.exe or symfony.bat files exists. We need to create a symfony.bat file (Windows batch file) for the command to work.

The GitHub page also mentions this, but the command given has never worked for me and just outputs the contents of the file on the command line whenever I try to run a command. I find the easiest way is to just create a symfony.bat file and then save the following into the file:

php "%~dp0symfony" %*

Now when you run symfony new project-name Windows will find the batch file from your path which will call the symfony file using php.

If you had a command prompt open before creating the file, you would need to close and reopen it again for the command to work.