0
votes

I'm trying to install Laravel with composer on Windows 7 and am running into an error. This is the command I'm running:

composer global require "laravel/installer=~1.1"

This is the error I get:

file_put_contents(C:\Users\myUser\AppData\Roaming\Composer/vendor/composer/installed.json): failed to open stream: No such file or directory

It's correct to say that the installed.json file does not exist, there's not even a composer folder inside the vendor folder. Not sure why that would be missing. I installed composer using the Windows installer.

Seems to be a composer related issue rather than laravel. I just tried installing yii and am getting a similar error running this:

composer create-project --prefer-dist yiisoft/yii2-app-basic MyApp

For this one, I get this after it successfully creates the folder and seems to load most files:

file_put_contents(C:\wwwroot\MyApp/vendor/composer/installed.json): failed to open stream: No such file or directory

Seems like the problem is that I never have a composer folder in my vendor folder.

UPDATE

I was able to get laravel to install globally by adding the COMPOSER_HOME environment variable. But I still run into a similar error when setting up a Laravel project after that

UPDATE 2

Some additional info, when I use the Windows Installer, composer gets installed in c:\ProgramData\ComposerSetup\bin. If I set the COMPOSER_HOME environment variable to this, laravel can get installed globally. But trying to install a project using the "laravel new MyApp" throws the following error:

Parse error: syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in C:\wwwroot\MyApp\artisan on line 31

I suspect that's because I have PHP 5.4 and the latest version of laravel is 5.6 and above, but I want to install 5.0, which is 5.4 and above. I tried doing it using "composer create-project laravel/laravel MyApp 5.0 --prefer-dist" instead. I get the following error:

file_put_contents(c:\wwwroot\MyApp/vendor/composer/installed.json): failed to open stream: No such file or directory

Seems there's just something weird going on with paths that I can't quite figure out.

UPDATE 3

I've now uninstalled composer and re-installed it manually per the instructions provided on the composer site. I'm now trying to create a project using the following command from c:\wwwroot:

composer create-project laravel/laravel c:\wwwroot\MyApp --prefer-dist

It does manage to install some stuff, but seems I get this error before any package it tries to install:

Installing laravel/laravel (v5.1.4)
Loading from cache
Failed to download laravel/laravel from dist: RecursiveDirectoryIterator::__construct(C:\wwwroot/vendor/composer/,C:\wwwroot/vendor/composer/): The system cannot find the path specified. (code: 3)

Again, seems like it can't create a directory for vendor/composer for some reason. I tried running the same command, but from inside an empty c:\wwroot\MyApp folder, same result except the path in the error changes accordingly.

I found the following: https://getcomposer.org/doc/articles/troubleshooting.md#-the-system-cannot-find-the-path-specified-windows-

But I checked my registry and I have none of these entries. So still no clue.

3
Are you sure you're configuring your global paths correctly? In your error messages the paths switch from being backslashes to forwards slashes, which is certainly not normal.marblewraith
By "global paths", what exactly do you mean. The PATH environment variable? If so, as far as I know that should be fine. Other than that, I've tried setting COMPOSER_HOME, but I was getting the forward slash/backslash thing without it, so...Rocket04
Hmmm need more info, it works fine on my win7 machine, even though i have my env variables set up a little differently.marblewraith
Also how did you install the stack? Did you manually install apache, php, mysql and then put composer on top of it? are you using an installer such as xampp or wamp? Are you using a VM?marblewraith
If i may make a suggestion. As long as you have no other projects dependent on the local server stack you have now, uninstall all of it and use laragonmarblewraith

3 Answers

0
votes

It seems that your composer is not globally accessible. Try to add C:\Users{UserName}\AppData\Roaming\Composer\vendor\bin to your environment variable then restart your Shell or Command-Prompt so that updated Path variables is loaded. Now try to install laravel again.

Here is the detailed instruction:

  1. Go to Control Panel > Systems ans Security > System > Advanced system settings then navigate to envirinment variables then scroll down and locate the PATH then add a semi colon (;) at the end of the PATH string. This means you are declaring a new variable. Then paste the C:\Users{UserName}\AppData\Roaming\Composer\vendor\bin after (;) you have added, restart the command prompt and try to install laravel again.
0
votes

Uninstall composer and install it again, but this time do enable shell menu. Right click on the location (directory) where you want to create the project, select "use composer here", then "composer create-project laravel/laravel projectName --prefer-dist" should create your laravel project, default to latest version (5.1).

To specify your prefer version:

"composer create-project laravel/laravel 4.2 projectName --prefer-dist"
0
votes

I will suggest you to install Homestead (http://blog.teamtreehouse.com/laravel-homestead-on-windows) and do all the heavylifting there.

You just need to do homestead ssh to actually connect to your machine and then perform all your operations.

Windows is pretty unpredictable in that kind of situations and in web development in general.