Composer could not find a composer.json - php

I tried to install composer via brew per:
In usr/local/bin (which was not on Mavricks and I had to make personally) I did.
brew tap josegonzalez/homebrew-php
brew install josegonzalez/php/composer
I can run php composer.phar, but when I do php composer.phar install, I get the error:
Composer could not find a composer.json file in /usr/local/bin
To initialize a project, please create a composer.json file as described in the http://getcomposer.org/ "Getting Started" section
So I go to the https://getcomposer.org/doc/00-intro.md. CTRL+F ".json" and nothing's there. Seriously composer?
EDIT:
What I was trying to do was to have composer executable vs php composer.phar. This works at this point from this now.

To install composer and add to your global path:
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
run these in terminal. It does say if you get an error that usr doesn't exist, you do need to manually make it. I know an answer was selected, so this is for anyone who may see this in the future, as i am sometimes, and don't want to be advised to visit yet another site. Its simple just two lines, might have to be in sudo if you have permission error

You are in wrong directory. cd to your project directory then run composer update.

In my case, I did not copy all project files to the folder where I was running composer install. So do:
Copy your project files (including the composer.json) to folder
open CMD (I am using ConEmu), navigate to the new folder, run composer install from there
It should work or throw errors in case the json file is not correct.
If you just want to make composer run, create a new composer.json file with for example:
{
"require": {
"php": ">=5.3.2"
}
}
Then run composer install.

The "Getting Started" page is the introduction to the documentation. Most documentation will start off with installation instructions, just like Composer's do.
The page that contains information on the composer.json file is located here - under "Basic Usage", the second page.
I'd recommend reading over the documentation in full, so that you gain a better understanding of how to use Composer. I'd also recommend removing what you have and following the installation instructions provided in the documentation.

I encountered the same error, and was able to solve it as follows:
composer diagnose to see if something is wrong with the version of composer installed
composer self-update to install the latest version
composer update to update your composer.json file.

Simple solution is install via this command :
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
To install package it's very simple :
composer global require "phpunit/php-invoker=1.1.*"
Ref : composer web site.

In my case, I am using homestead. cd ~/Homesteadand run composer install.

You could try updating the composer:
sudo composer self-update
If that doest works remove composer files & then use:
SSH into terminal & type :
$ cd ~
$ sudo curl -sS https://getcomposer.org/installer | sudo php
$ sudo mv composer.phar /usr/local/bin/composer
$ sudo ln -s /usr/local/bin/composer /usr/bin/composer
If you face an error that says: PHP Fatal error: Uncaught exception 'ErrorException' with message 'proc_open(): fork failed - Cannot allocate memory' in phar
/bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
/sbin/mkswap /var/swap.1
/sbin/swapon /var/swap.1
To install package use:
composer global require "package-name"

In my case I'm in wrong directory,
My directory Path
eCommerce-shop/eCommerce
I am in inside eCommerce-shop and executing this command composer intsall so that't it throwing this error.

If you forget to run:
php artisan key:generate
You would be face this error : Composer could not find a composer.json

2 things to notice; (i did mistake and corrected with step2)
might be wrong path of compose.json in docker file. ex; if your compose.json file is not in root of repo.
OR
if using any tools to build image, specify relevant path in context.

Create a file called composer.json
Make sure the Composer can write in the directory you are looking for.
Update your composer.
This worked for me

Related

ERROR: Your system is not ready to run Symfony projects

I've downloaded a Symfony application and then checked it using php -f ./app/check.php. However, I get:
[ERROR]
Your system is not ready to run Symfony projects
Fix the following mandatory requirements
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Vendor libraries must be installed
> Vendor libraries are missing. Install composer following
> instructions from http://getcomposer.org/. Then run "php
> composer.phar install" to install them.
However, there is no composer.phar file in this application. e.g.
php composer.phar install
Could not open input file: composer.phar
Note: I already have composer installed.
Any suggestions?
The answer is right there in the error message you received.
Install composer following instructions from http://getcomposer.org/
Instead of composer.phar run:
php composer install
I think that's what you need. If you install Composer, then you probably renamed it to composer, and that's the bin you run.

Why cant I run bin/behat?

I am trying to run behat on my vendor folder. I have installed composer globally, have installed the behat package, but every time I run bin/behat I keep getting this message from composer
You must set up the project dependencies, run the following commands:
curl -s http://getcomposer.org/installer | php
php composer.phar install
I am not sure how to fix this. I see the files are in the vendor folder, and when I type "composer" on the terminal, I see the manual.
If anyone can help me resolve this I would really appreciate it. Thanks!
There are several possible problems leading to this situation:
Make sure that composer is installed in your $PATH. That is, running composer at a command prompt should work, and you shouldn't need to run an explicit path like ~/Downloads/composer.phar
Execute the composer install instruction as the error message suggests. A common error is the message
Mcrypt PHP extension required
in which case you need to install the specified extension. For example, brew install php56-mcrypt on a Mac or sudo apt-get install php5-mcrypt on Ubuntu.

Composer install cant find composer.json

