I have a composer file for a laravel installation with the following composer.json file:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"laravel/framework": "4.1.*"
},
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
},
"minimum-stability": "stable"
}
I'm trying to add in the bundle for sentry. On sentry's website it says I can install it by adding the following to my composer.json file:
{
"require": {
"cartalyst/sentry": "2.0.*"
},
"minimum-stability": "dev"
}
I tried adding the new json object at the end of the current laravel one like so:
...
},
{
"require": {
"cartalyst/sentry": "2.0.*"
},
"minimum-stability": "dev"
}
When I run the composer update command to load the new package I get an error saying that the new object addition is not valid json.
If I add the cartalyst/sentry to the existing require object it cannot find the sentry package because the existing requires have a minimum-stability value of stable.
Is there a way of specifying the sentry package in a separate require object that has the minimum-stability setting of dev?
The answer is just add #dev
{
"require": {
"cartalyst/sentry": "2.0.*#dev"
},
}
You can read more about minimum stability settings here.
An alternative is to set your minimum-stability to dev, but tell composer you want to use stable whenever possible:
"minimum-stability": "dev",
"prefer-stable" : true
This basically means it will always use stable UNLESS there is no way to install a stable dependency, and therefore use dev.
You can also use other levels of stability, like alpha, beta combined with version selector.
Examples
With caret operator - maximum of version 2 allowing beta:
"cartalyst/sentry": "^2#beta"
Any version allowing alpha
"cartalyst/sentry": "*#alpha"
From the composer documentation:
To allow various stabilities without enforcing them at the constraint level however, you may use stability-flags like # (e.g. #dev) to let Composer know that a given package can be installed in a different stability than your default minimum-stability setting.
https://getcomposer.org/doc/articles/versions.md#stability-constraints
Related
My project is a Laravel implementation. I have created a composer.json file as follows:
{
"name": "company/project",
"description": "My cool project.",
"type": "project",
"license": "proprietary",
"require": {
"laravel/laravel": "8.*"
}
}
I can put this file in its own directory and run composer install. This installs version 8 of laravel/laravel and all dependencies in the vendor/ directory. But this is not a valid Laravel installation. If I then move the contents of vendor/laravel/laravel up into the main directory, copy .env.example to .env and run composer -o dump-autoload, then I have a directory structure that looks (as far as I can tell), just like a standard Laravel installation.
However, when I try to access the site from by browser, I get a 500 Server Error, with no apparent entries in the Apache or Laravel logs.
I know this is not an Apache configuration error because I can create exactly the same site using the command composer create-project laravel/laravel:8.* {directory}, and I get a function basic Laravel site.
My ultimate goal is to use composer to install my project AND Laravel, with all of it's dependencies, and get a functioning site. I am particularly interested in being able to lock all of the dependencies (including the specific version of laravel/laravel) via the composer.lock file, which will then be included with the version-controlled source of my project.
You may ask why I don't just use the recommended command to create a clean Laravel installation and just version-control the resultant composer.lock file. The reason is: That file does not contain the specific version of laravel/laravel. So when I then user the composer.json/lock files in a clean directory, the core laravel/larvel files are missing.
Any pointers as to what I am doing wrong? Or is there a simpler way to achieve my goal?
Your composer.json only requires "laravel/laravel": "8.*", but Laravel needs a lot more to function properly. When I do a composer create-project laravel/laravel it generates a composer.json with the following:
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"php": "^7.3|^8.0",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"laravel/framework": "^8.54",
"laravel/sanctum": "^2.11",
"laravel/tinker": "^2.5"
},
"require-dev": {
"facade/ignition": "^2.5",
"fakerphp/faker": "^1.9.1",
"laravel/sail": "^1.0.1",
"mockery/mockery": "^1.4.2",
"nunomaduro/collision": "^5.0",
"phpunit/phpunit": "^9.3.3"
},
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"#php artisan package:discover --ansi"
],
"post-update-cmd": [
"#php artisan vendor:publish --tag=laravel-assets --ansi"
],
"post-root-package-install": [
"#php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"#php artisan key:generate --ansi"
]
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
}
Now this does a lot more than just requiring a vendor-folder, these contain the namespace-declarations, scripts, and the requirements for a few more things.
And also note that this requires laravel/framework instead of laravel/laravel.
All in all I suggest using the full list from here and keep stripping until it breaks if you want to.
And on the subject of version pinning, you could either put the composer.lock-file in your VCS and only run composer install (that does not update if there is lock-file).
You could also remove the ^ from all the versions that you don't want to update, that way you can restrict a version with some room for updates if you want. 8.0.1 would keep at 8.0.1, but you could allow patches by specifying 8.0.* as a version-requirement.
In the end, I gave up trying to make this work. Instead, I now follow these steps to install a new site:
composer create-project --no-install --no-scripts laravel/laravel:{version} {SITE}
cd {SITE}
svn export --force {repo}/composer.json .
svn export --force {repo}/composer.lock .
composer install
svn co {repo} .
svn -R revert .
This allows me to create a site with the specific version of Laravel that I need.
I had a requirement in laravel, where i needed to some server side cropping using the the laravel package Imagine, now i followed the installation instruction for this package for my application, I.E. :
I added the below line in my composer.json file:
{
"require": {
"orchestra/imagine": "~3.0"
}
}
My composer.json file looks like below now:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"laravel/framework": "4.2.*",
"intervention/image": "dev-master",
"orchestra/imagine": "~3.0"
},
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
},
"minimum-stability": "stable"
}
Now when i run composer update from the terminal , i get the following messages:
and i have now followed THESE INSTRUCTIONS too, of adding the alias etc to the config/app.php,
Now when i try to load my admin panel , i get the following error:
Class 'Orchestra\Imagine\ImagineServiceProvider' not found
Why am i getting this error , can somebody explain ?
You are using laravel 4.2.* and imagine "~3.0" with it. imagine "~3.0" is for laravel 5.1. So try using correct version. Version compatibility image below
I do not understand where this error is coming from. I first noted it after installing a third party package, and thought that was the problem. Uninstalling the package made no difference. Reverting to an earlier version of Laravel also had no effect. (So now I'm back to the current version, 4.2.8.)
Here is the full error message in response to $ composer update -- the error is repeated 7 times, right after "Generating autoload files":
PHP Warning: Unexpected character in input: ' in phar:///usr/local/bin/composer/src/Composer/Autoload/ClassMapGenerator.php on line 118
This appears to refer to a corrupted piece of code in composer itself, rather than a corrupted file in the Laravel tree. My copy of composer lives in /usr/local/bin and the only file in that directory is composer. The warning appears to suggest that composer is a directory, but of course it's not. There is nothing on line 118 in composer itself.
I have no idea how to fix this, or how important it is, or how to find where the problem is. Do I need to reinstall composer?
Thanks for any help.
In response to a comment asking about whether composer.json is the problem, here's my entire composer.json file. I can't identify any errors there:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"laravel/framework": "4.2.*"
},
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php",
"app/libraries"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
},
"minimum-stability": "stable"
}
And here's lines 116-123 from composer.lock -- could the problem be here? :
"autoload": {
"psr-0": {
"Whoops": "src/"
},
"classmap": [
"src/deprecated"
]
},
Thanks.
Problem solved simply by running
composer self-update
Thanks much to help from Marwelln and WereWolf.
When I try to run composer update, I get the following error:
[RuntimeException]
Error Output: '$_' is not recognized as an internal or external command,
operable program or batch file.
I am not sure why this happens, but I have tried updating composer itself (which runs successfully) and it does not work. Composer usually works just fine, so I am a little bit confused.
Added composer file:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"laravel/framework": "4.1.*",
"bogardo/mailgun": "dev-master"
},
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
},
"minimum-stability": "stable"
}
I seem to have solved my problem. I need to keep the scripts because it powers my deployment. I needed to run composer update --no-scripts and it worked perfectly.
I think the problem is located in your code.
Try to run
php artisan
if the error gets thrown also it is a problem in your code.
composer
fails also because in the
scripts
section you run php artisan.
try this command composer update --ignore-platform-reqs
I'm using the Laravel framework and wanted to include a library from GitHub. This is my full composer.json file:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"laravel/framework": "4.0.*",
"intervention/helper": "dev-master" <- this is what I've added
},
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/validators",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
},
"minimum-stability": "dev"
}
I've added "intervention/helper": "dev-master" under the require directive and when I do composer update on my local copy of the website, everything works fine and I can use the library.
I did a git push and pull to get it onto my live server, and when doing a composer update it doesn't download this library. This is the entire output of the command: http://pastebin.com/UgPNTaDw
I also tried composer install and composer update for a second time but neither worked. I've also verified that git retrieved the new composer.json file on the live server, and it has.
Why isn't composer recognizing the changes and downloading the library?
Besides the fact that your log does exactly tell you the "missing" library was downloaded, I have some general comment:
Are you sure you want to use EVERY library in DEVELOPMENT quality? Because that is what you enabled with the "minimum stability" flag: You are allowing EVERYTHING in possibly broken state from whatever development branch the libraries provide.
And the second thing is: You are supposed to update only once, on your development machine! Then test that everything still is working, and commit the composer.lock file!
Then push and pull that change to wherever you need it, and there only composer install - because you probably want the exact SAME library versions that you tested with, not anything slightly newer with possibly broken commits.
If you only want to use that particular library as development version, you should add that flag to the version requirement:
"intervention/helper": "dev-master#dev"
On the other hand, this library has released versions, so it might be better to require them...