centos下安装使用composer
2023-06-13 09:16:16 时间
composer的中文意思为作曲家,是php最新的包管理器。
安装
cd path-to-your-project
curl -sS https://getcomposer.org/installer | php
# Composer successfully installed to: /tmp/composer.phar
# Use it: php composer.phar
如果在此提示,那是因为php没有在系统的环境变量$PATH中。
command not found: php
解决方法:
为当前php的路径创建一个软连接
ln -s /usr/local/php/bin/php /usr/local/bin/php
仔细察看composer.phar的权限,应该是755,即-rwxr-xr-x
,说明这个文件其他人都有执行权限,所以如果我们将其移动至/usr/local/bin/
中,即可全局可用!
mv composer.phar /usr/local/bin/composer
使用
我们先使用-h
查看帮助
composer -h
Usage:
help [--xml] [--format="..."] [--raw] [command_name]
Arguments:
command The command to execute
command_name The command name (default: "help")
Options:
--xml To output help as XML
--format To output help in other formats (default: "txt")
--raw To output raw command help
--help (-h) Display this help message
--quiet (-q) Do not output any message
--verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
--version (-V) Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
--no-interaction (-n) Do not ask any interactive question
--profile Display timing and memory usage information
--working-dir (-d) If specified, use the given directory as working directory.
Help:
The help command displays help for a given command:
php /usr/local/bin/composer help list
You can also output the help in other formats by using the --format option:
php /usr/local/bin/composer help --format=xml list
To display the list of available commands, please use the list command.
看来想要找到所有的命令需要运行php /usr/local/bin/composer help list
我们试试吧
php /usr/local/bin/composer list
______
/ ____/___ ____ ___ ____ ____ ________ _____
/ / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
/_/
Composer version 1.0-dev (4f80e7ff68466cab970c22b425725b8058c32970) 2015-06-09 00:03:48
Usage:
command [options] [arguments]
Options:
--help (-h) Display this help message
--quiet (-q) Do not output any message
--verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
--version (-V) Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
--no-interaction (-n) Do not ask any interactive question
--profile Display timing and memory usage information
--working-dir (-d) If specified, use the given directory as working directory.
Available commands:
about Short information about Composer
archive Create an archive of this composer package
browse Opens the package's repository URL or homepage in your browser.
clear-cache Clears composer's internal package cache.
clearcache Clears composer's internal package cache.
config Set config options
create-project Create new project from a package into given directory.
depends Shows which packages depend on the given package
diagnose Diagnoses the system to identify common errors.
dump-autoload Dumps the autoloader
dumpautoload Dumps the autoloader
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.
info Show 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 Show information about licenses of dependencies
list Lists commands
remove Removes a package from the require or require-dev
require Adds required packages to your composer.json and installs them
run-script Run the scripts defined in composer.json.
search Search for packages
self-update Updates composer.phar to the latest version.
selfupdate Updates composer.phar to the latest version.
show Show information about packages
status Show a list of locally modified packages
update Updates your dependencies to the latest version according to composer.json, and updates the composer.lock file.
validate Validates a composer.json
国内镜像
为了更好的使用composer,我们使用phpcomposer国内镜像加速,具体使用方法很简单,你可以参考官网的使用说明!
在项目中使用composer
比如我们的项目需要使用laravel与monolog,怎么办呢?
首先,在packagist.org中搜索需要的包名,这样我们得到了包名monolog/monolog
,laravel同理。
其次,我们需要确定版本,我们看到官网的提示:
{
"require": {
"vendor/package": "1.3.2", # 明确指定版本
"vendor/package2": "1.*", # 使用通配符,方便以后执行更新
"vendor/package2": "~1.3", # 是指 1.3<= X <2.0的版本
"vendor/package3": ">=2.0.3", # 指定一个范围
"vendor/package3": ">=2.0.3-dev" # 默认composer会取稳定版,但是如果指明-dev,则会下载dev版
}
}
更多使用方法请移步基本用法 | Composer 中文文档 | Composer 中文网
我们在项目根目录下建立文件 composer.json
{
"require": {
"monolog/monolog": "1.0.*"
}
}
自动生成composer.json
为了自动生成composer.json,你可以通过命令
composer init --require "monolog/monolog:1.0.*" -n
更新
如果对composer配置做了修改,需要更新库,使用以下命令
composer update
更多
相关文章
- Centos 安装图形界面与远程使用「建议收藏」
- centos安装python环境
- centos7.4安装docker_centos安装python3.6
- 在CentOS(Linux)中添加单个IP和批量添加多个IP地方法
- CentOS安装Docker
- CentOS安装SQL Server
- 使用VM虚拟机安装CentOS-stream系统
- CentOS安装Rclone
- 在centos系统上安装mongodb数据库
- centos 彻底卸载软件包(含依赖)并解决安装冲突包问题
- CentOS python3 & Java 安装
- centos docker 安装和使用
- 在 CentOS 8/RHEL 8 上安装和使用 Cockpit的方法
- CentOS安装与使用EPEL软件仓库(linuxepel)
- 安装CentOS使用Yum安装Redis(redisyum)
- Centos与Linux:一段友谊(centos和linux的关系)
- CentOS下安装MySQL步骤指南(centos下安装mysql)
- 如何使用Nginx安装WordPress并在CentOS 8上加密SSL
- 在CentOS 8上安装和使用Docker Compose
- 使用Nginx安装和配置Drupal 8-并在CentOS 8上使用 Let’s Encrypt
- 如何在CentOS 8上使用HTTPS安装Gitea代码托管平台
- 如何使用Nginx安装DokuWiki并在CentOS 8上加密SSL
- 如何在CentOS 8上使用Nginx和LE SSL安装Flarum论坛
- 在CentOS 8上使用Nginx安装LibModsecurity Web应用程序防火墙
- 实战案例:实现CentOS 7编译安装基于httpd 模块方式的LAMP
- 在CentOS 7中,使用Yum安装MySQL的简单步骤(yummysql安装)
- centOS安装MySQL更为稳定便捷的选择(centos-mysql)
- CentOS系统上安装MySQL的正确姿势使用Yum命令一键安装(mysql yum安?)
- Flask框架学习笔记(一)安装篇(windows安装与centos安装)