I am trying to just install composer, I am on mac osx. I have done it before using the terminal lines from their site and it worked just fine. I got a clean install on my mac now, and it won't install properly.
I tried to:
cd ~
curl -sS https://getcomposer.org/installer | php
and and:
cd /Applciations/MAMP/htdocs
curl -sS https://getcomposer.org/installer | php
and neither works. (I saw a post saying I should cd to a directory before trying to install it. But no matter what, I keep hitting this error:
Composer could not find a composer.json file in /Applications/MAMP/htdocs
To initialize a project, please create a composer.json file as described in the http://getcomposer.org/ "Getting Started" section
when trying to install composer.
I think your question arises from a slight misunderstanding. Composer installs itself when you run the script provided on their Web site. No additional work to install Composer is necessary.
$ php composer.phar install is used to install packages with Composer, which are almost always listed in a JSON file named composer.json. Without this file, Composer doesn't know which packages to install and fails.
See "Declaring Dependencies" in Composer's Getting Started guide for how to generate a composer.json for your project.
In my case, I had a deprecated error being output from PHP. Apparently that causes composer to fail detecting the composer.json file.

Could not open input file: composer.phar

I am trying to install zendframework using composer tool in wamp server.
The following steps are done towards installation
I downloaded the Composer-Setup.exe file from composer page and got successfully installed.
I downloaded the zendframework and extracted inside the c:\wamp\www\zend folder
I executed the command for self update
php composer.phar self-update
This line generates the error message: could not open file composer.phar
how to resolve this error
If I try the
composer.phar self-update
Use this :
php -r "readfile('https://getcomposer.org/installer');" | php
This will install composer to the current directory so that you can use php composer.phar
The composer.phar install is not working but without .phar this is working.
We need to enable the openssl module in php before installing the zendframe work.
We have to uncomment the line ;extension=php_openssl.dll from php.ini file.
composer use different php.ini file which is located at the wamp\bin\php\php-<version number>\php.ini
After enabling the openssl we need to restart the server.
The execute the following comments.
I can install successfully using these commands -
composer self-update
composer install --prefer-dist
I was trying to install YII 2.0
php composer.phar create-project yiisoft/yii2-app-advanced advanced 2.0.0-alpha
I got the same error:
Could not open input file: composer.phar
Then i gave the full path of .phar like this:
php C:\ProgramData\Composer\bin\composer.phar create-project yiisoft/yii2-app-advanced advanced 2.0.0-alpha
and it worked.
I am using Windows 7, and I got the same problem as yours while using Composer via cmd.
The problem is solved when I use
php C:\ProgramData\ComposerSetup\bin\composer.phar create-project slim/slim-skeleton
instead of
php composer.phar create-project slim/slim-skeleton
Hope this is useful for people who got the same problem.
First try this: dont use the php composer.phar [parameters] simply use composer [parameters] if this doesn't work for you than try the rest. Hope it helps.
Question already answered by the OP, but I am posting this answer for anyone having similar problem, retting to
Could not input open file: composer.phar
error message.
Simply go to your project directory/folder and do a
composer update
Assuming this is where you have your web application:
/Library/WebServer/Documents/zendframework
change directory to it, and then run composer update.
Initially, I was running php composer.phar self-update and got the same error message.
As a resolve, you should use composer command directly after install it.From the command prompt, just type composer and press enter.
If composer is installed correctly then you should able to see a lot of suggestion and command list from composer.
If you are up to this point then you should able to run composer self-update directly.
Try in command line:
curl -sS https://getcomposer.org/installer | php
dont use php composer.phar self-update
First go to Your project directory
simply use composer.phar self-update
This works for me
I have fixed the same issue with below steps
Open project directory Using Terminal (which you are using i.e. mintty )
Now install composer within this directory as per given directions on https://getcomposer.org/download/
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === 'the-provided-hash-code') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
Now run your command.
Everything is working fine now because the composer.phar file is available within the current project directory.
Copied from https://stackoverflow.com/questions/21670709/running-composer-returns-could-not-open-input-file-composer-phar/51907013#51907013
thanks
This is how it worked for me:
Make sure composer is installed without no errors.
Open "System Properties" on windows and go to the "Advanced" tab. (You can just press the windows button on your keyboard and type in "Edit the system environment variables`
"Environment variables"
Under "System variables" Edit "PATH"
Click on "New".
Type in: C:\ProgramData\ComposerSetup\bin\composer.phar
Close all folders & CMDs + restart you WAMP server.
Go to whatever directory you want to install a package in and type in
composer.phar create-project slim/slim-skeleton
for example.
If you go through the documentation, they have mentioned to use php composer.phar
Link: https://getcomposer.org/doc/03-cli.md#update-u
Don't use php composer.phar
only give composer
Command: composer self-update
It will work.
Instead of
php composer.phar create-project --repository-url="http://packages.zendframework.com" zendframework/skeleton-application path/to/install
use
php composer.phar create-project --repository-url="https://packages.zendframework.com" zendframework/skeleton-application path/to/install
Just add https instead of http in the URL. Though it's not a permanent solution, it does work.
Another solution could be.. find the location of composer.phar file in your computer. If composer is installed successfully then it can be found in the installed directory.
Copy that location & instead of composer.phar in the command line, put the entire path there.
It also worked for me!
I had the same issue when trying to use php composer install in a local directory on my Apache server for a laravel project I cloned from Github. My problem was I had already setup composer globally on my Ubuntu 18 machine. Adding sudo instead of php started the install of a whole slew of packages listed in the json.lock file i.e. sudo composer install.
Just Use composer install
composer install

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