PHP Fatal error when trying to install Laravel 5 with Composer - php

I'm trying to run composer to install Laravel 5.0.14, and am also trying to test this code out in Jenkins using the Jenkins php-template.
Whenever I run composer update, I get the following error:
Error Output: PHP Fatal error: Call to undefined method
Illuminate\Foundation\Application::redirectIfTrailingSlash()
in /var/lib/jenkins/jobs/Demo/workspace/bootstrap/start.php on line 16
If I remove the offending line in start.php, I obtain the following error when attempting to run composer update:
Error Output: PHP Catchable fatal error:
Argument 1 passed to Illuminate\Foundation\Application::detectEnvironment()
must be an instance of Closure, array diven, called in
/var/lib/jenkins/jobs/Demo/workspace/bootstrap/start.php on line 32
and defined in
/var/lib/jenkins/jobs/Demo/workspace/vendor/laravel/framework/src/Illuminate
/Foundation/Application.php
on line 402
This is my composer.json file:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"laravel/framework": "5.0.14",
"phpunit/phpunit": "4.7.*#dev",
"theseer/fxsl": "1.0.*#dev",
"theseer/phpdox": "0.6.6",
"squizlabs/php_codesniffer": "1.4.6",
"phpmd/phpmd": "2.0.0",
"h4cc/phpqatools": "dev-master",
"phploc/phploc": "2.0.2",
"sebastian/phpcpd": "2.0.1",
"monolog/monolog": "1.13.0",
"patchwork/utf8": "1.2.1",
"phpdocumentor/phpdocumentor": "v2.0.1",
"mayflower/php-codebrowser": "1.1.0-beta1",
"pear/console_commandline": "dev-trunk",
"pear/log": "dev-master",
"pear/pear_exception": "1.0.0",
"phing/phing": "2.6.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 optimize"
],
"pre-update-cmd": [
"php artisan clear-compiled"
],
"post-update-cmd": [
"php artisan optimize"
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
},
"minimum-stability": "dev"
}
I can run composer update --no-scripts.
I've searched for any composer.php files with sudo find . -print | grep -i 'compiled.php'. The only one I have is ./vendor/symfony/dependency-injection/Tests/Fixtures/php/services9_compiled.phpwhich does not correspond with the compiled.php file several other people have suggested deleting for other people who have had this problem.

I think you are using a Laravel 4 composer.json. One of the big changes from Laravel 4 to Laravel 5 is the usage of namespaces.
Also a lot of paths have been modified, so just installing Laravel 5 over an existing Laravel 4 is not possible.
Better to install a fresh Laravel 5 and follow this guide:
http://laravel.com/docs/master/upgrade#upgrade-5.0
For reference here is my composer.json (notice the psr-4 in the autoload section)
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"laravel/framework": "5.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"
}
}

The composer file could be very well be 30 days older and not updated.
You would have to run this command from the path of the code folder using either a vitrtual box or cmd/gitbash/terminal:
curl -sS https://getcomposer.org/installer | php
once downloaded, move the composer.phar file to the composer folder , normally its located at:
sudo mv composer.phar usr/bin/local/composer
then run the composer update to regenerate the autoloaded files.

Related

PHP Fatal error: Uncaught ReflectionException: Class Kernel does not exist [duplicate]

I was trying to go live with a laravel project i developped a year back in school and i ran into some issue.
After uploading the whole project on my hosting service's server, i got these errors on my browser as well as on my SSH shell.
Fatal error: Uncaught exception 'ReflectionException' with message 'Class App\Http\Kernel does not exist' in /home/clients/ffa41f94063541f86a0fe6602a73caa1/myforms/vendor/laravel/framework/src/Illuminate/Container/Container.php:779
Stack trace: #0 /home/clients/ffa41f94063541f86a0fe6602a73caa1/myforms/vendor/laravel/framework/src/Illuminate/Container/Container.php(779): ReflectionClass->__construct('App\Http\Kernel') #1 /home/clients/ffa41f94063541f86a0fe6602a73caa1/myforms/vendor/laravel/framework/src/Illuminate/Container/Container.php(659): Illuminate\Container\Container->build('App\Http\Kernel', Array) #2 /home/clients/ffa41f94063541f86a0fe6602a73caa1/myforms/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(644): Illuminate\Container\Container->make('App\Http\Kernel', Array) #3 /home/clients/ffa41f94063541f86a0fe6602a73caa1/myforms/vendor/laravel/framework/src/Illuminate/Container/Container.php(229): Illuminate\Foundation\Application->make('App\Http\Kernel', Array) #4 /home/clients/ffa41f94063 in /home/clients/ffa41f94063541f86a0fe6602a73caa1/myforms/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 779
I think it could be related to my namespace configuration, because i haven't all understood yet.
Here is my composer.json file :
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"laravel/framework": "5.0.*",
"illuminate/html": "5.*",
"barryvdh/laravel-dompdf": "0.5.*",
"guzzlehttp/guzzle": "~4.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "myforms/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"
}
}
What I have already done :
Delete /vendor and make a new install with composer install
composer dump-autoload
composer update
btw, I get the error when I insert the composer update
Please inform me if i should post another file that could be useful.
Thanks in advance for your help.
In composer.json change:
"psr-4": {
"App\\": "myforms/app/"
}
to:
"psr-4": {
"App\\": "app/"
}
On the server, in your source directory, run composer update then composer dump-autoload
PSR-4 in Laravel looks for namespaces relative to the root of the project
Check if console/kernel.php is inside of app-folder, if not it might be inside of your laravelApp.
If so, move console/kernel.php to app-folder.
In my case composer.json was missing propper bracket closing "{ }" and line with "psr-4" was in wrong json segment.
Check composer.json for proper align of "psr-4" it should be child of "autoload" section.
Remove vendor
composer install
OK
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"laravel/framework": "5.0.*",
"illuminate/html": "5.*",
"barryvdh/laravel-dompdf": "0.5.*",
"guzzlehttp/guzzle": "~4.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "myforms/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"
}
}
With the help of the other answers here, I realised I'd just missed a change when manually updating from Laravel 5.5 to 5.7
In composer.json, I'd missed this from the autoload block:
"autoload": {
"psr-4": {
"App\\": "app/"
},
...
},
If you're using version control, run composer update on your dev machine to update composer.lock. Then on your production server, you should only need to run composer install

