How to use composer on windows? - php

I have installed xampp on my PC. After that I installed composer using window installer. On the website they tell about composer.json which looks something like this in the example
{
"require": {
"monolog/monolog": "1.2.*"
}
}
Where do I put it? How do I run it? I have searched a lot but found nothing. Any suggestion would be great.
I ran command prompt as administrator with following command
C:\windows\system32>composer
It printed out a bunch of commands. I tried typing
C:\windows\system32>composer install
I got an error that composer could not find composer.json file

Okay, let's say your website is at:
C:\xampp\htdocs\mywebsite\
You should put the Composer file at:
C:\xampp\htdocs\mywebsite\composer.json
Then, in your terminal, use these two commands:
cd C:\xampp\htdocs\mywebsite
composer install
That should be it.
You can do various other things with Composer. To find out what type composer in your terminal. It will show you a list of commands you can use.
If you want to know more about a command then you can use composer help [COMMAND], like so:
composer help install

Related

'composer' is not recognized as an internal or external command in windows server

I am using windows server 2008 os. i download composer setup.exe and install to my PC . when I try composer install . I getting an error:
'composer' is not recognized as an internal or external command,
eg:-
c:\xampp\htdocs\shop>composer install
'composer' is not recognized as an internal or external command,
operable program or batch file.
My environment variable PATH is shown below:
C:\xampp\php\;C:\Users\Administrator\AppData\Roaming\Composer\vendor\bin
For anyone coming here from Google who are facing the same issue. I just managed to solve this issue after all the other "solutions" other people suggested didn't work.
I installed Composer properly and the Environment variable was set but it just wouldn't work.
In my case composer is installed in C:\ProgramData\ComposerSetup\bin and this is exactly what is in my PATH Environment variable. After messing around a bit trying to fix it I saw that under System variables under PATH there is something called PATHEXT I opened that and added ;.PHAR to the end of it. So it ended up like this:
And this is what my PATH is now:
I closed all file explorer windows and command prompts and started a new CMD and ran composer --version and it worked!
I hope this helps someone facing the same issue as me.
https://getcomposer.org/doc/00-intro.md#installation-windows
Close your current terminal and open a new one.
I had the same problem, I kept repeating the composer installation until it was resolved this way:
1) Download the composer installer (.exe) and put it on C:/XAMPP.
2) Run the installer by just clicking next till the end.
3) Open command-line (cmd) and cd to your project directory (C:/XAMPP/htdocs/myproject) and type composer and see if you have it installed.
4) It should work now, let's say you want to install a PHP framework from your project directory: cmd=>composer require slim/slim "^3.0".
I had the same problem .
In my case i used the command "php composer.phar " instead of "Composer " and it worked .
just paste " echo #php "%~dp0composer.phar" %*>composer.bat " This in your Terminal where you install composer and Boom you get the solution.
The solution is to use complete composer path instead of composer install
eg:- C:\ProgramData\ComposerSetup\bin\composer install" instead of "composer install
Better still, add "C:\ProgramData\ComposerSetup\bin\" to your environment variables, so that you can use "composer install".
If u can't find composer file than follow only 2 steps
1- Download composer file from [https://getcomposer.org/download/]<click on Composer-Setup.exe>
2- Install above file at your project root dir. and give second path is your php.exe file and finally solve this issue.
Simply use
like this
C:\jay\xampp\htdocs\zoho1>php composer.phar require zohocrm/php-sdk
You Just Don't need to worry about this if you have installed composer using Command-line installation than this problem will occurs.
So my suggestion is to download .exe file by visiting this link https://getcomposer.org/
And also after download using this link you don't need to use php composer.phar instead of composer only
I was facing the same issue in installing the composer command in cmd but when I closed all windows file explorers and again run this command "composer global require laravel/installer " from "**https://laravel.com/docs/8.x**". It just installed without any error
remove all your playings with composer path in path variable
go to https://getcomposer.org/doc/00-intro.md#using-the-installer
and find Composer-Setup.exe link to that exe.
I can solve this problem easily without do anything.
Suppose I'm going to create a project in my desktop and facing the problem which you have shown in the description. now follow the step.
Project folder on desktop
Step 1: go you your CMD(Command Prompt) of your Computer
step 2:Select the folder by command here like image (cd/desktop/example folder)
Step 3: After select the folder now write the command which you want to do like screenshot . you can see Im writing the command for laravel.
done, just easy step you can work anything from here and you can see downloading and being prepare for the project

Installing Slim 3 using Composer

Hello. Please I am new to the php slim framework. I have tried all day to download and install slim 3 through composer but haven't been successful.
Am using a windows pc. I used command prompt and downloaded composer and installed composer to the desired directory. However, when i try installing slim 3, I get an error : "installation failed, reverting ./composer.json to its original content"
[Command Prompt Error Message][Command prompt error message]
you have to load the direction page of slim frame work using this link:
https://www.slimframework.com/docs/start/installation.html
and there will be a command like this - composer require slim/slim "^3.0"
instead of using this one you have to use this...
php composer.phar require slim/slim "^3.0"
and you will get slim installed
Kick-start Slim 3 projects using a skeleton!
With Composer installed, use the cmd line to access the C:\xampp\htdocs folder, then write this command:
$ php create-project slim/slim-skeleton [my-app-name]
Command will produce composer.json and composer.lock files along with a public/ folder that can all be committed to VCS (do not commit any other folders/dependencies).
Make sure you have high enough version of PHP, and PHP is in your PATH. To check this - print "php -v " in command line (you can pretty sure run up to PHP7).
Make sure you are in the right directory for your project.
Provide complete command line output, there could be things you didn't know to be important for a good answer.
After all, you can delete composer.json and composer.lock from the directory, and try again.
I use windows with XAMPP to run a virtual apache server.
After many similar issues, I downloaded git-bash and used it instead of the windows cmd.
give it a try, and see if that can resolve your issues.
https://git-scm.com/

Why I can't use "laravel" command inside Homestead VM

I am new to laravel.
So, I have successfully installed and configured Homestead on my Windows machine.
Then I wanted to install Laravel. As I said, I am on Windows, so obviously I don't want to install php, composer and all that stuff on it, that's why I just hit "vagrant ssh" to get inside Homestead and then tried to install laravel following the official documention
composer global require "laravel/installer"
Then I tried to run "laravel" command, but no luck - command not found. I decided, that I had to edit PATH variable, but then I found out that there is no "~/.composer/vendor/bin" folder at all (not it inside /home/vagrant or /root).
and after I got stuck. What do I do wrong, guys?
P.S. "composer create-project --prefer-dist laravel/laravel blog" works fine, but I want to find out how to make "laravel" command work
I don't believe there is a laravel command-line executable.
Are you trying to run artisan commands?
docs
when you run composer global require "laravel/installer" what did it say ? it should output
Changed current directory to /home/vagrant/.config/composer where laravel will be installed
so you can just add /home/vagrant/config/composer/vendor/bin (note config vs what you say ~/.composer/vendor/bin) in your PATH variable and laravel command will work

Running composer in a different directory than current

I don't know if this question has been asked, because searching finds results mostly about moving the libraries installation directory.
I have a globally installed composer command. Is there a way to run, for example, composer install in a different directory than current, i.e. to specify the directory in which I would like tu run the command?
E.g. being in /home/someuser, I would like to acquire the same result as in running composer install it inside /home/someuser/myproject. Of course, one way would be to simply change the current directory, run composer and go back.
Try composer install -h. There you'll find an option --working-dir (or -d). And that's what you're looking for.
Then run:
composer install --working-dir=/home/someuser/myproject
You can find more in composer docs.
Depending on your operating system, the = might need to be removed:
composer install --working-dir /home/someuser/myproject
In addition to the above answer from Tomáš Votruba i had to append the = charachter on OSX. So the full command would be:
composer install -d=/home/someuser/myproject
My first post on SO so was unable to simply add this as a comment.
This works for me, PHP 7.3 on ubuntu 18.04
Install
composer install --working-dir=/your_composer_dir
Update
composer update --working-dir=/your_composer_dir
I tried what others said, but it was giving me: Invalid working directory specified 'PATH' does not exist. Although it was my working dir that contained composer.json!
I don't know why anyway, but this worked for me (only for gnu/linux users):
composer --working-dir=$(pwd)
And by the way, if you had run composer -h, it would've told you the solution:
-d, --working-dir=WORKING-DIR If specified, use the given directory as working directory.
I am using a Windows machine with PHPStorm (terminal) and this worked for me.
composer install --working-dir /home/someuser/myproject
My Linux OS machines require me to use
composer install --working-dir=/home/someuser/myproject
Note: You may be able to substitute ~/ for /home/someuser/ if your path is super long.
Run:
cd /home/mysites/google.com
Then run:
composer require facebook/graph-sdk
Above steps will open up the directory named (google.com) and install facebook Graph SDK there.

Composer says ???? when trying to install

I recently installed the PHP Composer dependency manager, however, now when I try to run the command php composer.phar install it simply outputs ????. There is a composer.json file in the same directory, but I can't get it to work.
The contents of my composer.json:
{
"require": {
"cboden/Ratchet": "0.2.*"
}
}
If I try adding -v to the command (php composer.phar install -v) like suggested in the comments, it still says the same thing.
What do I do?
Try this one
php -d detect_unicode=Off composer.phar install
php composer.phar diagnose
It's a system sanity check function. It may report your issue.
I actually managed to fix this problem with a similar solution to Mantas's below.
In his answer, you just add detect_unicode, but I managed to get it to work for me with this command:
php -d detect_unicode=Off -d suhosin.executor.include.whitelist=phar composer.phar install
When I installed Composer I also had to put these both in, so I guess you need to whenever you run the file...

Categories