2

I tried creating larvel 9 project using composer. Since my machine don't have php 8 installed on it. While running command composer create-project laravel/laravel --prefer-dist myapp, a laravel 8 project is created.

While running composer create-project laravel/laravel:^9.0 --prefer-dist myapp it gives me error as Could not find package laravel/laravel with version ^9.0 in a version installable using your PHP version, PHP extensions and Composer version. .

So, my question is, i dont want to install php8 on my machine rather i want to create a laravel 9 project using docker but i seems to get lost on it.

I did tried creating project using following command:

composer create-project laravel/laravel=9.* --ignore-platform-req your-project-name --prefer-dist

It gives me the same error as above Could not find package laravel/laravel with version ^9.0 in a version installable using your PHP version, PHP extensions and Composer version.

  • Does this answer your question? [Skip composer PHP requirement](https://stackoverflow.com/questions/26165101/skip-composer-php-requirement) – hassan May 22 '22 at 08:08
  • Since, i need to initialize a new laravel 9 project with composer. This one doesn't solves the issue. – Roshan Twanabasu May 23 '22 at 07:40

1 Answers1

1

You can create a docker container with PHP already installed in it and map it to your local drive:

docker run -it --rm -v $(pwd):/work -w /work php:alpine3.14

That works in bash. If you're in windows, replace the $(pwd) bit with the directory you want to create the project in.

This should give you a shell that allows you to use php without having it on your machine. You can try your project init there and it'll create the files on your local drive. You can exit by typing ctrl+d or typing exit.

If this image doesn't have what you want, you can try this one:

docker run -it --rm -v $(pwd):/work -w /work composer

Which already has composer installed.

For a full run, taking care of file ownership and with the correct instructions to composer, you'd want to run this:

docker run -it --rm -v $(pwd):/work -w /work -u 1000:1000 composer:latest create-project laravel/laravel=9.* --ignore-platform-reqs --no-scripts /work
Software Engineer
  • 15,457
  • 7
  • 74
  • 102
  • i tried this command. But the volume doesnot seems to persist. As the project is nowhere to be seen. ```docker run -it --rm -v $(pwd):/testdocker -w $(pwd) composer:latest create-project laravel/laravel=9.* --ignore-platform-reqs --no-scripts $(pwd)/testdoc``` – Roshan Twanabasu May 26 '22 at 10:23
  • Your working directory `-w` cannot be `pwd`, it has to be hard-coded to a specific path in the container. The same thing applies to the path at the end of the line. You should change the 2nd and 3rd `$(pwd)` into `/testdocker` (the final one should just be `/testdocker` alone, the `/testdoc` bit is also unnecessary. – Software Engineer May 26 '22 at 12:51
  • So, try: `docker run -it --rm -v $(pwd):/work -w /work composer:latest create-project laravel/laravel=9.* --ignore-platform-reqs --no-scripts /work` – Software Engineer May 26 '22 at 12:52
  • Assuming `pwd` works for you. It's a linux command, so if you're in windows it won't work. You can try this in wsl though, and it should work on a mac (probably). – Software Engineer May 26 '22 at 12:53
  • Yup, i did tried: ```docker run -it --rm -v $(pwd):/work -w /work composer:latest create-project laravel/laravel=9.* --ignore-platform-reqs --no-scripts /work ``` But the volume doesn't seems to persist. while creating project, composer does shows, that project is being created to my current directory. But poofs no files or any folder. – Roshan Twanabasu May 27 '22 at 06:39
  • 1
    Are you using linux? I just tried that command without any changes to it at all, and ended up with a directory on my laptop full of stuff (I don't really know php/larvel, so I can't tell if its the right stuff, but there is lots of stuff). It all had the wrong owner, so I have pasted a fix for that at the end of this comment. The whole process took less than a minute. To fix the file owner issue: `docker run -it --rm -v $(pwd):/work -w /work -u 1000:1000 composer:latest create-project laravel/laravel=9.* --ignore-platform-reqs --no-scripts /work` – Software Engineer May 27 '22 at 07:09
  • 1
    Yes i am using linux. Yup giving -u flag let the volume persist and have my project up and runing on my current directory. Thank a lot for the answer. – Roshan Twanabasu May 28 '22 at 15:25