Laravel - can't install from my source control - php

I need to automate my laravel project setup/upgrade on my production machine from source control.
I wrote a bash script to clone the source from the GIT repo and run the setup.
The git code is going to the folder /var/www/prod/mainapp/, so the following bash code is running after the git command:
cd /var/www/prod/mainapp/app/
composer install # composer update will not work as well
php artisan dump-autoload
php artisan optimize
I am getting the following error when the code reaches to: php artisan optimize
PHP Fatal error: Class 'App\Providers\SocialUserProvider' not found in /var/www/prod/mainapp/app/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php on line 146
in my app.php i have the following providers:
App\Providers\FacebookGraphProvider::class,
Torann\GeoIP\GeoIPServiceProvider::class,
App\Providers\SocialUserProvider::class,
this is 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.2.*",
"torann/geoip": "0.2.3"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"symfony/css-selector": "2.8.*|3.0.*",
"symfony/dom-crawler": "2.8.*|3.0.*"
},
"autoload": {
"classmap": [
"database",
"app/Facades",
"app/Services"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-root-package-install": [
"php -r \"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"
}
}

You need to add to the classmap the line that will tell who should be autoloaded. app/Providers
"classmap": [
"database",
"app/Facades",
"app/Services",
"app/Providers" //this is the missing part.
]

I've come across this a few times.
My workaround is to run
composer install --no-scripts
You are getting that error due to the pre install scripts in your composer.json file and by adding that flag to the install process you skip these scripts.
Once you have everything installed you can then just use composer install and composer update as you usually would.

Related

Composer hangs on "Resolving dependencies on SAT" between Moodle and Laravel used as a local plugin

I'm using a Laravel project as a local plugin of Moodle, using the composer/installer package. The layout of the project is:
// Moodle Application
- composer.json
- local/
- laravel-plugin/ <- here is the Laravel local plugin
- composer.json <- composer.json of Laravel plugin
The composer.json of the Moodle application
{
"name": "moodle/moodle",
"license": "GPL-3.0",
"description": "Moodle - the world's open source learning platform",
"type": "project",
"homepage": "https://moodle.org",
"require": {
"composer/installers": "~1.0",
"Pursuittech/sam": "dev-master" <- here is the Laravel local plugin
},
"require-dev": {
"phpunit/phpunit": "5.5.*",
"phpunit/dbUnit": "1.4.*",
"moodlehq/behat-extension": "3.33.1",
"mikey179/vfsStream": "^1.6"
},
"repositories": [
{
"type": "vcs",
"url": "git#github.com:Pursuittech/sam.git"
}
]
}
composer.json of the Laravel local plugin
{
"name": "Pursuittech/sam",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "moodle-local",
"require": {
"php": ">=5.6.4",
"laravel/framework": "5.4.*",
"laravel/tinker": "~1.0",
"composer/installers": "~1.0"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~5.7"
},
"autoload": {
"classmap": [
"database/seeds",
"database/factories"
],
"psr-4": {
"Api\\": "api/",
"App\\": "app/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"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",
"sort-packages": true,
"optimize-autoloader": true
}
}
When I try to install the Laravel plugin using php composer.phar -vvv update, I hang on "Resolving dependencies through SAT".
I found a similar question which has the problem when only dealing with Laravel 4.2 in isolation. I haven't been through everything in the list and will update when I have.
My question is, is it normal for "Resolving dependencies through SAT" to hang when combining large composer projects like Laravel and Moodle? Are there any immediate steps I can take to reduce the complexity of the problem?
try those steps maybe you will get more reasonable output, its probably conflict of package version (eg. one of the packages locked on version which does not satisfy other package)
try no-dev option first
composer update --no-dev -vvv
try updating package by package
composer update some/package --no-dev -vvv
try to delete vendor folder and composer.lock
finally check composer.json of each package and compare requirements search for versions which exclude themselves from working together

composer scripts use older php version

I host more and more sites on webfaction. Great provider! I ran into some problems though which I think are Linux related. Hope someone can help.
SSH command php -v defaults to an older version of php, So I created an alias in my .bash_profile:
alias composer="php70 $HOME/composer.phar"
alias php="php70"
When I preform a php -v now it returns PHP 7.0. So far, so good!
PHP 7.0.0 (cli) (built: Dec 4 2015 12:58:58) ( NTS )
But now when I run a composer install and put a php -v in the scripts -> post-install-cmd list in my composer.json file:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.1.*"
},
"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 -v",
"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"
}
}
Now tt returns the old php version again, see this screenshot:
Maybe this seems completely logic to you guys/girls, but I'm stuck here.
Well, Composer doesn't use your alias to execute PHP.
You could use php70 -v in composer.json, but its better to
symlink the newer PHP version to /bin/php, so that Composer can pick it up:
Create a ~/bin folder
mkdir ~/bin
Then symlink the newer PHP version /usr/local/bin/php70 to just~/bin/php
ln -s /usr/local/bin/php70 ~/bin/php
Finally, add this line to .bash_profile to append this folder to your environment variable PATH.
export PATH="$HOME/bin:$PATH"

