I am told by PHPStorm that I need to composer require ext-zip, however, that command is failing...
PHPStorm says
The command I am issuing is
composer require ext-zip
results in
Your requirements could not be resolved to an installable set of packages.
and
Installation failed, reverting ./composer.json to its original content.
Solution #1 - add ext-zip to your required section of composer.json:
{
"require" : {
"ext-zip": "*"
}
}
Solution #2 - install php-zip extension:
Windows:
Uncomment this line in your php.ini
;extension=php_zip.dll
Linux:
sudo apt-get install php-zip
or
sudo apt-get install php7.0-zip (make sure you typed YOUR php version, you can check your version by doing php -v command)
Then, you need to restart your web server.
sudo service apache2 restart
If your code runs OK - you've already got the zip extension installed on your machine. PHPStorm adds this suggestion to ensure that anywhere else that the project is deployed also has the right extensions too.
Manually adding the line in your composer.json file (require block) "ext-zip": "*", (and others that it can suggest, such as ext-apc, ext-redis and ext-json, as well as any others that you might be using) will make sure that when you deploy it composer can also check that the appropriate extra items are installed.
It's only a warning though, and you could ignore it - or you can allow composer to make sure that your servers are setup as they would be needed to run your code, and do things with zip-files. If your server doesn't have ext-zip installed, composer install would complain, and stop - saving issues later when you discover that code fails without the zip extension, et al.
The given hint comes from PhpStorm, not from composer itself: your IDE has detected that your code uses a method (or in this case: the ZipArchive class) that is only available when the ZIP extension is enabled. But your composer.json did not contain that requirement so far.
So, PhpStorm asks you to add this requirement to the JSON file to make the requirements to run your code more precise. How you solve that requirement is up to you: the best way would be to install that extension, but that is out of composer's scope
Related
I'm trying to configure a PhpStorm project to utilize both remote PHP and a remote Composer. Remote being my Windows Subsystem for Linux (WSL) installation. However, when I initiate any Composer commands from PhpStorm, I get errors. And unfortunately, the errors are not very indicative of the cause or offer a link for additional details.
Errors received in my "Event Log":
12:21 PM Composer
Failed to install packages for ./composer.json.
Show in Log
And in my "Composer Log":
install --no-interaction --no-ansi
/bin/sh: 1: composer: not found
Failed to install packages for ./composer.json.
So far, I've followed the instructions located at:
https://www.jetbrains.com/help/phpstorm/how-to-use-wsl-development-environment-in-product.html
https://www.jetbrains.com/help/phpstorm/configuring-remote-interpreters.html
I also followed the answer at this post to set WSL as my default terminal:
How to use WSL as default terminal in WebStorm or any other JetBrains' products?
In my WSL installation, composer is located at /home/<user>/.local/bin/composer and is included in my path upon login in my /home/<user>/.profile file. And I was sure to restart PhpStorm after doing so to ensure it has the updated path. Additionally, running composer install within my project, on WSL works without issue.
I'm not sure how to determine which terminal or composer file PhpStorm is using. Either it's still trying to find and use a composer on my host Windows install (which doesn't exist) or I'm missing a path which I have to map for WSL.
Any idea how I can obtain more details as to what I have misconfigured?
I figured out my issue.
When in Settings -> PHP -> Composer, in the "Execution" section. I was already selecting "Remote Interpreter", but the "Composer executable" field requires an absolute path. I was simply supplying the name of the executable since the field is asking for the executable.
I just figured it would utilize my $PATH to resolve the executable, but this isn't using an SSH session so it wouldn't have my custom $PATH values. So it all makes sense.
I have been writing laravel code for quite sometime. Currently, I tried cloning a project from github and editing locally. I installed composer in my project directory but a vendor folder was not included, I tried to run composer install but I gives me this error
Your lock file does not contain a compatible set of packages. Please run composer update
How do I resolve this?
Note: I have tried running composer update on previous clones and that didn't work.
Run this command:
composer install --ignore-platform-reqs
or
composer update --ignore-platform-reqs
Disclaimer, this solution will not fix the issue for PHP 8 projects.
In most cases this happens because of PHP 8 (In my case it was GitHub CI actions automatically started using PHP 8 even though my project is php 7.4)
If you have multiple PHP installations (E.g. 7.4 and 8 on the same server), this is how you can fix it.
Specify your php version in your composer.json file
"config": {
"platform": {
"php": "7.3"
}
},
If you have the lock file already committed, run composer update after you adding above line in to the composer.json and then commit the new lock file. (Please be aware composer update will upgrade your packages to latest versions)
I solved this problem with this command:
composer self-update --1
It probably works because at time that the project was developed, composer was on another version and when change the Major version from 1 to 2 the compatibility was broke. With this command you downgrade composer and probably going to solve this
You should try running composer update --lock that will update all packages and recreate the compose.lock file.
Either you can delete the composer.lock file and run composer install that will also recreate the .lock file.
This resolved my issue.
I had this error with Github Actions trying to deploy a Laravel app, this is probably different than the OP's case but none of the suggestions worked for me. Adding my answer here just in case there is someone else out there with a similar problem to mine.
I had to disable -q in Github Actions and see that it was complaining about extensions not being installed.
Make sure your require section of composer's php extensions matches the extensions: in your github action file for shivammathur/setup-php#v2 and it will deploy again
Recently I've just come across of this error when I tried to run my Laravel 7 project which required php v7.* with php v8. As I forgot my php version I just tried bunch of composer command, but just got error after error.
Anyway, to solve this just downgrade/upgrade php version as required. Just search how to do that in youtube.
you can see your project required php version in composer.json file (just if you wonder)
Also you can try following way (But though it didn't worked for me, seems it helped quite some people)
-- Open composer.json file and change php version to something like this: "php": "^7.3|^8.1"
-- Then run composer update
I faced this problem with my cakephp project in garuda linux (arch based)
Fix :
Install php-intl using sudo pacman -S php-intl
Enable php intl by editing php config ( in my case /etc/php/php.ini ) .
add extension=intl or uncomment the existing one
restart apache or whatever you are using
I had the same error deploying another project with composer, but the problem was a missing php extension.
I understand you solve your problem but for anyone seeing the same error message, here is a general guidance :
The error message Your lock file does not contain a compatible set of packages. Please run composer update is shown each time there is a conflict during the dependency solving step of composer install. (see the relevant part in composer source code)
It doesn't inform on the real problem though, and it could be hard to guess.
To get the exact explanation you can add --verbose option to composer install command (the option is available to any composer command (see the doc)) : composer install --verbose
It will give you the full message explaining what exactly is preventing composer install from completing (package version conflict, missing php extension, etc.), then you'll be able to fix the problem.
Hope this could help.
In my case this problem is occuring in Ubuntu 20.04 Desktop. This is due to some missing packages.
I ran the following commands to install some packages then rerun Composer install and its working properly. The commands are:
sudo apt-get install php-mbstring
sudo apt-get install php-xml
Then rerun composer install
I'm trying to run a symfony4 application in the Google Cloud App Engine following this instructions.
My app has a dependency which itself depends on php-gd. This extension seems to be unavailable since composer fails with the requested PHP extension gd is missing from your system..
How would I have to modify the tutorial to have the extension available?
Can this be solved with a php.ini file or do I need a custom environment?
Alternatively since I don't need the parts of my dependency which require php-gd, is there a way to get composer run with the --ignore-platform-reqs flag?
Make sure to get installed this php-gd or apt-get install php5-gd
-your OS apt-get install php gd or apt-get install php5-gd, be aware of your php version.
The other approach here woulbe to add "ext-gd": "*" to your application's composer.json:
composer require "ext-gd:*" --ignore-platform-reqs
It doesn't matter if gd is enabled in your local PHP install, the flexible environment is built using your composer.json and app.yaml files, so you need to add it there.
Well this is based on Symfony
So on the root of your application create a file php.ini
In the file enter this line
extension=gd.so
So that your php.ini file will look like this.
Google Cloud App Engine only seems to load extensions required in the top level composer.json's require.
It does not seem to resolve dependencies recursevly.
Therefore a workaroud is to add all required extensions manually to the projects composer.json.
I've looked quite a bit and have seen this post, and the corresponding notice that extension is now available. However with the ext, and dropping the ext I still get errors.
Also in their documentation updated 12/3/2014 the ext is in the example at heroku.
Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested package mongo could not be found in any version, there may be a typo in the package name.
When I try to run my application I see the error in the log that PHP Fatal error: Class 'MongoClient' not found
What am i doing incorrectly?
Not sure I understand your question. The error messages you provided give little information in the context.
You add
"ext-mongo": "*"
to the require { ... } section in your composer.json.
After that, run
$ composer update
to re-generate composer.lock, then
$ git add composer.json composer.lock
$ git commit -m "enable ext/mongo"
$ git push heroku master
That's all.
In case you're using PHP 7 you should ext-mongodb and not ext-mongo add to your composer.json
"ext-mongodb": "*"
After that make sure running
composer update
And committing your composer.lock since Heroku uses the composer.lock to enable the extensions.
Resolved!
I uninstalled phpunit from pear and then reinstalled it again. I believe I was using the wrong/old/not enough sources before installing. Works like a charm!
So I'm trying to set up PEAR & PHPUnit. I was following http://www.newmediacampaigns.com/page/install-pear-phpunit-xdebug-on-macosx-snow-leopard but after I installed pear I had a different directory structure in /usr/local. Regardless, I was able run the phpunit install. But now I'm lost and asking for help before I make a bigger mess :)
pear config-show says:
PEAR directory php_dir /usr/local/share/pear
And my php.ini file (and confirmed in phpinfo() says:
include_path=".:/usr/local/share/pear"
So that's good, right? But now what? I get
Failed opening required 'PHPUnit/Framework.php' (include_path='.:/usr/local/share/pear')
If I try to include it in the php. And I have no idea where the binary might be to run it from the command line.
Inside /usr/local/share/pear/PHPUnit there are two directories "Extensions" and "Framework"
It sometimes happen that the install fails on PHPUnit specifically, but succeeds on the dependencies, so it only looks like the install was succesfull.
Try this when installing
pear install --force --alldeps phpunit/PHPUnit
The --force option will force the install of PHPUnit, even if all the dependencies can't be met. In my case there was a missing dependency for the dom PHP extension which blocked the installation even though the PHP_Invoker package could be used instead.
The --alldeps option makes sure that all of the dependencies got installed.
Check for a bin directory in the pear install, something along the lines of /usr/local/share/pear/bin/ - your install is different than mine..
You could also try searching for the binary -
find /usr/local/share/pear -name 'phpunit'