1

背景:

有个项目需要安装laravel-queue-rabbitmq,但在composer install时爆以下错误:

No composer.lock file present. Updating dependencies to latest instead of installing from lock file. See https://getcomposer.org/install for more information.
Loading composer repositories with package information
Warning: Accessing nexus.officemate.cn over http which is an insecure protocol.
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - php-amqplib/php-amqplib[v2.11.0, ..., 2.x-dev] require ext-sockets * -> it is missing from your system. Install or enable PHP's sockets extension.
    - vladimir-yuldashev/laravel-queue-rabbitmq v10.2.3 requires php-amqplib/php-amqplib ^2.11 -> satisfiable by php-amqplib/php-amqplib[v2.11.0, ..., 2.x-dev].
    - Root composer.json requires vladimir-yuldashev/laravel-queue-rabbitmq 10.2.3 -> satisfiable by vladimir-yuldashev/laravel-queue-rabbitmq[v10.2.3].

To enable extensions, verify that they are enabled in your .ini files:
    - D:\willen\phpStudy\PHPTutorial\php\php-7.2.1-nts\php.ini
You can also run `php --ini` in a terminal to see which files are used by PHP in CLI mode.
Alternatively, you can run Composer with `--ignore-platform-req=ext-sockets` to temporarily ignore these required extensions.

报错截图:
报错截图

查询资料后,发现原因是要使用 RabbitMQ的话,要先在本地安装php-amqplib扩展,这个对应的是amqp扩展;

安装步骤:
1.执行php -v查看本地环境;
本地开发环境

2.ampq 扩展安装
http://pecl.php.net/package/amqp

ampg扩展下载路径

windows 点击红色框框的内容,选择和php版本匹配的文件下载,下载后php_amqp.dll 放到php的ext,我的本地是phpstudy,在D:\willen\phpStudy\PHPTutorial\php\php-7.2.1-nts\ext

rabbitmq.4.dll 放到php目录下,即和php.exe在一个目录,我的目录是D:\willen\phpStudy\PHPTutorial\php\php-7.2.1-nts

3.php.ini添加扩展

extension=php_amqp.dll

注意
rabbitmq.4.dll 放在php目录下,是因为如果不放在这里的话,当执行“php”命令的时候会报“无法启动此程序,因为计算机中丢失rabbitmq.4.dll。尝试重新安装该程序以解决此问题”错误,如图:

系统报错

4.重启php环境
可以看到amqp扩展

amqp扩展安装成功

5.再次 composer install还是报这个错,
composer install报错

解决方法:需要开启sockets扩展,然后重启php就可以了
开启sockets扩展


willeny
144 声望3 粉丝