Laravel 5.3 Uploading in ubuntu16.04 nginx with command composer install --no-dev

Everytime I run the command composer install --no-dev
I am getting this error, I am using maatwebsite in laravel as the error pointing out, I just don't know how to fix it.
PHP Fatal error: Uncaught
Symfony\Component\Debug\Exception\FatalThrowableError
: Class 'PHPExcel_Shared_Font' not found in
/var/www/laravel/config/excel.php:18
2 Stack trace:
0 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap
/LoadConfiguration.php(60): require()
1 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap
/LoadConfiguration.php(38):
Illuminate\Foundation\Bootstrap\LoadConfiguration->l
oadConfigurationFiles(Object(Illuminate\Foundation\Application),
Object(Illumina
te\Config\Repository))
2 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Applicati
on.php(203):
Illuminate\Foundation\Bootstrap\LoadConfiguration->bootstrap(Object
(Illuminate\Foundation\Application))
3 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Console/K
ernel.php(268):
Illuminate\Foundation\Application->bootstrapWith(Array)
4 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Console/K
ernel.php(114): Illuminate\Foundation\Console\Kernel->boo in
/var/www/laravel/co
nfig/excel.php on line 182 Script php artisan optimize handling the
post-install-cmd event returned with er
ror code 255
Update:
This is the composer.json file content
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.6.4",
"laravel/framework": "5.3.*"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~5.0",
"symfony/css-selector": "3.1.*",
"symfony/dom-crawler": "3.1.*",
"maatwebsite/excel": "~2.1.0"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-root-package-install": [
"php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
],
"post-install-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postInstall",
"php artisan optimize"
],
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
"php artisan optimize"
]
},
"config": {
"preferred-install": "dist"
}
}
I would assume the reason you getting this error is because you're running --no-dev and you have maatwebsite/excel listed as a require-dev dependency.
You'll need to remove it as a dev dependency and then require it as a normal dependency and it should be fine.
Hope this helps!

Laravel error 'ReflectionException' - 'Class App\Http\Kernel does not exist'

