Composer: The requested package php could not be found - composer-php

Every time i try and run composer install, the dependencies fail due to the following error:
The requested package php could not be found
I've got this working on a LAMP stack, but I'm trying to get it working on a LEMP stack now, with php5-fpm and its not going well.
$ php -v
PHP 5.5.8-3+sury.org~precise+2 (cli) (built: Jan 29 2014 13:23:55)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
with Zend OPcache v7.0.3-dev, Copyright (c) 1999-2013, by Zend Technologies
EDIT
I have other stuff in mine, but i tested the following composer.json on the same server, and its still doing it.
composer.json
{
"require": {
"php": "5.4.*"
}
}
my composer version is
Composer version b7a9ea4187bce63f418bf7ba035b63dcb1e23ef6 2014-02-06 22:07:47
Am I missing something?

Well, that's easy: Composer is exactly doing what you tell it to do.
You are requesting any version of PHP 5.4. You explicitly do not allow any versions of 5.5. So Composer correctly complains about having not the right version of PHP (yours is PHP 5.5, you request 5.4.*).
It is very unlikely that your code does not run with the newer version, so it's best to use this composer.json content:
{
"require": {
"php": ">=5.4"
}
}
Requesting a version greater than or equal 5.4 will also include 5.5 and above.

Related

inheritance of ArrayAccess: Uncaught ErrorException: Collection::offsetExists($key)

NB: Local server PHP Version 8.1.4, laravel project inside composer.json file have "php": "^7.2.5", version & "laravel/framework": "^7.0"
PHP Fatal error: During inheritance of ArrayAccess: Uncaught ErrorException: Return type of Illuminate\Support\Collection::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
error displaying below like this :
That's a php version issue. Upgrade laravel or downgrade PHP. This article covers how to downgrade the PHP version so it matches the Laravel Version.
https://bytexd.com/fix-laravel-return-type-of-illuminatesupportcollectionoffsetexistskey/
in your composer.json update line
"php": "^7.3",
to
"php": "^7.3|^8.1",
and run composer update
You would need to upgrade your Laravel Framework version to at least version 8 and it's dependencies using composer.
Reference: https://laravel.com/docs/8.x/releases
Or if you want to postpone it, you would need to add #[\ReturnTypeWillChange] before declaring every function that throws the error. This is highly not advisable.
P.S. If you updated your PHP version you would have to change the PHP version in composer to the one used, in your case it should be "php": "^8.1.4"
In my case, using a mac, turns out my php version was 8.1 which somehow is not compatible with laravel version 7. Tho most of these answers are correct, but they did not fix my issues. I followed these steps (if brew is installed):
brew unlink php#8.1
brew link php#8.0 or lower
Reference How can I easily switch between PHP versions on Mac OSX?
run "composer update" on your project directory and it will work .

How to constraint compatibility with PHP without explicitly constraint all the depending packages

I got this requirement in my composer.json:
"php": ">= 5.6",
"symfony/http-foundation": "^3.0"
The problem with that configuration is that it will install paragonie/random_compat v9.99.99 which is only compatible with PHP 7 and more. But the thing is that I don't want my composer.lock file to require PHP 7, I want it to still be compatible with PHP 5.6.
The solution I found is to track down which package was pulling this dependency and, once I found it, I added this to my requirements:
"paragonie/random_compat": "~2.0"
But I wonder if there is not a better way of doing that: somehow telling that I accept all the versions above PHP 5.6, but I don't accept packages that would force to have PHP 7?
If you want to make composer.lock compatible with PHP 5.6, you have at least two options to achieve that:
Use PHP 5.6 for composer update - you should be able to install multiple versions of PHP on your OS and run Composer like this:
/path/to/php6.5 /path/to/composer update
Use platform settings in composer.json to force installation for specific version regardless PHP version used to run Composer commands:
"config": {
"platform": {
"php": "5.6.38"
}
},

Symfony parse error in output.php when creating project in laravel

Installed laravel 5.6
Have PHP 7.0 installed as well.
When I try
laravel new sample-project
it creates the required files and dependencies but bails with an error below:
PHP Parse error: syntax error, unexpected '?', expecting variable (T_VARIABLE) in /home/johndoe/laravel/sample-project/vendor/symfony/console/Output/Output.php on line 40
Have a feeling this might be due to issues with the symfony file but not sure how to go about getting the right version or making a change in Output.php
Trying any other command such as
php artisan list
results in the same error
Composer relevant section denoting laravel 5.6 / php 7.1.3
"require": {
"php": "^7.1.3",
"fideloper/proxy": "~4.0",
"laravel/framework": "5.6.*",
"laravel/tinker": "~1.0"
},
Any help would be appreciated.
EDIT
Based on the answer I had to create a project with laravel version 5.5 which means I had to use
composer create-project laravel/laravel sample-project "5.5.*"
That worked.
Laravel 5.6 requires PHP > 7.1.3
you will need to make sure your server meets the following
requirements:
PHP >= 7.1.3
I ended up having to edit the $PATH in my .bashrc file, because it was picking up an old version of php.
> whereis php
> echo $PATH
I found the correct version of php here: /opt/php71/bin
So now my .bashrc file looks like this:
export PATH=/opt/php71/bin:$PATH
This fixed the error I was getting in composer, AND now php artisan also works!
:-D
PS. The version of php that you're using in the shell may be different from the version used to serve your site. That can be fixed in cpanel's php selector.