Class not found Error when running the application

I'm working on an application with Laravel framework. When I tried loading the application(http://localhost/laravel/public/) from firefox browser, I get the below error:
FatalErrorException in C:\wamp\www\laravel\vendor\laravel\framework\src\Illuminate\Foundation\ProviderRepository.php line 150: Class 'Illuminate\Broadcasting\BroadcastServiceProvider' not found
I tried solving this by following few of the solutions mentioned below, but I couldn't get out.
I tried uninstalling the Composer and installing it with --dev-o and this didn't work for me.
I tried moving the folder Vendor out of my application(laravel) and then bringing it in by changing the composer.lock file. And this didn't work.
I tried renaming my namespace:
C:\wamp\www\laravel>php artisan app:name laravel
Even this gives me the same error: [Symfony\Component\Debug\Exception\FatalErrorException] Class 'Illuminate\Broadcasting\BroadcastServiceProvider' not found
My composer.json file components:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": { "php": ">=5.5.9", "laravel/framework": "5.1.*"
},
"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"},
"require": {"illuminate/html": "5.*","laravel/framework": "5.0.*"}
}
Your help will get me out of this limbo.
You should run
composer install --no-dev --no-scripts
and then
composer install --no-dev -o

Deployment on Laravel Forge throwing faker not found Exception

I am trying to deploy a laravel project on forge and i am getting the below exception :
Symfony\Component\Debug\Exception\FatalErrorException]
Class 'Faker\Factory' not found
I have the faker reference in require-dev in composer.json!
composer.json file
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.1.*",
"tymon/jwt-auth": "0.5.*",
"dingo/api": "1.0.x#dev"
},
"require-dev": {
"fzaninotto/faker": "~1.5",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1",
"laracasts/testdummy": "1.*",
"laracasts/generators": "^1.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"
}
}
Deployment script in Forge:
git pull origin master
composer install --no-interaction --no-dev --prefer-dist
php artisan migrate --force
php artisan db:seed --class="StaticDataSeeder"
I was able to deploy the same project locally with out any problem and composer update on forge also runs successfully and i can see the faker package getting downloaded.
Please let me know if i am missing something.
There is a clear conflict that explains your problem:
You've added the "fzaninotto/faker" package to the require-dev section.
You're running the deployment composer install command with the --no-dev option which explicitly prohibits installing the packages listed in require-dev.
So the solution is either to move the package to the require section or remove the --no-dev option when deploying.
I have same problem on heroku deployment i think it same, i fix with
moving "fzaninotto/faker": "~1.4" from "require-dev" to "require" in composer.json and composer.lock
composer install
composer update
git add
git commit
git push heroku
if you don't use heroku as deployment don't run from step 4-6
Run the next command:
composer install
And the problem should go away

Composer is not copying on the specified bin-dir directory

I had this issue sometimes, on windows, on mac, on ubuntu...
I have this composer.json:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"laravel/framework": "4.2.*",
"zizaco/confide": "~4.0#dev",
"zizaco/entrust": "1.2.*#dev",
"guzzlehttp/guzzle": "~4.0"
},
"require-dev": {
"phpunit/phpunit": "4.1.4",
"behat/behat": "3.0.12",
"behat/mink": "1.5.0",
"behat/mink-extension": "2.0.0",
"behat/mink-goutte-driver": "1.0.9",
"codeception/verify": "0.2.7",
"codeception/specify": "0.3.6"
},
"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": {
"bin-dir": "bin/",
"preferred-install": "dist"
},
"minimum-stability": "stable"
}
This is Laravel 4 with a few testing packages.
After a composer install or a composer update the directory "bin" is not created on my project.
I should have one binary for phpunit and another for behat. So i have to use the commands like vendor/behat/bin/behat and vendor/phpunit/phpunit/phpunit which is a pain.
Any idea why the binaries are not on the "bin" folder?
Yesterday, the some project with less packages, I had the binary folder there with the phpunit binary. Now is gone. I don't get it.
This happened to me today as well. While I haven't yet figured out why it happens, a dirty workaround is to remove vendor folder and run composer install.
I've found this pull request in composer's git repo:
https://github.com/composer/composer/pull/5127
It seems that the feature of recreating the binaries, will get released in Composer 1.1

Categories