php——composer安装与使用

Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.

 

下载安装器

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

校验

php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

本地工程安装

php composer-setup.php --install-dir=bin --filename=composer
All settings correct for using Composer
Downloading...
Composer (version 2.2.3) successfully installed to: ../bin/composer
Use it: php bin/composer

localhost:vms chong$ php bin/composer --version
Composer version 2.2.3 2021-12-31 12:18:53

全局安装

php composer-setup.php

sudo mv composer.phar /usr/local/bin/composer

 

常见异常处理

1、preg_replace(): Allocation of JIT memory failed

php bin/composer update
                                                                                                        
  [ErrorException]                                                                                      
  preg_replace(): Allocation of JIT memory failed, PCRE JIT will be disabled. This is likely caused by  
   security restrictions. Either grant PHP permission to allocate executable memory, or set pcre.jit=0  
                                                                                                        

install [--prefer-source] [--prefer-dist] [--prefer-install PREFER-INSTALL] [--dry-run] [--dev] [--no-suggest]
[--no-dev] [--no-autoloader] [--no-progress] [--no-install] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader]
[-a|--classmap-authoritative] [--apcu-autoloader] [--apcu-autoloader-prefix APCU-AUTOLOADER-PREFIX]
[--ignore-platform-req IGNORE-PLATFORM-REQ] [--ignore-platform-reqs] [--] [<packages>]...

解决办法

/Applications/XAMPP/xamppfiles/etc/php.ini

修改php.ini:


;pcre.jit=1
改为:
pcre.jit=0

保存,重启php服务即可

 

posted @ 2022-01-05 12:57  会飞的斧头  阅读(519)  评论(0编辑  收藏  举报