Laravel CLI fails to create new app due to Cannot use lexical variable $eventName as a parameter name

After successful installation of Laravel's install tool using composer using composer global require "laravel/installer" command, the first attempt to create an application by running laravel new app-name fails with the following output, any advice will be appreciated :)
Crafting application...
PHP Fatal error: Cannot use lexical variable $eventName as a parameter name in /Users/ABN/.composer/vendor/guzzlehttp/guzzle/src/Event/Emitter.php on line 48
PHP Stack trace:
PHP 1. {main}() /Users/ABN/.composer/vendor/laravel/installer/laravel:0
PHP 2. Symfony\Component\Console\Application->run() /Users/ABN/.composer/vendor/laravel/installer/laravel:13
PHP 3. Symfony\Component\Console\Application->doRun() /Users/ABN/.composer/vendor/symfony/console/Application.php:126
PHP 4. Symfony\Component\Console\Application->doRunCommand() /Users/ABN/.composer/vendor/symfony/console/Application.php:195
PHP 5. Laravel\Installer\Console\NewCommand->run() /Users/ABN/.composer/vendor/symfony/console/Application.php:878
PHP 6. Laravel\Installer\Console\NewCommand->execute() /Users/ABN/.composer/vendor/symfony/console/Command/Command.php:259
PHP 7. Laravel\Installer\Console\NewCommand->download() /Users/ABN/.composer/vendor/laravel/installer/src/NewCommand.php:52
PHP 8. GuzzleHttp\Client->get() /Users/ABN/.composer/vendor/laravel/installer/src/NewCommand.php:125
PHP 9. GuzzleHttp\Client->createRequest() /Users/ABN/.composer/vendor/guzzlehttp/guzzle/src/Client.php:125
PHP 10. GuzzleHttp\Client->getEmitter() /Users/ABN/.composer/vendor/guzzlehttp/guzzle/src/Client.php:115
PHP 11. spl_autoload_call() /Users/ABN/.composer/vendor/guzzlehttp/guzzle/src/Event/HasEmitterTrait.php:15
PHP 12. Composer\Autoload\ClassLoader->loadClass() /Users/ABN/.composer/vendor/guzzlehttp/guzzle/src/Event/HasEmitterTrait.php:15
PHP 13. Composer\Autoload\includeFile() /Users/ABN/.composer/vendor/composer/ClassLoader.php:322
Turned out the issue is related to the guzzle version installed on the system.
After seeing similar issue reported around guzzle 5.3 on some other repositories/apps, confirmed my globally installed version by running composer global info guzzlehttp/guzzle and it was 5.3.
Then updating my composer's global installation by running composer global updatesolved the problem, after seeing the update report as shown bellow, running the same laravel new app-name generates the application successfully.
Updating guzzlehttp/guzzle (5.3.0 => 6.2.3): Downloading (100%)
This is related to Guzzle's PHP 7.x incompatibility and this has been fixed in Guzzle >=5.3.1.
The solution is to upgrade your Guzzle by modifying line in your composer.json file to:
"guzzlehttp/guzzle": "~5.3.1",
or:
"guzzlehttp/guzzle": "~5.3#stable",

voyager - (Symfony\Component\Console\Exception\CommandNotFoundException] There are no commands defined in the "voyager" namespace)

So I am trying to install Voyager for my laravel, but when I insert
php artisan voyager:install
I am getting this error message:
(Symfony\Component\Console\Exception\CommandNotFoundException] There
are no commands defined in the "voyager" namespace)
Here is my PhP and Laravel version:
Laravel Framework version 5.3.16
λ php -v PHP 7.0.13 (cli) (built: Nov 8 2016 13:45:28) ( ZTS )
Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, Copyright
(c) 1998-2016 Zend Technologies
And my package service providers:
/*
* Package Service Providers...
*/
TCG\Voyager\VoyagerServiceProvider::class,
Intervention\Image\ImageServiceProvider::class,
So what is the problem? why am I getting this error message
Looks like you didn't install it. Comment out or remove service providers from the list and run these commands:
composer require tcg/voyager
composer dumpauto
According to the docs, next step will be adding a service provider to the config/app.php:
TCG\Voyager\VoyagerServiceProvider::class,
And only then run php artisan voyager:install command.
php artisan config:clear
solved my problem
If you have successfully executed the command line:
composer require tcg/voyager
You must have the line "tcg/voyager": "^1.2" in the require section of your composer.json file, in this case the command line "composer dumpautoload" will automatically perform all the packages discovery for you. Otherwise do the following :
add the line of code: TCG\Voyager\VoyagerServiceProvider::class to the file "config/app.php". Then run the following command line :
composer dumpautoload

Resources