Laravel installation does not know php term - php

I have copied laravel project files into my wamp/www/test folder.
I have also downloaded composer.exe for windows
I have set my php variable
then when I execute the following command to get started, it does not work and says does not the term php
cd c://wamp/www/test
composer install
And here is what I have appended to the environment variable:
C:\wamp\bin\php\php5.3.13
What's wrong with it?

Did you restart your terminal after adding the path to your System Variables?
Or maybe you didn't use ; to separate the new path you added from the already existing ones.

Related

Xampp PHP7 with PHP5 in Windows

I have a Xampp version that it has PHP 5. It is working ok, the problem is that I installed a new Xampp which it has PHP 7, I have first xampp running in localhost:80 and the another xampp in localhost:8085.
I have the two Xampp in different folder, first one in C:/xampp and the second one in C:/xampp7
When i navigate with cmd to Xampp7 and I put on the command line php -v. I do not understand why it still shows me PHP 5 if this xampp has PHP 7. I would like to know why does this happen? and how can I fix it?
Thanks
If you're using a php installation on windows, in order to invoke PHP from cli either you have to refer the full path to the php.exe
C:\Users\YourUser> c:/xampp7/php/php.exe -v
...or you have your path variables set up properly, so the PHP directory will be searched for when you call php.exe.
If you have two xampp folders and call php.exe from anywhere else besides a php folder, then windows will look for the path variable and detect the first one found.
If you want to change this behaviour, either use an absolute path like described above, or set your path variable accordingly.
Actually, php5 is set in your environment variable "path". That's why cmd "php -v" reported php5.
If you set php7 path in environment variable "path", then cmd "php -v" will return php7.
So, whether or not you install xampp in different folder it does not execute according to folder rather execute php or mysql according to environment variable "path".
The best you can do to run different application for different version of php by adding different version of php in xampp. help link.
Or you can leave xampp and start using laragon portable
Please look at the Command Search Sequence in Windows: https://technet.microsoft.com/en-us/library/cc723564.aspx#XSLTsection127121120120
(Headline: Command Search Sequence)
If you are cd'd into a folder, the local file (Step 6) has precedence over folders listed in the PATH variable (Step 7)
However, you just cd'd into C:\Xampp7 - which will result in a final lookup in the PATH, cause C:\Xampp7 does not contain a php.exe
If you would cd into C:\Xampp7\php\bin and run php -v it will report Version 7 as expected.
Depending on what you need to achieve, use absolute paths, or change your PATH Variable.

Install phpunit on windows without composer won't work

I'm trying to install phpunit manually on my windows machine. I don't use composer, so I have to install it manually with a .phar file. I'm following the instructions from the official documentation:
https://phpunit.readthedocs.io/en/latest/installation.html#windows
I've done every step, but it won't work. phpunit --version will throw me the message 'phpunit' is not recognized as an internal or external command, operable program or batch file. Can someone Help me?
I'm using Windows 7 64-bit with XAMPP 3.2.2 and PHP 7.1.1.
EDIT:
My phpunit.cmd file location is C:\xampp\php\phar\phpunit.cmd.
The file contains the code #php "%~dp0phpunit.phar" %*. I've added ;C:xampp\php\phar to my PATH variable.
In order to make Windows recognize any command, you must put the binary's path in the relevant environment variable (PATH). Before that you need to create some kind of file Windows can run natively (i.e. not a .phar – can be a command line / batch file or executable). Here are instructions:
https://phpunit.de/manual/current/en/installation.html#installation.phar.windows
Edit: If following the above instructions, it's also important to make sure that php itself is part of the PATH environment variable, so that it's possible to execute commands like php phpunit.phar.

How to change PHP version used by composer

