How to add PHP path to %PATH% environment variable on Windows
February 22, 2021
What is PATH and what is it for
It is quite possible that you have never encountered echo %PATH% and environment variable expressions before, so I will briefly explain what it is.
The PATH variable contains a list of folders in which Windows looks for executable files.
In the GUI, when shortcuts are used to launch programs, the PATH value is not very large. But if you run the program on the command line, then PATH can come in handy. Again, if you specify the full path to the file, for example, C:\Users\Alex\Documents\php.exe, then PATH is not used. But if, for example, you run the program only by the file name or just by the name (without the file extension), then whether the program starts will depend on the contents of the PATH variable.
For example, I try to run a file on the command line (without specifying the full path)
In this case, the operating system will look at all PATH entries (several directories may be specified there). Windows will then try to find the php.exe file in each of these directories. If the file is found, it will be launched. If the file is not found, a corresponding message will be displayed.
In fact, only those who work a lot with the command line need to add something to the PATH variable. For example, you are a programmer and you place your programs in the C:\MyApps folder and you often run your command line utilities. In this case, you can add C:\MyApps to PATH and after that, to run programs from this folder, you no longer need to enter the full name each time (for example, C:\MyApps\parser.exe), but it will be enough in the command line enter only the filename:
Do I need to add PHP to environment variable on Windows
When installing and configuring PHP on Windows, it is not necessary to add the path to PHP to the PATH, but it is recommended to do so.
First, you can run PHP using the shorthand:
Secondly, a number of extensions (which are included in the php.ini file) do not work correctly if you do not write the path to PHP in the PATH; this also applies to such a rather popular extension as cURL. In theory, this is some kind of bug of these extensions or PHP, but we ourselves will have to fix the situation, since this problem has existed for many years.
How to add PHP to system environment variables
So let's get started.
In the search box start typing “Edit the system environment variables”
and open the corresponding settings window.
There click on “Environment Variables”, it will open:
In the “System variables” window, find and click on Path, then click “Edit”.
Then click the “New” button and enter “C:\Server\bin\PHP\” there:
Raise the entry to the very top:
Close all windows and save your changes.
Restart the server.
- How to install Apache web server with PHP, MySQL and phpMyAdmin on Windows (100%)
- Error “Unable to load dynamic library 'xmlrpc.so'” (SOLVED) (100%)
- What is open_basedir for and how to use open_basedir (100%)
- How to fix “Configuration File (php.ini) Path” no value (100%)
- All the ‘tips of the day’ LibreOffice (50%)
- How to download YouTube subtitle file in any language (RANDOM - 50%)