Hi there I want to update Path environmental variable permanently through PHP script. I know about putenv() but it is not permanent. I have read some where of generating a .reg file with following content.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment]
'PATH'='c:/abc/test/ImageMagick-6.7.8-Q8/convert.exe'
I have generated the file with content.
When I run this file, it shows me that file has been run successfully and key values containing in file is added in registry successfully. But When I go to path variable to check, my values are not there :-(
Can any body tell me why is this happening. I am using window 7. But my work has also to be compatible with window xp. Or is there any other way to accomplish this task?
Need suggestions....
Best Regards
The PATH environment variable in the registry is copied to a process' environment when the process is created.
cmd.exe (the command window or shell) is a process in it's own right. You have to SET PATH= within the shell to change it.
If you open a new command window, you should have the new PATH set. See also Programmatically adding a directory to Windows PATH environment variable
Hi I have solved this issue. I have solved it by creating .bat file. The content of .bat file looks like
#echo off
set KeyName=Path
set KeyValue="D:\songs;%PATH%"
setx -m %KeyName% %KeyValue%
-m is used if you want to set it at system level for all users. If you want it to set only for current user, then remove -m. The above command will set D:\songs in environement Path variable. To run this you need to be the administrator of the system.
Cheers if this is useful for any one :-)
Related
I got the following error when I run a command with php
C:\xampp\htdocs>php
'php' is not recognized as an internal or external command,
operable program or batch file.
I don't get any error when I run the command with php in following path:
C:\xampp\php>php //do not got error here
Why I get this error?
'php' is not recognized as an internal or external command, operable program or batch file.
Add C:\xampp\php to your PATH environment variable.(My Computer->properties -> Advanced system setting-> Environment Variables->path (click on edit))
Then close your command prompt and restart again.
Note: It's very important to close your command prompt and restart again otherwise changes will not be reflected.
You need to Go to My Computer->properties -> Advanced system setting
Now click on Environment Variables..
Add ;C:\xampp\php in path variable value
Now restart command prompt DONE!
Note: Make sure you run CMD via run as administrator
You just need to a add the path of your PHP file. In case you are using wamp or have not installed it on the C drive.
Set "C:\xampp\php" in your PATH Environment Variable. Then restart CMD prompt.
You need to add C:\xampp\php to your PATH Environment Variable, Only after then you would be able to execute php command line from outside php_home.
Is your path correctly configured?
In Windows, you can do that as described here:
http://www.computerhope.com/issues/ch000549.htm
For Laragon:
First, download your PHP from [https://windows.php.net/download/]
then unzip your file -> copy folder -> paste this direction:
C:\laragon\bin\php`Your folder`
search from windows
Edit the system environment variables
and then open it.
Click Environment variables...
Click path and Edit
Click New and add the php.exe path
like:
C:\laragon\bin\php`Your folder`
and then press OK for all steps.
restart laragon and vscode
and our problem is already solved.
Here what I DO on MY PC I install all software that i usually used in G: partian not C:
if my operating system is fall (win 10) , Do not need to reinstall them again and lost time , Then How windows work it update PATH automatic if you install any new programe or pice of softwore ,
SO
I must update PATH like these HERE! all my software i usually used
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;G:\HashiCorp\Vagrant\bin;G:\xampp\php;G:\xampp\mysql\bin;G:\Program Files (x86)\heroku\bin;G:\Program Files (x86)\Git\bin;G:\Program Files (x86)\composer;G:\Program Files (x86)\nodejs;G:\Program Files (x86)\Sublime Text 3;G:\Program Files (x86)\Microsoft VS Code\bin;G:\Program Files (x86)\cygwin64\bin
I also got the following error when I run a command with PHP, I did the solution like that:
From the desktop, right-click the Computer icon.
Choose Properties from the context menu.
Click the Advanced system settings link.
Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
In the Edit System Variable window, Add C:\xampp\php to your PATH Environment Variable.
Very important note: restart command prompt
Extra info:
If you are using PhpStorm as IDE, after updating the path variable you need to restart PhpStorm so that it takes effect.
Restarting terminal window was not enough for me. (PhpStorm 2020.3.2)
In latest Xampp 8.1.2
PHP path is changed to this below: Set it in your PATH variable.
C:\xampp\php\windowsXamppPhp
Don't forget to restart the PowerShell and run as Administrator.
I faced this issue even with a properly set up windows environment variable. I just needed to close and restart the terminal to solve it.
The previous answers about adding the path to the Env Var are correct, but my case was different.
I needed to downgrade my PHP version to 5 in order to update an old application.
I was using the following combination: MAMP, PhpStorm, the Environment Variable Path was set properly to the MAMP PHP version that I was using
The error was showing in PhpStorm's Terminal
The error was due to the php.ini file using # in the comment
After I replaced "#" by ";" I restarted PhpStorm and recognized the PHP version and the command "php -v" worked again
I have to face the same problem which I solved by adding the path of XAMP/WAMP to PATH environment variable.
Follow these steps:
Go to System Properties
Go to Advanced
Go to Environmental Variables
Edit the Path environment variable
Add the installation path of xammp/wamp like in my case the path is E:\xammp\php
Click on Ok
Restart command prompt (cmd)
Check the version of PHP by running php --version.
Laragon users
you will find your PHP folder in the bin folder of laragon. goto your desired PHP version folder and copy the location. for me it was:
C:\laragon\bin\php\php-7.4.19-Win32-vc15-x64
Add that location on your system PATH:
After that, you need to restart your cmd or terminal.
In my case the problem was in the path, I was giving the path to the php.exe and that's wrong I have to write the path of the root folder...
I restarted CMD program it solves my problem
currently im trying to make backup and restore mysql database in my laravel project. I am using this laravel package https://github.com/backup-manager/laravel for backup package. i already follow the intructions, but when i am trying to backup my local database through command line (php artisan db:backup) in the last question, i got this message.
Dumping database and uploading...
[BackupManager\ShellProcessing\ShellProcessFailed]
'mysqldump' is not recognized as an internal or external command,
operable program or batch file.
I already googling it, and already put C:\xampp\mysql\bin to my windows env variables paths, but i still having this issue. if anybody know how to fix this, please tell me, i really appreciate it.
Laravel 5.1.x
It is because mysqldump.exe is not found in that location, the right path is given bellow
Open Command Prompt and type this
cd C:\Program Files (x86)\MySQL\MySQL Server 5.5\bin
Press Enter
then type
mysqldump.exe
or,
Directly open this directory "C:\Program Files (x86)\MySQL\MySQL Server 5.5\bin" and Press LEFT SHIFT KEY from keyboard and RIGHT CLICK on the Directory Window.
then type
mysqldump.exe
It will work 100% correctly
If you are using Xamp then:
Open your Xamp folder
Go to \mysql\bin find the mysqldump.exe
Go to your environment variables under System variable click on 'New'.
As 'variable name' put 'mysqldump'(without the quotes) and as 'variable value' put the path to your xamp\mysql\bin\mysqldump.exe this will make 'mysqldump' available as a global system alias.
Reminder: Make sure to restart your command-line interface.
It happened with me and I solved it by adding the following line at the top of the .bat file.
cd "C:\xampp\mysql\bin"
Please add C:\xampp\mysql\bin to this path at your user variables and system variables. If you are using a wamp server, add C:\wamp64\bin\mysql\mysql8.0.27\bin this path at your user and system variables.
Note: MySQL version path will change as per your installation.
On my side, I was using PowerShell and I had the same error message.
I had to go inside the directory of MySql. Mine was located in:
C:\Program Files\MySQL\MySQL Server 5.7\bin
Then I had to make sure that I had mysqldump.exe in the bin folder.
And then run this command:
./mysqldump.exe -u root -p yordbName > C:\MySqlDump\sakila.sql
It is late, but I will answer to this question for other people who have the same issue.
You need to add the mysqldump.exe runtime file path to your Windows environment variable. I am using Wamp, the path look like this "C:\wamp64\bin\mysql\mysqlx.x.xx\bin"
Close your command-line interface and try again, It should work.
I am using Xamp and the following step is working:
Copy the path "C:\xampp\mysql\bin"
Go to your environment variables under System variable click on 'Path' and add "New".
Put the path there then click ok.
Restart your command-line interface.
I know it is possible to set PATH programmatically with using for example
SET PATH=%PATH%;C:\wamp\bin\php\php5.4.16\
But how can I unset PATH programmatically?
The reason why I want to unset PATH is that I could not rename my text file because it will show this error.
The action cannot be completed because the file is open in php.exe
It is possible to unset PATH in a command prompt window or in a batch file for everything started from within this command interpreter process after doing that.
The possible commands are set PATH= or path ; as explained in help of command path output in a command prompt window after entering path /? or help path.
But PATH is not unset for any process already running and for new process started not from within this command interpreter process.
To remove PATH is a good method for testing a batch file which should be executed by Windows task scheduler. If nothing in the batch file depends on PATH, the probability is high that it works also with Windows task scheduler running with a different account/credentials.
But in your case of being not able to rename a text file as being currently opened by php.exe, it is of no use to unset PATH. Terminate PHP process and rename the file, or restart Windows which results also in terminating PHP process and rename the file after Windows started again.
You just set a new path
path c:\windows\system32;c:\windows;c:\windows\system32\wbem
which is system standard path.
You can use set to remove C:\Program Files\Debugging Tools for Windows from path.
`set path=%PATH:C:\Program Files\Debugging Tools for Windows=%`
watch out for trailing semi colons.
Though it's unlikely to help your specific problem.
The formatting has fucked up, make sure you put =% on the end of the line.
I have a problem in accessing the php command using command line.
I also created a PATH in my environment variables.
The PATH is like this
C:\wamp\bin\php\php5.5.12
Now the console output is this
C:\Users\Web4>php
'php' is not recognized as an internal or external command,
operable program or batch file.
I also restarted the PC and the command console still same effect. I also created a batch for this still same effect too.
SET PATH=%PATH%;C:\wamp\bin\php\php5.5.12
Is there some configuration other than this? I am using wampserver.
If you run echo %PATH% and it does not include the path to WAMP, then the problem is simply that you haven't set it properly in your environmental variables.
The setting is located here:
http://i.imgur.com/fy5LvRD.png
Edit the System Variables "Path" field and prepend your path to WAMP (obviously make sure you have the exact path to the folder where php.exe is located). Then click OK until all the settings dialogs are closed.
Once you change the path, you will need to close your CMD window and open a new one. The path changes don't take effect on any open CMD windows.
‘php.exe’ is not recognized as an internal or external command,
operable program or batch file.
Why does that error occur even though I've added PHP to my environment variables?
My environment variable PATH is shown below:
C:\Program Files\NVIDIA Corporation\PhysX\Common;C:\Program
Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files\PC
...............
Files\QTSystem\;A:\xampp\php\php.exe
I'm using Windows 7.
A:\xampp\php\php.exe
The PATH environment variable must contain paths only, not file names.
Make that
A:\xampp\php
it is very easy to do
You need to also add php.exe
Adding this path:
windows key + pause
click on Advance system settings
click Environment Variable
System variables part -> Path -> Edit and the add
C:\wamp\bin\php\php5.3.8;
close you cmd prompt if its open
It's Done!
I think you need to change it to A:\xampp\php\ and just leave it there, then it will search the directory for the file, also: have you tried calling just php instead of php.exe and check that the directory is correct.
View above screen shot for setup enviroment variable in window 7
Note:- After setup enviroment variable please restart you computer then its will work fine
Shouldn't the last part be: C:\xampp\php\ ? Unless you remapped your drives, A is the floppy disk. :)
Also, you need to specify the folder, not the exe file itself.
My case am Using Bitnami Ruby Stack apache Web server ,
Pressed Windows key + Pause/Break Button
Clicked advanced system settings
Click Environment Variables
Under System variables > edit PATH variable by adding C:\Bitnami\rubystack-1.9.3-24\php
Click Ok to close the Environment Variable window
Close your command prompt if open
*(Proceed to 7. to confirm if php is installed)
Press Windows Key + R button to open your cmd
Type php -v to view your php version
Set PHP as environment variable from System as below to run it from CMD
1)Windows key + Pause
2)Click on Advanced system settings
3)Now click on Environment Variables.. button
4)In system variable section search for Path and edit it as D:\wamp\bin\php\php5.3.13;(If one needs to append it to some already exits value then start path with;)
5)Now open CMD and run command PHP from any path where you don’t have PHP installed , in my case it’s C drive.
6)We can check above set Path from CMD using Path command also.
If you have installed WAMP server, then your path can vary. For example, I installed WAMP and the path to my php.exe turned out to be:
C:\wamp\bin\php\php5.5.12\php.exe
To make it work, I entered the following path in the PATH variable of the System Variables:
C:\wamp\bin\php\php5.5.12
Once done, I restarted command prompt and everything worked fine.
So the path can vary depending upon how you installed PHP. If you would like to install WAMP server and have it install other essential packages like PHPMyAdmin, etc. you may do so from: wampserver.com
In my case, environment path is C:\ProgramData\Drush\;C:\Program Files (x86)\Drush\Php; and it works for me.
If I simply add C:\xampp\php\ dint work for me.
I hope if someone facing this issue can try this suggestion.
This happened to me and I found why.
Xampp can't run properly depending on your UAC settings.
Try to do this:
Log in as administrator (running cmd.exe as administrator isn't enough)
Execute cmd.exe or equivalent
type php -version