Composer says there is no composer.json in this folder
Composer could not find a composer.json file in /var/www/my-appShort answer
Composer reads composer.json from the working directory, and stops when the file is not there. The message names the folder it checked. Either you are in the wrong folder, the file has another name or never reached the server, or the project has none yet and needs composer init.
Fix it fast
1Find out which cause you have
Read the folder named in the message, then list that folder. Composer reads composer.json from the directory it runs in.
pwd ls -la composer.json composer.lock2Match what you see, then jump to its fix
- 1
The path in the message is a parent or sibling of your projectYou ran Composer from the wrong folderFix - 2
No composer.json anywhere in the folder treeThe project does not have a composer.json yetFix - 3
composer.json exists on your laptop but not after a deploy, zip upload or Docker buildThe file was never copied to the serverFix - 4
The project uses composer-other.json or similar, and a COMPOSER variable may be setThe environment points Composer at another file nameFix
- 1
What does the error look like?
Composer could not find a composer.json file in /var/www/my-appTo initialize a project, please create a composer.json file.
Cause 1 of 4
You ran Composer from the wrong folder
1Check
Composer reads composer.json from the working directory, so a parent or sibling folder does not count.
find . -maxdepth 3 -name composer.json -not -path "*/vendor/*"2Fix
Change into the folder that holds composer.json, or leave the folder alone and pass it with the working-dir option.
cd /var/www/my-app && composer install
# or, without cd:
composer install --working-dir=/var/www/my-app3Verify
The install starts and writes into vendor in the project folder.
ls vendor/autoload.phpConfirmed by getcomposer.org
Cause 2 of 4
The project does not have a composer.json yet
1Check
A folder of plain PHP files has no composer.json. Composer needs that file to know what to install.
ls -la2Fix
Create one with the init command, which asks a few questions, or pre-fill the answers with options. Then add packages with require.
composer init --name="vendor/my-app" --no-interaction
composer require monolog/monolog3Verify
The file exists and lists the package.
cat composer.jsonConfirmed by getcomposer.org
Cause 3 of 4
The file was never copied to the server
1Check
composer.json belongs in the top folder of the project and in version control. A deploy that copies only src or public folders leaves it out, and so does a Docker COPY that skips it.
git ls-files composer.json composer.lock
ls -la2Fix
Commit composer.json and composer.lock, and make the deploy or the Docker COPY step include them before composer install runs.
COPY composer.json composer.lock ./
RUN composer install --no-dev --no-interaction3Verify
Rebuild or redeploy, then run the install in the target folder.
ls composer.json && composer validateConfirmed by getcomposer.org
Cause 4 of 4
The environment points Composer at another file name
1Check
The COMPOSER environment variable changes the file name Composer reads, and the lock file takes the same base name.
echo "$COMPOSER"2Fix
Unset the variable to use composer.json, or keep it and make sure the named file exists in the working directory.
unset COMPOSER
composer install3Verify
Composer reads composer.json and finds composer.lock.
composer validateConfirmed by getcomposer.org
How do I stop it coming back?
- Keep composer.json and composer.lock in the top folder of the repository and commit both.
- In scripts and CI, use --working-dir instead of relying on the current folder.
- Print pwd at the start of a deploy script, so a wrong folder is obvious in the log.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Apache returns 503 or 504 because PHP-FPM did not answer in time
Error dispatching request
Apache sent the request to PHP-FPM and gave up waiting.
3 causes, each with a fixBack end
AWS SDK for PHP cannot get credentials from the instance profile metadata server
Error retrieving credentials from the instance profile metadata server.
The SDK tries the EC2 instance metadata service when it has no valid credentials from anywhere earlier in its chain.
4 causes, each with a fixBack end
AWS SDK for PHP rejects requests: the signature is from the future
Signature not yet current: {date} is still later than {date}
AWS compares the timestamp in your signed request with its own clock.
2 causes, each with a fixBack end
CodeIgniter 4 cannot write its cache files
CodeIgniter\Cache\Exceptions\CacheException: Cache unable to write to /var/www/app/writable/cache/
CodeIgniter 4's file cache needs a cache directory that the web server can really write to.
2 causes, each with a fixBack end
CodeIgniter 3 loads the model but the property is undefined
The model name you are loading is the name of a resource that is already being used: user
CodeIgniter 3 expects a model file named like its class, with the first letter capitalised, for example User_model.php holding class User_model.
2 causes, each with a fixBack end
CodeIgniter 3 stops with "Your system folder path does not appear to be set correctly"
503 Service Unavailable
CodeIgniter 3's front controller resolves $system_path and then checks that the result is a directory.
3 causes, each with a fix