I want to use another php version on my machine than the one already installed using WAMP (2 PHP version installed).
The composer installed uses PHP 5.6
A new project requires PHP7.0.
Whenever I choose PHP 7 from the control panel of WAMP and then run php -v it still printing PHP5.6 (CLI)... instead of PHP7.
How can I use PHP7 without reinstalling the composer again?
You can change php version of composer without uninstalling it, follow these steps :
Search for system environment variables in cortana.
Click on the button "Environment variables".
Under "System variables" select path and click on edit, you will see one entry like this "C:\wamp\bin\php\php5.6.13".
Just change this to the folder name of the php located at your wamp/bin/php7.1.9, here php7.1.9 is folder name.
Replace php5.6.13 with bin7.1.9, it will look like these "C:\wamp\bin\php\php7.1.9", just click ok on all the boxes.
You are done.
To verify, first close all the cmd windows, than open cmd and type php -v, press enter and you should see php7.1.9.
If you don't see change in php version than just restart your pc and run php -v again in cmd , it will work.
I'm assuming Windows if you're using WAMP. Composer likely is just using the PHP set in your path: How to access PHP with the Command Line on Windows?
You should be able to change the path to PHP using the same instructions.
Otherwise, composer is just a PHAR file, you can download the PHAR and execute it using any PHP:
C:\full\path\to\php.exe C:\full\path\to\composer.phar install
If anyone is still having trouble, remember you can run composer with any php version that you have installed e.g. $ php7.3 -f /usr/local/bin/composer update
Use which composer command to help locate the composer executable.
I found a very easy way to switch php versions:
Search for system environment variable
Click on "Environment variables"
Under "System variables" select path and click on edit
Move the PHP version folder you want to use before the other one.
So for example: php 7.0 will now be used:
Close all windows by clicking "OK"
Close all the cmd windows, than open cmd and type php -v
You will see the correct php version loaded now:
Another possibility to make composer think you're using the correct version of PHP is to add to the config section of a composer.json file a platform option, like this:
"config": {
"platform": {
"php": "<ver>"
}
},
Where <ver> is the PHP version of your choice.
Snippet from the docs:
Lets you fake platform packages (PHP and extensions) so that you can emulate a production env or define your target platform in the config. Example: {"php": "7.0.3", "ext-something": "4.0.3"}.
This is what happens in my case. I hope this may help to someone have same situation. I'm using macOS Monterey with MAMP.
I linked the php 7.4 using ~/.profile file. So the terminal it says I'm using php 7.4. However, still my composer giving an error saying i'm using php 7.3.
So I check the php path using
which php
This gives me the /usr/local/bin/php as my php cli location. So I remove the file and made a symlink to my php7.4 and now working perfectly.
sudo rm -rf /usr/local/bin/php
sudo ln -s /Applications/MAMP/bin/php/php7.4.21/bin/php /usr/local/bin/php
I found out that composer runs with the php-version /usr/bin/env finds first in $PATH, which is 7.1.33 in my case on MacOs.
So shifting mamp's php to the beginning helped me here.
PHPVER=$(/usr/libexec/PlistBuddy -c "print phpVersion" ~/Library/Preferences/de.appsolute.mamppro.plist)
export PATH=/Applications/MAMP/bin/php/php${PHPVER}/bin:$PATH
Old question I know, but just to add some additional information:
WAMP is used only on Microsoft Windows Operating Systems.
Changing the version of PHP used through the left-click -> PHP -> Version menu changes the version used by Apache to server your site.
Changing the version of PHP used through the right-click -> Tools -> Change PHP CLI Version menu changes the version used by WAMP's PHP CLI.
Note: It is important to understand that the "PHP CLI Version" is used by WAMP's own internal PHP scripts. This "PHP CLI Version" has nothing to do with the version you wish to use for your scripts, Composer or anything else.
For your scripts to work with the version you require, you need to add it's path to the Users Environmental Path. You could add it to the Systems environmental Path but the Users Path is the recommended option.
From WAMP v3.1.2, it would display an error when it detect reference to a PHP path in the System or User Environmental Path. This was to stop confusion such as you were experiencing. Since v3.1.7 the display of this error can now be optionally displayed through a selection in the WampSettings menu.
As indicated in previous answers, adding an installed PHP path (such as "C:\wamp64\bin\php\php7.2.30") to the Users Environmental Path is the correct approach. PS: As the value of the Users Environmental Path is a string, all paths added must be separated with a semi-colon (;)
After experiencing the exact same problem (IE: Choosing which version of PHP I wanted Composer to use), I created a script which could easily and rapidly switch between PHP CLI Versions depending on what project I was working on.
The Windows batch script "WampServer-PHP-CLI-Version-Changer" can be found at https://github.com/custom-dev-tools/WampServer-PHP-CLI-Version-Changer
I hope this helps others.
Good luck.
After a long search on the internet and finding many unrelated answers / ones that did not work for me, Here is what worked for me.
Those who are in shared hosting know that bin directory is write-protected and running sudo commands or any system-wide command is not allowed.
There's two ways of solving this:
Run the command directly on your project folder selecting the appropriate PHP version you need.
ea-php80 /opt/cpanel/composer/bin/composer update
To get available PHP on your server type ea-php and hit TAB to see a list.
make an alias to composer
Run this command to edit/make this file nano ~/.bashrc
Inside that file, put alias composer="ea-php80 /opt/cpanel/composer/bin/composer"
This gives you the flexibility to run composer commands as usual without those long trailing strings
If you are using Windows, all you have to do is change the path to php.exe in the composer.bat file located in: "C:\ProgramData\ComposerSetup\bin".
In my case I include paths to all php versions, whenever I need to run a project on a specific php version, I just move the required path to the top (using these buttons in the right) and then close all the terminals and restart my wampp server.
The path with listing in the will be selected as your php version by windows
This is the simplest solution I think.
If you still facing the problem after changing Environment variables in windows, try to delete directory or just rename directory of your old php.
I've done it and it's work.
I will assume that you need this because a requirement to have multiple php versions installed to handle multiple projects.
If this is the case a prefer to run directly the php desired bin pointing to the executable script of composer, for example, in my case I have php 8.1 and 7.4, my main php version configured for CLI is 8.1, but I want to run composer with 7.4 in some projects, so I run this command:
php7.4 -f /usr/local/bin/composer install
Where php7.4 is the bin installed and my global composer script is in /usr/local/bin/composer
From there, you can make an alias like this to facilitate things: alias composer7.4='php7.4 -f /usr/local/bin/composer ' so next time you need to run composer with php#7.4 you only need to run: composer7.4 install
Came here by the title, but the question specifies WAMP; which this may not easily apply to. So, in my case - using a Mac.. so more like a MAMP - if you have brew and the below versions installed, this could help - and composer picks it up.
brew link --overwrite --force php#8.1
php -v
#PHP 8.1...
brew link --overwrite --force php#7.4
php -v
#PHP 7.4...

