linux(ubuntu 21.10): 安装composer 2.2.0(php 8.1.1)


一,配置php命令可以直接访问:

1,把php的bin目录加入到$PATH变量中
root@lhdpc:~# vi /etc/profile
增加内容:
export PHP_HOME=/usr/local/soft/php8
export PATH=$PATH:$PHP_HOME/bin
使生效
root@lhdpc:~# source /etc/profile
测试效果:
liuhongdi@lhdpc:/usr/local/soft$ php --version
PHP 8.1.1 (cli) (built: Dec 20 2021 16:12:16) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.1, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.1, Copyright (c), by Zend Technologies

说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest

         对应的源码可以访问这里获取: https://github.com/liuhongdi/
         或: https://gitee.com/liuhongdi

说明:作者:刘宏缔 邮箱: 371125307@qq.com

 

二,安装curl

1,查看是否安装了curl
liuhongdi@lhdpc:/usr/local/source$ whereis curl
curl:
2,安装curl
liuhongdi@lhdpc:/usr/local/source$ sudo apt-get install curl
3,查看安装效果:
liuhongdi@lhdpc:/usr/local/source$ curl --version
curl 7.74.0 (x86_64-pc-linux-gnu) libcurl/7.74.0 OpenSSL/1.1.1l zlib/1.2.11 brotli/1.0.9 libidn2/2.3.1 
libpsl/0.21.0 (+libidn2/2.3.0) libssh/0.9.6/openssl/zlib nghttp2/1.43.0 librtmp/2.3 Release-Date: 2020-12-09 Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps mqtt pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp Features: alt-svc AsynchDNS brotli GSS-API HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM NTLM_WB PSL SPNEGO SSL TLS-SRP UnixSockets

三,安装composer

1,检查是否已安装composer
liuhongdi@lhdpc:/usr/local/source$ whereis composer
composer:
2,安装composer
liuhongdi@lhdpc:/usr/local/source$ curl -sS https://getcomposer.org/installer | /usr/local/soft/php8/bin/php
All settings correct for using Composer
Downloading...
 
Composer (version 2.2.0) successfully installed to: /usr/local/source/composer.phar
Use it: php composer.phar
3,移动composer到/usr/local/bin目录下
liuhongdi@lhdpc:/usr/local/source$ sudo mv composer.phar /usr/local/bin/composer
liuhongdi@lhdpc:/usr/local/soft$ composer --version
Composer version 2.2.0 2021-12-22 11:03:27

四,修改composer的配置,使用国内源:

1,查看默认配置:
liuhongdi@lhdpc:/usr/local/soft$ composer config -l -g
[repositories.packagist.org.type] composer
[repositories.packagist.org.url] https://repo.packagist.org
[process-timeout] 300
[use-include-path] false
[allow-plugins]
[use-parent-dir] prompt
[preferred-install] dist
[notify-on-install] true
[github-protocols] [https, ssh]
[gitlab-protocol]
[vendor-dir] vendor (/usr/local/soft/vendor)
[bin-dir] {$vendor-dir}/bin (/usr/local/soft/vendor/bin)
[cache-dir] /home/liuhongdi/.cache/composer
[data-dir] /home/liuhongdi/.local/share/composer
[cache-files-dir] {$cache-dir}/files (/home/liuhongdi/.cache/composer/files)
[cache-repo-dir] {$cache-dir}/repo (/home/liuhongdi/.cache/composer/repo)
[cache-vcs-dir] {$cache-dir}/vcs (/home/liuhongdi/.cache/composer/vcs)
[cache-ttl] 15552000
[cache-files-ttl] 15552000
[cache-files-maxsize] 300MiB (314572800)
[cache-read-only] false
[bin-compat] auto
[discard-changes] false
[autoloader-suffix]
[sort-packages] false
[optimize-autoloader] false
[classmap-authoritative] false
[apcu-autoloader] false
[prepend-autoloader] true
[github-domains] [github.com]
[bitbucket-expose-hostname] true
[disable-tls] false
[secure-http] true
[cafile]
[capath]
[github-expose-hostname] true
[gitlab-domains] [gitlab.com]
[store-auths] prompt
[archive-format] tar
[archive-dir] .
[htaccess-protect] true
[use-github-api] true
[lock] true
[platform-check] php-only
[home] /home/liuhongdi/.config/composer
2,配置使用国内源
liuhongdi@lhdpc:/usr/local/soft$ composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

3,查看是否生效:

liuhongdi@lhdpc:/usr/local/soft$ composer config -l -g
[repositories.packagist.org.type] composer
[repositories.packagist.org.url] https://mirrors.aliyun.com/composer/
[process-timeout] 300
[use-include-path] false
[allow-plugins]
[use-parent-dir] prompt
[preferred-install] dist
[notify-on-install] true
[github-protocols] [https, ssh]
[gitlab-protocol]
[vendor-dir] vendor (/usr/local/soft/vendor)
[bin-dir] {$vendor-dir}/bin (/usr/local/soft/vendor/bin)
[cache-dir] /home/liuhongdi/.cache/composer
[data-dir] /home/liuhongdi/.local/share/composer
[cache-files-dir] {$cache-dir}/files (/home/liuhongdi/.cache/composer/files)
[cache-repo-dir] {$cache-dir}/repo (/home/liuhongdi/.cache/composer/repo)
[cache-vcs-dir] {$cache-dir}/vcs (/home/liuhongdi/.cache/composer/vcs)
[cache-ttl] 15552000
[cache-files-ttl] 15552000
[cache-files-maxsize] 300MiB (314572800)
[cache-read-only] false
[bin-compat] auto
[discard-changes] false
[autoloader-suffix]
[sort-packages] false
[optimize-autoloader] false
[classmap-authoritative] false
[apcu-autoloader] false
[prepend-autoloader] true
[github-domains] [github.com]
[bitbucket-expose-hostname] true
[disable-tls] false
[secure-http] true
[cafile]
[capath]
[github-expose-hostname] true
[gitlab-domains] [gitlab.com]
[store-auths] prompt
[archive-format] tar
[archive-dir] .
[htaccess-protect] true
[use-github-api] true
[lock] true
[platform-check] php-only
[home] /home/liuhongdi/.config/composer
可见国内源设置已生效

五,更新composer自身:

1,查看composer当前版本:
liuhongdi@lhdpc:/usr/local/soft$ composer --version
Composer version 2.2.0 2021-12-22 11:03:27 
2,注意切换到有权限的账号或用sudo
root@lhdpc:~# composer selfupdate
Upgrading to version 2.2.1 (stable channel).
   
Use composer self-update --rollback to return to version 2.2.0
3,查看效果:
liuhongdi@lhdpc:/usr/local/soft$ composer --version
Composer version 2.2.1 2021-12-22 22:21:31
升级成功了

六,查看php的版本:

liuhongdi@lhdpc:/usr/local/source$ /usr/local/soft/php8/bin/php --version
PHP 8.1.1 (cli) (built: Dec 20 2021 16:12:16) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.1, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.1, Copyright (c), by Zend Technologies

七,查看linux的版本:

liuhongdi@lhdpc:/usr/local/soft$ cat /etc/os-release
PRETTY_NAME="Ubuntu 21.10"
NAME="Ubuntu"
VERSION_ID="21.10"
VERSION="21.10 (Impish Indri)"
VERSION_CODENAME=impish
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=impish