0

I'm trying to create a new Laravel project for use within Homestead, as I have successfully many times in the past, and have issued the following command:

composer create-project --prefer-dist laravel/laravel test

But unfortunately it fails with Composer could not find a composer.json file in /home/vagrant/code/test... and leaves the "test" folder empty.

The full output is here:

1/2:        http://repo.packagist.org/p/provider-latest$d0bd0b2315439b65010ddf266ff3cd834b7f92edb850d5dd1f8a40c44586751f.json
2/2:        http://repo.packagist.org/p/provider-2019-04$0835fd3847a1c8f8d46ee6dd6da638ec6e9846bf1dce10d9b2f10a0e953bbd04.json
Finished: success: 2, skipped: 0, failure: 0, total: 2
1/2:        http://repo.packagist.org/p/provider-latest$d0bd0b2315439b65010ddf266ff3cd834b7f92edb850d5dd1f8a40c44586751f.json
2/2:        http://repo.packagist.org/p/provider-2019-04$0835fd3847a1c8f8d46ee6dd6da638ec6e9846bf1dce10d9b2f10a0e953bbd04.json
Finished: success: 2, skipped: 0, failure: 0, total: 2
Installing laravel/laravel (v5.8.17)
  - Installing laravel/laravel (v5.8.17): Loading from cache
Created project in test

  [InvalidArgumentException]                                                                              
  Composer could not find a composer.json file in /home/vagrant/code/test                                 
  To initialize a project, please create a composer.json file as described in the https://getcomposer.or  
  g/ "Getting Started" section                                                                            

create-project [-s|--stability STABILITY] [--prefer-source] [--prefer-dist] [--repository REPOSITORY] [--repository-url REPOSITORY-URL] [--dev] [--no-dev] [--no-custom-installers] [--no-scripts] [--no-progress] [--no-secure-http] [--keep-vcs] [--remove-vcs] [--no-install] [--ignore-platform-reqs] [--] [<package>] [<directory>] [<version>]

Some context: I recently updated my Homestead vagrant box to v8.0.0 and Homestead source code to v9.0.1 (and then downgraded to v8.0.1 due to strange behaviour as described here). The create-project problem reported above occurs using both Homestead v9.0.1 and v8.0.1.

UPDATE

I tried adding an empty composer.json file to the "test" folder, but that results in a "./composer.json" does not contain valid JSON error.

I even copied in the composer.json file from the laravel/laravel project, but that results in a Could not scan for classes inside "database/seeds" which does not appear to be a file nor a folder run-time exception (which is correct because the "test" folder comprises only a "vendor" folder, a composer.json file and a composer.lock file).

I've been going around in circles for a couple of days now, so any assistance would be greatly appreciated.

w5m
  • 2,286
  • 3
  • 34
  • 46
  • You could try to create an empty composer.json file as the error suggests – Borjante Jul 05 '19 at 11:07
  • Thanks for the suggestion. I had already tried that and also copying in a composer.json file from the laravel/laravel project (see updated question) to no avail. – w5m Jul 05 '19 at 11:22
  • Then it's most likely a permission issue. verify that the user/group has write permissions for /home/vagrant/code/test directory – Borjante Jul 05 '19 at 12:25
  • Thanks @Borjante setting permissions (`sudo chmod -R a+rwx /home/vagrant/code/test`) seems to have resolved the composer.json error and the create-project process gets past writing the lock file. However, when it then attempts to call `@php artisan package:discover` I get the 'Unable to load the "app" configuration file.' error as described in my first link. This is strange as the app.php file exists and the permissions on the "code" folder, the "test" subfolder, the "config" subfolder and the app.php file are all 777. Any thoughts? – w5m Jul 05 '19 at 13:59

1 Answers1

1

So it turned out to be a permission problem, great.

What I do, and I don't use Homestead but Docker (it is similar though) is, I DON'T run Composer commands nor Laravel commands from the HOST, but from inside the virtual machine.

That way you don't have to sudo chmod -R a+rwx /home/vagrant/code/test which is bad (as it gives user, group and others read/write/execute permissions)

Just ssh into your Homestead machine, run composer create-project --prefer-dist laravel/laravel test and later php artisan package:discover and you should avoid all this trouble.

w5m
  • 2,286
  • 3
  • 34
  • 46
Borjante
  • 9,767
  • 6
  • 35
  • 61
  • That was more out of desperation (and obviously only for my local environment). Just to confirm, I had been running all commands from within the Homestead VM (after SSHing in) and not from the Host, as I don't have composer installed on my Host. – w5m Jul 05 '19 at 15:45
  • Please paste the full second error then, the one that pops when you execute `php artisan package:discover` – Borjante Jul 05 '19 at 15:47
  • The second error is exactly the same as https://stackoverflow.com/q/56857532/2047725 and I've coded an alternative that works - which I've posted as an answer there. I do however feel like I'm addressing the symptoms of the problem rather than the cause, as now when I run `php artisan migrate:refresh --seed` the migrations run happily but the seeding fails with `ReflectionException : Class DatabaseSeeder does not exist` despite DatabaseSeeder.php residing in the expected database/seeds folder. Everything was working nicely before I updated Homestead vagrant box & Homestead source code. – w5m Jul 05 '19 at 17:00
  • And I've tried `composer dump-autoload` but it still fails to recognise the existence of the `DatabaseSeeder` class. – w5m Jul 05 '19 at 17:02