PHP command not found in my shell for windows 10 neither in git bash. I tried all the available solution from here

When I typed php in my command prompt, It results
C:\Users\samsung>php
'php' is not recognized as an internal or external command,
operable program or batch file.
I have installed xampp in my windows 10 and I haven't edited the php.ini file in the settings. Any help to enable this php command would be greatly appreciated because I am stock in my laravel composer setup due to this.
If you are using windows:
Open My Computer Properties
Click on Advance System Setting
Select Environment Variables
Click on Path & Edit
Click new & Add your PHP.exe path (e.g. C:\xampp\php\php.exe)
As shown in the picture
then Restart
Detail Support available here
You should add the php.exe path to PATH environment variable
http://php.net/manual/en/faq.installation.php#faq.installation.addtopath
Install composer, during the installation process allow composer to add php to your path:
https://getcomposer.org/Composer-Setup.exe

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

I am trying to install Symfony 2.7 as instructed by the manual.
When I open CMD (I am running it as an administrator in Windows 8.1) the default path is C:\Windows\System32. I have tried running the command specified in the documentation there (c:\> php -r "readfile('http://symfony.com/installer');" > symfony), as well as in the root directory, both give me the same error.
I am using WAMP, the appache rewrite module and php_xls are activated.
I've also added the following to the PATH in the environment variables: ;C:\wamp\bin\php\php5.2.5;C:\wamp\bin\mysql\mysql5.0.45\bin
After having added it, I rebooted the computer and still nothing worked. How can I install Symfony 2.7?
Here is the solution to your original problem:
You just have to make sure that the path to your php executable is correct when you add it to your PATH environment variable. This path is probably related to the version of PHP you have. You should be able to find this path by navigating inside your wamp installation and looking for the php folder and binary. In your case, this would be C:\wamp\bin\php\php5.5.12
However, for the new problem you have...
However, I get the error The directory name is invalid when I execute
the following command: c:>projects\ php symfony
You just have to make sure that your PATH is updated with the correct path for your php, and then do this from C:>
php projects\symfony
Note that php is the executable and projects\symfony is the path to the symfony file.

Categories