我无法使用 Composer 安装 Laravel(缺少 ext-zip 扩展名)

I cannot install Laravel with Composer (ext-zip extension is missing)

我尝试在我的 Debian 9 终端上安装 Laravel 和 Composer

composer global require laravel/installer

但我收到以下错误:

Using version ^3.0 for laravel/installer
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - laravel/installer v3.0.1 requires ext-zip * -> the requested PHP extension zip is missing from your system.
    - laravel/installer v3.0.0 requires ext-zip * -> the requested PHP extension zip is missing from your system.
    - Installation request for laravel/installer ^3.0 -> satisfiable by laravel/installer[v3.0.0, v3.0.1].

  To enable extensions, verify that they are enabled in your .ini files:
    - /opt/lampp/etc/php.ini
  You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.

Installation failed, deleting ./composer.json.

我尝试安装 PHP ext Zip 扩展:

apt-get install php7.4-zip

apt-get install php-zip

并编辑 php.ini 文件,取消注释以下行:

extension=php_zip.dll
extension="zip.so"

但是没有任何效果,我也有同样的错误...

  • 确保在更改后重新启动网络服务器
  • php -m 列出已编译的模块
  • 有一次(在 plesk 上)我碰巧 composer 使用的 php 版本与使用 php 本身不同
  • 您可以尝试 php composer.phar(the location of that) 并检查结果

如果安装 laravel 在这里很重要

这里有一些可能的解决方案

  • composer create-project laravel/laravel [dir]
  • git clone https://github.com/laravel/laravel.git然后cd到那个目录,通常是laravel,所以cd laravel然后composer install

我遇到了和你一样的问题

我可以通过

看到我缺少 zip 扩展名
php -m

我做到了

apt search php | grep zip

为了查看是否有我可以安装的软件包,我找到了 php-zip,所以我安装了

sudo apt install php-zip

之后 php -m 在列表中显示 zip

然后我再次尝试安装Laravel的命令

composer global require laravel/installer

成功了。