Composer về cơ bản là trình quản lý phụ thuộc cho ngôn ngữ lập trình PHP. Nó hoạt động như một loại trình quản lý dự án giúp lập trình viên quản lý các phụ thuộc sẽ được sử dụng trên cơ sở từng dự án.
Cài đặt phụ thuộc
apt update
apt install wget php-cli php-zip unzip
root@vps:~# apt install wget php-cli php-zip unzip
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
wget is already the newest version (1.21.2-2ubuntu1).
wget set to manually installed.
The following additional packages will be installed:
bzip2 libzip4 mailcap mime-support php-common php8.1-cli php8.1-common
php8.1-opcache php8.1-readline php8.1-zip
Suggested packages:
bzip2-doc php-pear zip
Tải xuống và cài đặt Composer
Hãy đảm bảo rằng bạn đang ở trong thư mục gốc của mình và tải xuống trình cài đặt Composer bằng wget.
cd ~
wget -O composer-setup.php https://getcomposer.org/installer
Output:
root@vps:~# cd ~
root@vps:~# wget -O composer-setup.php https://getcomposer.org/installer
--2022-05-26 10:16:07-- https://getcomposer.org/installer
Resolving getcomposer.org (getcomposer.org)... 142.44.245.229, 2607:5300:201:2100::4:d105
Connecting to getcomposer.org (getcomposer.org)|142.44.245.229|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 58140 (57K) [application/octet-stream]
Saving to: ‘composer-setup.php’
composer-setup.php 100%[===================>] 56.78K --.-KB/s in 0.08s
2022-05-26 10:16:07 (732 KB/s) - ‘composer-setup.php’ saved [58140/58140]
Bây giờ, hãy tải xuống và cài đặt Composer tại /usr/local/bin bằng cách chạy lệnh sau.
root@vps:~# php composer-setup.php --install-dir=/usr/local/bin --filename=composer
All settings correct for using Composer
Downloading...
Composer (version 2.3.5) successfully installed to: /usr/local/bin/composer
Use it: php /usr/local/bin/composer
Để kiểm tra cài đặt của bạn, hãy chạy lệnh sau.
root@vps:~# composer
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Continue as root/super user [yes]? y
______
/ ____/___ ____ ___ ____ ____ ________ _____
/ / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
/_/
Composer version 2.3.5 2022-04-13 16:43:00
Usage:
command [options] [arguments]
Options:
-h, --help Display help for the given command. When no command is given display help for the list command
-q, --quiet Do not output any message
-V, --version Display this application version
Điều này xác minh rằng Composer đã được cài đặt thành công trên hệ thống của bạn.