[php] Composer could not find a composer.json

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.

This question is related to php json composer-php osx-mavericks

The answer is


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


  • 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

If you forget to run:

php artisan key:generate

You would be face this error : Composer could not find a composer.json


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.


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


I encountered the same error, and was able to solve it as follows:

  1. composer diagnose to see if something is wrong with the version of composer installed
  2. composer self-update to install the latest version
  3. composer update to update your composer.json file.

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 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"

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 did not copy all project files to the folder where I was running composer install. So do:

  1. Copy your project files (including the composer.json) to folder
  2. open CMD (I am using ConEmu), navigate to the new folder, run composer install from there
  3. 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.


Examples related to php

I am receiving warning in Facebook Application using PHP SDK Pass PDO prepared statement to variables Parse error: syntax error, unexpected [ Preg_match backtrack error Removing "http://" from a string How do I hide the PHP explode delimiter from submitted form results? Problems with installation of Google App Engine SDK for php in OS X Laravel 4 with Sentry 2 add user to a group on Registration php & mysql query not echoing in html with tags? How do I show a message in the foreach loop?

Examples related to json

Use NSInteger as array index Uncaught SyntaxError: Unexpected end of JSON input at JSON.parse (<anonymous>) HTTP POST with Json on Body - Flutter/Dart Importing json file in TypeScript json.decoder.JSONDecodeError: Extra data: line 2 column 1 (char 190) Angular 5 Service to read local .json file How to import JSON File into a TypeScript file? Use Async/Await with Axios in React.js Uncaught SyntaxError: Unexpected token u in JSON at position 0 how to remove json object key and value.?

Examples related to composer-php

Composer require runs out of memory. PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted How to change PHP version used by composer PHP7 : install ext-dom issue PHP error: "The zip extension and unzip command are both missing, skipping." Composer: file_put_contents(./composer.json): failed to open stream: Permission denied require(vendor/autoload.php): failed to open stream How to install a specific version of package using Composer? Composer update memory limit Cannot create cache directory .. or directory is not writable. Proceeding without cache in Laravel To enable extensions, verify that they are enabled in those .ini files - Vagrant/Ubuntu/Magento 2.0.2

Examples related to osx-mavericks

Composer could not find a composer.json pip installation /usr/local/opt/python/bin/python2.7: bad interpreter: No such file or directory Where is my m2 folder on Mac OS X Mavericks How to set JAVA_HOME environment variable on Mac OS X 10.9? dyld: Library not loaded: /usr/local/lib/libpng16.16.dylib with anything php related Xcode is not currently available from the Software Update server Maven not found in Mac OSX mavericks Genymotion, "Unable to load VirtualBox engine." on Mavericks. VBox is setup correctly App can't be opened because it is from an unidentified developer Error executing command 'ant' on Mac OS X 10.9 Mavericks when building for Android with PhoneGap/Cordova