背景:
有个项目需要安装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
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扩展
5.再次 composer install
还是报这个错,
解决方法:需要开启sockets
扩展,然后重启php就可以了
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。