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.
Related
after upgrading Laravel according to the docs to v7 I ran composer update. Then I'm getting this:
Script #php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 255
This is my composer.json file:
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require": {
"php": "^7.1.3",
"fideloper/proxy": "^4.0",
"guzzlehttp/guzzle": "^6.5",
"kitetail/zttp": "^0.6.0",
"laravel/framework": "^7.0",
"laravel/tinker": "^2.0",
"laravel/telescope": "^2.1",
"laravelcollective/html": "^6.0",
"livewire/livewire": "^0.7.4",
"spatie/laravel-html": "^2.24",
"spatie/laravel-permission": "^3.0.0"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.2",
"filp/whoops": "^2.0",
"fzaninotto/faker": "^1.4",
"laravel/ui": "^2.0",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^4.1",
"phpunit/phpunit": "^7.5"
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"autoload": {
"psr-4": {
"App\\": "app/"
},
"classmap": [
"database/seeds",
"database/factories"
]
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"#php artisan package:discover --ansi"
],
"post-root-package-install": [
"#php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"#php artisan key:generate --ansi"
]
}
}
I'm confused right now. It even seems that php artisan doesn't do anything in this project. In other projects it's just working fine. Any idea how this could be fixed?
Edit: Some of the answers provided suggestions. I'm getting the following using Laragon:
PS C:\laragon\www\attila> composer update
Updating dependencies (including require-dev)
Package operations: 0 installs, 4 updates, 0 removals
- Updating laravel/framework (v7.0.1 => v7.0.2): Downloading (100%)
- Updating spatie/laravel-permission (3.10.1 => 3.11.0): Downloading (100%)
- Updating laravel/ui (v2.0.0 => v2.0.1): Downloading (100%)
- Updating nunomaduro/collision (v4.1.1 => v4.1.2): Downloading (100%)
Package moontoast/math is abandoned, you should avoid using it. Use brick/math instead.
Writing lock file
Generating optimized autoload files
> #php artisan package:discover --ansi
Script #php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 255
PS C:\laragon\www\attila> php artisan package:discover --ansi
PS C:\laragon\www\attila>
After deleting all the cache in bootstrap & storage/framework folders, still no results.
Running the php artisan --help returns some errors, this gave me a hint where the problem is.
After checking the Upgrade Guide I solved the issue, for me it was:
Changes in App\Exceptions\Handler methods
install require laravel/ui package
For me, it was a very simple error and fix.
The relevant portion of the 7.x Upgrade docs says the following:
Symfony 5 Related Upgrades Likelihood Of Impact: High
Laravel 7 utilizes the 5.x series of the Symfony components. Some
minor changes to your application are required to accommodate this
upgrade.
First, the report, render, shouldReport, and renderForConsole methods
of your application's App\Exceptions\Handler class should accept
instances of the Throwable interface instead of Exception instances:
use Throwable;
public function report(Throwable $exception);
public function shouldReport(Throwable $exception);
public function render($request, Throwable $exception);
public function renderForConsole($output, Throwable $exception);
Relevant file: ./App/Exceptions/Handler.php
Change: convert instances of "Exception" to "Throwable" (editor search and replace)
So, basically, once I put the change in place, 'php artisan' started to work again.
This included the package:discover command in the OP's composer.json (and mine).
I tried putting it back to Exception, and the artisan command would fail to do anything.
Change the occurrences of Exception to Throwable, and everything works. (My application only had the first two functions defined, though.)
So, it pays to pay attention to the documentation.
You must delete old files (cache). This commands should works:
cd bootstrap/cache/
rm -rf *.php
composer update
If you are work on regular user, add sudo before each command.
Try this :
cd bootstrap/cache/
rm -rf *.php
Then composer update again.
After following the upgrade guide in the docs some folks in the Laravel Discord chat guided me to update the Symfony 5 Related Upgrades.
I had to remove telescope (which I'm not using) too.
If you are using Laravel 7 for some reason while your install composer 3.x installed on your system. use following command:
composer require laravel/ui ^2.0
For last 3 days, I am trying to install laravel 5.5 in my system(windows 8.1) through composer and getting a series of errors one after other. So I am asking some questions in order to clear my doubts which are still doubted after more than 20-25 hour of research on various blogs and SO.
I have installed php 7 in c:\php.
After that, I have installed composer using composer installer and did nothing after that, like setting PATH on environment setting.
I found that I have to create a composer.json file which I have copied from Github and shown below, but I don't know where to keep this composer.json file so I created this file on C:\Users\MyPC (i.e. my home directory).
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=7.0.0",
"fideloper/proxy": "~3.3",
"laravel/framework": "5.5.*",
"laravel/tinker": "~1.0"
},
"require-dev": {
"filp/whoops": "~2.0",
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~6.0"
},
"autoload": {
"classmap": [
"database/seeds",
"database/factories"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"extra": {
"laravel": {
"dont-discover": [
]
}
},
"scripts": {
"post-root-package-install": [
"#php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"#php artisan key:generate"
],
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"#php artisan package:discover"
]
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
}
}
Please check the code above if I have committed any mistake.
After that I executed "composer update" command which downloaded a lot of files and placed in C:\Users\MyPC\vendor folder (I think), but throws an error at last which I can't remember.
After that I executed "composer install" command and get this error shown below.
This is my problem and I am not able to figure out what to do.
I have a couple of more doubt:
a - composer create-project --prefer-dist laravel/laravel NAME_OF_PROJECT can also be used to set up new project then why we use composer global require “laravel/installer” and then laravel new NAME_OF_PROJECT method. What are the benefits of using this method.
b - What are the steps to follow after the installation of the composer using the installer for setting up a new laravel project. What are the best practices to structure the project folder?
Please help me. I am learning laravel but don't know how to deal with this composer stuff and installing laravel as most or all of the tutorial starts with creating new project file .they don't teach how to install them.
Ok so a lot of research and try and errors I figured out a way that worked for me. I am using Windows 8.1.
I have installed php 7 in c:\php.
Note : Download php from
http://php.net/downloads.php. Download Non Thread Safe
version in zip format and extract it to the
desired folder (I extracted in C:\php).
After that I have installed composer using composer installer and did nothing after that, like setting PATH on environment setting, Installer will do it for you.
Download Composer Installer from https://getcomposer.org/download/.
After that I have downloaded laravel from github and exctrated to the desired project folder.
Download Laravel latest version from https://github.com/laravel/laravel
After that I ran "composer self-update"command.
After that I ran "composer update"command.
After that I ran "composer global require “laravel/installer”"command. This command will install Laravel Installer.
Now I can go to the project folder directory and run "laravel new myProjectName" command to create new laravel project.
I'm new to PHP Laravel. I've added a package using composer: composer require djchen/oauth2-fitbit. It seems that my composer.json did not update the autoloader as i keep getting the following error:
Fatal error: Class 'djchen\OAuth2\Client\Provider\Fitbit' not found in xxx on line 5.
this is what line 5 looks like:
use djchen\OAuth2\Client\Provider\Fitbit;
$provider = new Fitbit([ // line 5
Here is my composer.json (necessary bits)
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "vcs",
"require": {
"php": ">=5.6.4",
"djchen/oauth2-fitbit": "^1.0",
"laravel/framework": "5.4.*",
"laravel/tinker": "~1.0"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~5.7"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/",
"djchen\\OAuth2\\Client\\": "src/" // added manually - still does not work
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/",
}
},
I've done my research and i've tried composer install, composer update and composer dump-autoload. None of these worked. Any help would be appreciated.
Let's go with the nuclear solution here, your autoload file probably is cached somewhere.
Run following commands:
php artisan clear-compiled
php artisan cache:clear
php artisan config:clear
php artisan optimize
If this doesn't work, try to manually delete all autoload files you can find and run a composer update.
Answering my own question..
I probably should have really emphasised the fact that I'm new to Laravel. I managed to get around this by simply including the autoloader:
include('vendor/autoload.php');
And also calling composer dump-autoload afterwards.
I've created my laravel project with create-project beacause composer install didn't work.
cd to my project and then, when I try to use php artisan list or any artisan command it just says:
Could not open input file: artisan
How do I fix this? the vendor file is in the project
My composer.json:
{
"name": "vendor_name/package_name",
"description": "description_text",
"minimum-stability": "stable",
"license": "proprietary",
"authors": [
{
"name": "author's name",
"email": "email#example.com"
}
],
"require": {
"barryvdh/laravel-ide-helper": "^2.0"
}
}
path to my project:
c:\wamp\www\project1
Inside vendor, no folder named artisan is showed
Use the project's root folder
Artisan comes with Laravel by default, if your php command works fine, then the only thing you need to do is to navigate to the project's root folder. The root folder is the parent folder of the app folder. For example:
cd c:\Program Files\xampp\htdocs\your-project-name
Now the php artisan list command should work fine, because PHP runs the file called artisan in the project's folder.
Now install the laravel framework
Keep in mind that Artisan runs scripts stored in the vendor folder, so if you installed Laravel without Composer, like downloading and extracting the Laravel GitHub repo for laravel, then you don't have the framework itself and you may get the following error when you try to use Artisan:
Could not open input file: artisan
To solve this you have to install the framework itself by running composer install in your project's root folder.
Have you tried to do a "ls" (linux) or a "dir" (win) to make sure you are in the correct folder?
Check if you have correctly installed php.
Run cmd or shell and try to run
php -v
I'm going to assume you have Windows as your OS.
Go to Control Panel -> System and Security -> System -> Advanced system settings.
Then go to Environment Variables, find "Path" and add
;your/path/to/php.exe
at the end.
Replace "your/path/to/" with your current php.exe directory (including C:\ )
EDIT
Try with this one:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"laravel/framework": "5.0.*",
"barryvdh/laravel-ide-helper": "^2.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"classmap": [
"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 -r \"copy('.env.example', '.env');\"",
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
}
}
I'm using windows 10, today is 31st dec, 2016.
I had the same issue, did a bit of a research and solved it.
First go to vendor directory from your laravel project directory and run this command:
composer install
if it further shows an error and asks for the composer.json file missing then:
cd ../
composer install
This fixed my issue!
I don't know if this has been solved, but I found this to be useful:
composer require laravel/passport --ignore-platform-req=ext-fileinfo
I am trying to use Mandrill to send emails via my Laravel framework, however I am receiving the following error:
FatalErrorException in MandrillTransport.php line 114: Class
'GuzzleHttp\Client' not found
I have installed Guzzle using the following command in Terminal:
"guzzlehttp/guzzle": "~4.0"
According to Laravel's documentation I need to add "guzzlehttp/guzzle": "~4.0" to my composer.json file, but I'm not sure if where I have placed it is correct as I still see the error.
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"laravel/framework": "5.0.*",
"illuminate/html": "^5.0",
"guzzlehttp/guzzle": "~4.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"classmap": [
"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 -r \"copy('.env.example', '.env');\"",
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
}
}
Here is the list of packages my application has, notice that guzzle has a different version: 4.2.3 which i've also tried updating to but still get the same error.
Open up your terminal at the root of your project and enter
composer require guzzlehttp/guzzle
It worked for the mailgun API. For some reason, the suggested method at the laravel's mail doc. You may install this package to your project by adding the following line to your composer.json file
"guzzlehttp/guzzle": "~5.3|~6.0"
doesn't make the composer download the Guzzle source codes. By the way, I didn't find out what | means in determining the version. This command just downloads the PSR code.
In this moment, the solution may work. However, be aware of compatibility issues. Because the command would install the latest stable version, not the suitable one.
If you're using Laravel when you run into this error, just run:
composer require guzzlehttp/guzzle
And try again.
After updating your composer.json file you need to run the update command to resolve and install your dependencies:
composer update
or, if composer isn't in your path:
php composer.phar update
Did you try :
artisan clear-compiled
or if artisan is not available try to remove compiled.php if exist (in vendor directory) and launch composer dumpautoload
I had the same issue.
I used an old version in order to work.
It's not working anymore since version 4.
It works on version 3.8.1
So you can add "guzzlehttp/guzzle": "~3" to works
simple in my case add "guzzlehttp/guzzle": "^6.3" in composer.json
require object as mentioned below
"require": {
"php": ">=7.0.0",
"ext-gd": "*",
"barryvdh/laravel-cors": "^0.11.2",
"barryvdh/laravel-dompdf": "^0.8.1",
"dingo/api": "2.0.0-alpha1",
"doctrine/dbal": "^2.6",
"fideloper/proxy": "~3.3",
"guzzlehttp/guzzle": "^6.3",
"intervention/image": "^2.4",
"laravel/framework": "5.5.*",
"laravel/tinker": "~1.0",
"league/flysystem-aws-s3-v3": "~1.0",
"predis/predis": "^1.1",
"tymon/jwt-auth": "dev-develop"
},
than run composer update in project root using terminal than its working fine.
I am oblivious to why this worked for me, I saw this in a forum somewhere
I just added this captcha generator to the composer.json file
"mews/captcha": "~2.0.",
added it to all the require package
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.1.*",
"laravelcollective/html": "5.1.*",
"laracasts/flash": "~1.3",
"mews/captcha": "~2.0.",
"guzzlehttp/guzzle": "~4.0"
},
If someone knows why this worked it would really scratch the itch in my brain.
I got this error when I tried running my code outside of the Laravel framework while testing in a stand alone file. It worked for me when I moved it inside a controller.
You can solve this problem to add "mews/captcha": "1.0.1" and "guzzlehttp/guzzle": "~4.0" to your composer.json file. And then you need run composer update command on your terminal.
I have tried on Laravel 4. It works for me.
Try updating your composer to latest version might end sorting your problem. This worked out for me. Ubuntu/Linux users use this tutorial in Digital ocean