【阿里云镜像】macOS 安装 composer 作者: Chuwen 时间: 2020-11-23 分类: macOS 评论 # 下载 > 由于在官网下载 `composer` 比较慢,所以我们可以使用 **阿里云 Composer 全量镜像** 下载 > 但我还是贴出 *官方下载&安装:`curl -sS getcomposer.org/installer | php`* ```shell # 下载 composer.phar curl https://mirrors.aliyun.com/composer/composer.phar -O composer.phar # 检查版本号 php composer.phar -v ``` # 如果需要全局使用 > 可以移动 `composer.phar` 到 `/usr/local/bin/` 路径下 ```shell sudo mv composer.phar /usr/local/bin/composer ``` ## 可能因为权限问题,直接执行 `composer` 会报权限不够 ```log chuwen@WenzhoudeMBP cms.iton.pw % composer -v zsh: permission denied: composer ``` ## 设置下权限即可 ```log sudo chomd -R 755 /usr/local/bin/composer ``` # 测试(输出版本号) > 记得往下,改 `阿里云 Composer 镜像源`,安装项目起飞?️ ```shel chuwen@WenzhoudeMBP cms.iton.pw % composer -v ______ / ____/___ ____ ___ ____ ____ ________ _____ / / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/ / /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ / \____/\____/_/ /_/ /_/ .___/\____/____/\___/_/ /_/ Composer version 2.0.7 2020-11-13 17:31:06 Usage: command [options] [arguments] Options: -h, --help Display this help message -q, --quiet Do not output any message -V, --version Display this application version --ansi Force ANSI output --no-ansi Disable ANSI output -n, --no-interaction Do not ask any interactive question --profile Display timing and memory usage information --no-plugins Whether to disable plugins. -d, --working-dir=WORKING-DIR If specified, use the given directory as working directory. --no-cache Prevent use of the cache -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug Available commands: about Shows the short information about Composer. archive Creates an archive of this composer package. browse Opens the package's repository URL or homepage in your browser. cc Clears composer's internal package cache. check-platform-reqs Check that platform requirements are satisfied. clear-cache Clears composer's internal package cache. clearcache Clears composer's internal package cache. config Sets config options. create-project Creates new project from a package into given directory. depends Shows which packages cause the given package to be installed. diagnose Diagnoses the system to identify common errors. dump-autoload Dumps the autoloader. dumpautoload Dumps the autoloader. exec Executes a vendored binary/script. fund Discover how to help fund the maintenance of your dependencies. global Allows running commands in the global composer dir ($COMPOSER_HOME). help Displays help for a command home Opens the package's repository URL or homepage in your browser. i Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json. info Shows information about packages. init Creates a basic composer.json file in current directory. install Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json. licenses Shows information about licenses of dependencies. list Lists commands outdated Shows a list of installed packages that have updates available, including their latest version. prohibits Shows which packages prevent the given package from being installed. remove Removes a package from the require or require-dev. require Adds required packages to your composer.json and installs them. run Runs the scripts defined in composer.json. run-script Runs the scripts defined in composer.json. search Searches for packages. self-update Updates composer.phar to the latest version. selfupdate Updates composer.phar to the latest version. show Shows information about packages. status Shows a list of locally modified packages. suggests Shows package suggestions. u Upgrades your dependencies to the latest version according to composer.json, and updates the composer.lock file. update Upgrades your dependencies to the latest version according to composer.json, and updates the composer.lock file. upgrade Upgrades your dependencies to the latest version according to composer.json, and updates the composer.lock file. validate Validates a composer.json and composer.lock. why Shows which packages cause the given package to be installed. why-not Shows which packages prevent the given package from being installed. ``` # 切换成 阿里云 Composer 镜像源 ## 1. 全局配置(推荐) ```shell composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ # 取消当前项目配置 composer config --unset repos.packagist ``` ## 2. 仅在当前项目配置 ```shell composer config repo.packagist composer https://mirrors.aliyun.com/composer/ # 取消全局配置 composer config -g --unset repos.packagist ```
Composer 常见问题 作者: Chuwen 时间: 2019-01-20 分类: PHP 评论 原文链接:[Composer常见问题][1] 安装了Composer后,运行 `composer --version`,查看Composer的版本号。如果出现下面的提示,那么软件安装成功。 ``` Composer version 1.2.0 2016-07-19 01:28:52 ``` 若想给某个项目添加类似monolog的第三方库,则按下面的步骤操作: 新建 `composer.json` 文件,添加内容: ``` { "require": { "monolog/monolog": "1.20.0" }, "repositories": { "packagist": { "type": "composer", "url": "https://packagist.phpcomposer.com" // Mirror site in China. } } } ``` 以命令行方式打开项目的根目录,输入命令:`composer install` 正常情况下,一切顺利,执行完上述命令就能够成功导入 monolog 库到项目中。但是,现实与想象总是有段距离,上面只是走完了“长征”路程的一半,还有“雪山”要翻、“草地”要过呢! 执行完命令:`composer install` 后,并不会像期待那样地导入依赖,而是抛出异常。 > The openssl extension is required for SSL/TLS protection but is not available. If you can not enable the openssl exension, you can disable this error, at your own risk, by setting the ‘disable-tls’ option to true. 这段异常日志的大致意思是,Composer 采用 SSL 连接,需要外挂 OpenSSL 插件。 要消除这个异常,有两种解决方式,一是放弃SSL连接、直接“裸奔”;二是启用 OpenSSL。 取消SSL连接的命令是 `composer config -g -- disable-tls true`。然而并没有什么卵用,试过之后,又抛出了新的异常。 剩下来的方案就是尝试启用 OpenSSL。安装了PHP后,安装目录(类似C:\php-5.6.24)中包含两个文件,一个是php.ini-development,另一个是php.ini-production,选择将其中任意的一个文件重命名为 `php.ini`,用作PHP的默认配置文件。通过修改配置文件来启用OpenSSL插件。 编辑php.ini文件,首先,定位到: ``` ; Directory in which the loadable extensions (modules) reside. ; http://php.net/extension-dir extension_dir = "./" ; On windows: extension_dir = "ext" ``` 删除 `extension_dir = "./"` 和 `extension_dir = "ext"` 前面的分号,取消注释这两行代码,配置 PHP 插件目录为./ext。 然后,定位到: ``` ... ;extension=php_mysqli.dll ;extension=php_oci8_12c.dll ; Use with Oracle Database 12c Instant Client extension=php_openssl.dll ;extension=php_pdo_firebird.dll ;extension=php_pdo_mysql.dll ;extension=php_pdo_oci.dll ;extension=php_pdo_odbc.dll ... ``` 删除 `extension=php_openssl.dll` 前面的分号,取消注释,从而启用 `OpenSSL` 插件。 注意:因为 SSL 连接需要认证,所以继续下面的步骤之前,需要准备好CA证书(建议把证书保存到 `C:\php-5.6.24\verify` 目录中),可以从 `https://curl.haxx.se/docs/caextract.html` 处下载。 接下来,定位到 ``` ;openssl.cafile= ``` 和上面一样,删去分号,取消注释,设置CA证书为 `openssl.cafile= C:\php-5.6.24\verify\cacert.pem`。 最后, 重新在命令行窗口中打开项目的根目录,执行命令:`composer install`,等待几分钟后,就可以成功添加 monolog 依赖。 [1]: https://mp.weixin.qq.com/s?__biz=MzI5NzQwNzY4Ng==&mid=2247483652&idx=1&sn=23ca573af8d41cda0d4f5270b25020d2&scene=4#wechat_redirect