By Erika Heidi
Developer Advocate
Neste guia de início rápido, instalaremos o Composer em um servidor Ubuntu 20.04.
Para uma versão mais detalhada deste tutorial, contendo explicações mais detalhadas para cada passo, confira Como instalar e configurar o Composer no Ubuntu 20.04.
Para seguir este guia, você precisará ter acesso a um servidor Ubuntu 20.04 como um usuário sudo
.
Comece atualizando o cache do gerenciador de pacotes e instalando as dependências necessárias, incluindo o php-cli
:
- sudo apt update
- sudo apt install php-cli unzip
Certifique-se de estar em seu diretório home. Em seguida, baixe o instalador do Composer usando o curl
:
- cd ~
- curl -sS https://getcomposer.org/installer -o composer-setup.php
Em seguida, vamos verificar se o instalador baixado corresponde ao hash SHA-384 para o instalador mais recente encontrado na página Composer Public Keys / Signatures.
Usando o curl
, pegue a última assinatura e armazene-a em uma variável shell:
- HASH=`curl -sS https://composer.github.io/installer.sig`
Agora, execute o seguinte código PHP para verificar se o script de instalação está seguro para ser executado:
- php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
Você verá o seguinte resultado:
Installer verified
Nota: se o resultado disser Installer corrupt
(Instalador corrompido), você precisará repetir o processo de download e verificação até que você tenha um instalador verificado.
O seguinte comando baixará e instalará o Composer como um comando de sistema chamado composer como um comando chamado composer
, em usr/local/bin
:
- sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
Você verá um resultado parecido com este:
OutputAll settings correct for using Composer
Downloading...
Composer (version 1.10.5) successfully installed to: /usr/local/bin/composer
Use it: php /usr/local/bin/composer
Para testar a sua instalação, execute:
- composer
Output ______
/ ____/___ ____ ___ ____ ____ ________ _____
/ / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
/_/
Composer version 1.10.5 2020-04-10 11:44:22
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
...
Isso verifica que o Composer foi instalado com sucesso em seu sistema e está disponível em todo o sistema.
Aqui estão os links para os guias mais detalhados relacionados a este tutorial:
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
Dev/Ops passionate about open source, PHP, and Linux. Former Senior Technical Writer at DigitalOcean. Areas of expertise include LAMP Stack, Ubuntu, Debian 11, Linux, Ansible, and more.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.