I was trying to go live with a laravel project i developped a year back in school and i ran into some issue.
After uploading the whole project on my hosting service's server, i got these errors on my browser as well as on my SSH shell.
Fatal error: Uncaught exception 'ReflectionException' with message 'Class App\Http\Kernel does not exist' in /home/clients/ffa41f94063541f86a0fe6602a73caa1/myforms/vendor/laravel/framework/src/Illuminate/Container/Container.php:779
Stack trace: #0 /home/clients/ffa41f94063541f86a0fe6602a73caa1/myforms/vendor/laravel/framework/src/Illuminate/Container/Container.php(779): ReflectionClass->__construct('App\Http\Kernel') #1 /home/clients/ffa41f94063541f86a0fe6602a73caa1/myforms/vendor/laravel/framework/src/Illuminate/Container/Container.php(659): Illuminate\Container\Container->build('App\Http\Kernel', Array) #2 /home/clients/ffa41f94063541f86a0fe6602a73caa1/myforms/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(644): Illuminate\Container\Container->make('App\Http\Kernel', Array) #3 /home/clients/ffa41f94063541f86a0fe6602a73caa1/myforms/vendor/laravel/framework/src/Illuminate/Container/Container.php(229): Illuminate\Foundation\Application->make('App\Http\Kernel', Array) #4 /home/clients/ffa41f94063 in /home/clients/ffa41f94063541f86a0fe6602a73caa1/myforms/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 779
I think it could be related to my namespace configuration, because i haven't all understood yet.
Here is my composer.json file :
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"laravel/framework": "5.0.*",
"illuminate/html": "5.*",
"barryvdh/laravel-dompdf": "0.5.*",
"guzzlehttp/guzzle": "~4.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "myforms/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"
}
}
What I have already done :
Delete /vendor and make a new install with composer install
composer dump-autoload
composer update
btw, I get the error when I insert the composer update
Please inform me if i should post another file that could be useful.
Thanks in advance for your help.
In composer.json change:
"psr-4": {
"App\\": "myforms/app/"
}
to:
"psr-4": {
"App\\": "app/"
}
On the server, in your source directory, run composer update then composer dump-autoload
PSR-4 in Laravel looks for namespaces relative to the root of the project
Check if console/kernel.php is inside of app-folder, if not it might be inside of your laravelApp.
If so, move console/kernel.php to app-folder.
In my case composer.json was missing propper bracket closing "{ }" and line with "psr-4" was in wrong json segment.
Check composer.json for proper align of "psr-4" it should be child of "autoload" section.
Remove vendor
composer install
OK
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"laravel/framework": "5.0.*",
"illuminate/html": "5.*",
"barryvdh/laravel-dompdf": "0.5.*",
"guzzlehttp/guzzle": "~4.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "myforms/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"
}
}
With the help of the other answers here, I realised I'd just missed a change when manually updating from Laravel 5.5 to 5.7
In composer.json, I'd missed this from the autoload block:
"autoload": {
"psr-4": {
"App\\": "app/"
},
...
},
If you're using version control, run composer update on your dev machine to update composer.lock. Then on your production server, you should only need to run composer install

Fatal error: Class ... not found in ... /ProviderRepository.php on line 146

This sounds like a trivial mistake, but I've been unable to find the solution for hours.
I tried to use https://github.com/michaelbonds/laravel-db2 in my Laravel project, and I added it using composer.
Here's my composer.json.
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.1.*",
"michaelb/laravel-db2": "~2.0"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"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"
],
"pre-update-cmd": [
"php artisan clear-compiled"
],
"post-update-cmd": [
"php artisan optimize"
],
"post-root-package-install": [
"php -r \"copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
}
}
Here's the error:
PHP Fatal error: Class 'MichaelB\Database\DB2\DB2ServiceProvider' not found in /var/www/html/mysjsu/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php on line 146
and
[Symfony\Component\Debug\Exception\FatalErrorException]
Class 'MichaelB\Database\DB2\DB2ServiceProvider' not found
I found a similar question before on StackOverflow, and somebody suggested that the order matters. So, here's what I did in the following order:
add "michaelb/laravel-db2": "~2.0" to composer.json
run php ../composer.phar update
add MichaelB\Database\DB2\DB2ServiceProvider::class to the providers arary in config/app.php
run php artisan migrate
Any idea on what might've been the problem?
This package is a fork of cooperl/laravel-db2. The documentation is inaccurate.
He changed the namespace to MichaelB but never tagged this as a stable version, so when you composer require his ~2.0, packagist gives you an older version with the wrong namespace.
So when you run composer update, it runs some post-cmd scripts such as php artisan optimize which tries to pull from the config file but fails because that class doesn't exist.
Here's how to fix it:
Change composer.json to this version:
"michaelb/laravel-db2": "dev-master"
Run composer update --no-scripts
Then you should be good.

Cannot load packages nor custom app folders in Laravel, dump-autoload doesn't work

I have a completely default set up of Laravel framework. To include an external library (TwitterOAuth, to be precise), I'm trying to use packages. Besides the official documentation, I followed this tutorial step-by-step to create my package. However, when I try to put it to action, I see
Class 'Abraham\TwitterOAuth\TwitterOAuthServiceProvider' not found
I saw that to solve this problem, I need to do "artisan dump-autoload" in the root of my project folder or in the package folder. I tried both. Whether I execute this command from the root folder or from the package folder, I get "Class not found" exception.
If before doing dump-autoload, I remove the class from "providers" array in /app/config/app.php, and try to launch the command in the root folder, the last thing I see is
Running for workbench [abraham/twitteroauth]...
And then it gets done without any reports. What is the way to include packages in Laravel?
P.S.: sorry, I'm not including the code, because there's a lot. But basically, it's adjusted code from the tutorial mentioned above.
UPD: I tried to run "composer dump-autoload -o", it finishes successfully, but the problem is still there. Here's the code of composer.json in the root folder:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"laravel/framework": "4.2.*"
},
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/models/validators",
"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"
}
And the one in the package folder:
{
"name": "abraham/twitteroauth",
"description": "",
"authors": [
{
"name": "Abraham Williams",
"email": "abraham#abrah.am"
}
],
"require": {
"php": ">=5.4.0",
"illuminate/support": "4.2.*"
},
"autoload": {
"psr-0": {
"Abraham\\TwitterOAuth": "src/"
}
},
"minimum-stability": "stable"
}

Categories