Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add Symfony to Path correctly on Windows?

Tags:

symfony

I followed the instructions as per the Getting Started page (https://symfony.com/doc/current/setup.html).

So after running php -r "readfile('https://symfony.com/installer');"

I then had a file called symfony in the root of my C drive.

I then moved this to be in my C:\wamp64\bin\php folder.

Adding C:\wamp64\bin\php to my Path and closing then reopening the console (to refresh the path, if I run echo %path% I can see it has been added to the path). I then try running symfony and I get the message that 'symfony' is not recognized as an internal or external command, operable program or batch file..

I get the same message if I try running symfony in the directory it exists in.

If I move to the directory containing symfony and run php symfony it works, but this fails when used in a directory that does not contain symfony.

If I use GitBash and try running symfony then it works as expected.

Why does the console not find symfony on my Path and how can I add it to it so that it will find this correctly.

I am using Windows 10 and have WAMP installed.

like image 724
Kvothe Avatar asked Nov 08 '22 22:11

Kvothe


1 Answers

You need to add a batch script to help windows along.

For the sake of completeness, here are all steps required, tested on Windows 10:

  1. get the symfony file php -r "readfile('https://symfony.com/installer');"

  2. move the symfony file to a directory of your choice, so in your case C:\wamp64\bin\php - personally I made a dedicated folder for commands to avoid unintended programs being picked up on: C:\commands

  3. make sure that directory, not the file, has been added to the PATH

At this point if you enter symfony into the command prompt it will come up asking you what you want to execute the program with, so not much use.

To remedy this we need to help it along and tell windows what to do with the file - that is, have PHP run it.

We can achieve this using a batch script:

  1. create a file called symfony.bat, place it into the same directory as your symfony file.

  2. Open the batch script in a file editor and add the following code:

@ECHO OFF
php "%~dp0symfony" %*

Once saved the symfony command should run correctly as Windows will now use the batch file whenever the command is entered.

like image 170
Bananaapple Avatar answered Nov 24 '22 03:11

Bananaapple