>  기사  >  백엔드 개발  >  PHP 관리 종속성 도구인 Composer 설치 및 사용 정보

PHP 관리 종속성 도구인 Composer 설치 및 사용 정보

不言
不言원래의
2018-06-13 16:02:035577검색

Composer는 PHP에서 종속 관계를 관리하는 데 사용되는 도구입니다. 프로젝트에서 의존하는 외부 라이브러리(라이브러리)를 선언할 수 있으며 Composer가 이러한 종속 라이브러리 파일을 자동으로 설치합니다.

PHP Composer 설치

시스템 요구 사항:

Composer를 실행하려면 PHP5.3.2+ 이상의 환경이 필요합니다. 몇 가지 민감한 PHP 설정과 컴파일 플래그도 필요하지만, 비호환성이 있으면 설치 프로그램에서 경고를 표시합니다.

예를 들어, PHP 확장에 대한 요구 사항은 –disable-phar 없이 PHP를 설치하거나 다시 컴파일하는 것입니다

간단한 압축 파일 패키지가 아닌 소스 주소에서 패키지를 설치하려면 버전 제어를 설치해야 합니다. git, svn, hg 등과 같은 패키지용 도구입니다.

Composer는 다중 플랫폼과 호환되며 Windows, Linux 및 OSX에서 실행됩니다.

설치 실패에 대한 오류 메시지:

curl -sS https://getcomposer.org/installer | PHP 
#!/usr/bin/env php 
some settings on your machine make Composer unable to work properly. 
Make sure that you fix the issues listed below and run this script again:

The phar extension is missing. 
Install it or recompile php without –disable-phar

Your PHP (5.2.9) is too old, you must upgrade to PHP 5.3.2 or higher.

내 로컬 기본 개발 환경은 PHP 5.2.9입니다. PHP 5.2.9에 설치하려고 하면 버전이 너무 낮아서 업그레이드해야 한다는 메시지가 나타납니다. PHP 5.3 이상.

그래서 XAMPP 1.7.7 USB Lite 버전을 다운로드했습니다.

E:\USB\Dropbox\phpstorm\php53>E:\USB\xampp_177\php\php.exe -v 
PHP 5.3.8 (cli) (built: Aug 23 2011 11:50:20) 
Copyright (c) 1997-2011 The PHP Group 
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies

XAMPP 1.7.7의 PHP 환경은 5.3.8입니다. 내 PHP 환경이 PHP5.3.2 이상인지 확인한 후.

PHP 5.3 Composer 설치

E:\USB\Dropbox\phpstorm\php53>curl -sS https://getcomposer.org/installer | E:\USB\xampp_177\php\php.exe 
#!/usr/bin/env php 
Some settings on your machine may cause stability issues with Composer. 
If you encounter issues, try to change the following:

The openssl extension is missing, which will reduce the security and stability o 
f Composer. 
If possible you should enable it or recompile php with –with-openssl

Downloading…

Composer successfully installed to: E:\USB\Dropbox\phpstorm\php53\composer.phar 
Use it: php composer.phar

참고:

XAMPP 1.7.7 Apache의 SSL 모듈을 꺼서 Composer에서 경고 메시지를 표시하고 보안을 위해 SSL 모듈을 활성화하도록 권장했습니다. 이유. 켜지지 않아도 사용에는 영향을 미치지 않습니다.
설치 중 매개변수는 실제 PHP 환경 경로로 변경되어야 합니다. 예: E:USBxampp_177phpphp.exe
Composer를 PHP 경로 + 명령으로 사용합니다. 우리가 설치한 환경에서는 E:USBxampp_177php/ php.exe 작곡가.phar 명령.
내가 설치한 환경은 Windows에 있고 PHP 5.3 환경이 기본 PHP 명령에 속하지 않는 경우에는 /usr/php/53/usr/bin/php를 사용해야 합니다. 예:

curl -sS https://getcomposer.org/installer | /usr/php/53/usr/bin/php

설치가 완료되면 설치된 버전을 확인해주세요.

E:\USB\Dropbox\phpstorm\php53>E:\USB\xampp_177\php/php.exe composer.phar -V 
Composer version 0209bd31a0ac3aeb2a68fc81e2d03c71072bef33

PHP Composer 명령을 확인하세요:

E:\USB\Dropbox\phpstorm\php53>E:\USB\xampp_177\php/php.exe composer.phar 
  ______ 
 / ____/___ ____ ___ ____ ____ ________ _____ 
/ /  / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/ 
/ /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ / 
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/ 
          /_/ 
Composer version 0209bd31a0ac3aeb2a68fc81e2d03c71072bef33

Usage: 
 [options] command [arguments]

Options: 
 –help      -h Display this help message. 
 –quiet     -q Do not output any message. 
 –verbose    -v Increase verbosity of messages. 
 –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 
 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 
 help       Displays help for a command 
 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. 
 list       Lists commands 
 require     Adds required packages to your composer.json and installs the 
m 
 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

이런 식으로 PHP5.3 환경의 Composer가 설치되었습니다.

마찬가지로 PHP 5.4 환경도 설치할 수 있습니다.

PHP 5.4 Composer 설치

XAMPP 1.8.1 USB 라이트 버전을 다운로드하면 PHP5.4.7 환경이 제공됩니다.

E:\USB\Dropbox\phpstorm\php53>E:\USB\xampp_181\php\php.exe -v 
PHP 5.4.7 (cli) (built: Sep 12 2012 23:48:31) 
Copyright (c) 1997-2012 The PHP Group 
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies

버전이 PHP 5.3.2 이상인지 확인한 후 설치를 시작하세요.

E:\USB\Dropbox\phpstorm\php54>curl -sS https://getcomposer.org/installer | E:\USB\xampp_181\php\php.exe 
#!/usr/bin/env php 
Some settings on your machine may cause stability issues with Composer. 
If you encounter issues, try to change the following:

The openssl extension is missing, which will reduce the security and stability o 
f Composer. 
If possible you should enable it or recompile php with –with-openssl

Downloading…

Composer successfully installed to: E:\USB\Dropbox\phpstorm\php54\composer.phar 
Use it: php composer.phar

설치가 완료된 후 설치된 버전을 확인하세요.

E:\USB\Dropbox\phpstorm\php54>E:\USB\xampp_181\php/php.exe composer.phar -V 
Composer version 0209bd31a0ac3aeb2a68fc81e2d03c71072bef33

이렇게 해서 PHP 5.4 환경의 Composer도 성공적으로 설치되었습니다.

PHP Composer 사용

여기에서는 PHP Composer를 사용하여 Symfony 프레임워크를 설치하는 방법을 간략하게 설명합니다.

먼저 명령의 표준 형식을 간략하게 설명하겠습니다.

php composer.phar create-project symfony/framework-standard-edition path/ 2.2.1

첫 번째 매개변수 PHP는 PHP 실행 명령을 가리키는 로컬 PHP 개발 환경입니다.
두 번째 매개변수는 작곡가.phar 모드에서 다운로드됩니다.
세 번째 매개변수는 create-project와 같은 작업 명령으로, 소프트웨어 패키지에서 지정된 디렉터리에 새 프로젝트를 생성하기 위한 것입니다.
네 번째 매개변수는 로컬 설치 디렉터리입니다.
다섯 번째 매개변수는 설치된 소프트웨어 패키지의 버전입니다.

우리가 PHP5.4 환경에 설치한 위에서 언급한 Composer에 따르면 설치 명령은 다음과 같습니다.

E:\USB\Dropbox\phpstorm\php54>E:\USB\xampp_181\php/php.exe composer.phar create-project symfony/framework-standard-edition E:\USB\xampp_181\htdocs\Symfony 2.2.1

설치 결과:

Installing symfony/framework-standard-edition (v2.2.1) 
 – Installing symfony/framework-standard-edition (v2.2.1) 
  Downloading: 100%
Created project in E:\USB\xampp_181\htdocs\Symfony 
Loading composer repositories with package information 
Installing dependencies from lock file 
 – Installing doctrine/lexer (v1.0) 
  Downloading: 100%
 – Installing doctrine/annotations (v1.1) 
  Downloading: 100%
 – Installing doctrine/cache (v1.0) 
  Downloading: 100%
 – Installing doctrine/collections (v1.1) 
  Downloading: 100%
 – Installing twig/twig (v1.12.2) 
  Downloading: 100%
 – Installing psr/log (1.0.0) 
  Downloading: 100%
 – Installing doctrine/inflector (v1.0) 
  Downloading: 100%
 – Installing doctrine/common (2.4.0-RC1) 
  Downloading: 100%
 – Installing symfony/symfony (v2.2.1) 
  Downloading: 100%
 – Installing jdorn/sql-formatter (v1.2.0) 
  Downloading: 100%
 – Installing doctrine/dbal (2.3.3) 
  Downloading: 100%
 – Installing doctrine/doctrine-bundle (v1.2.0-beta1) 
  Downloading: 100%
 – Installing doctrine/orm (2.3.3) 
  Downloading: 100%
 – Installing jms/cg (1.0.0) 
  Downloading: 100%
 – Installing phpoption/phpoption (1.2.0) 
  Downloading: 100%
 – Installing jms/parser-lib (1.0.0) 
  Downloading: 100%
 – Installing jms/metadata (1.3.0) 
  Downloading: 100%
 – Installing jms/aop-bundle (1.0.0) 
  Downloading: 100%
 – Installing jms/di-extra-bundle (1.3.0) 
  Downloading: 100%
 – Installing jms/security-extra-bundle (1.4.0) 
  Downloading: 100%
 – Installing sensio/distribution-bundle (v2.2.1) 
  Downloading: 100%
 – Installing sensio/framework-extra-bundle (v2.2.1) 
  Downloading: 100%
 – Installing sensio/generator-bundle (v2.2.1) 
  Downloading: 100%
 – Installing kriswallsmith/assetic (v1.1.0-alpha4) 
  Downloading: 100%
 – Installing symfony/assetic-bundle (v2.1.2) 
  Downloading: 100%
 – Installing monolog/monolog (1.4.1) 
  Downloading: 100%
 – Installing symfony/monolog-bundle (v2.2.0) 
  Downloading: 100%
 – Installing swiftmailer/swiftmailer (v4.3.0) 
  Downloading: 100%
 – Installing symfony/swiftmailer-bundle (v2.2.0) 
  Downloading: 100%
 – Installing twig/extensions (v1.0.0) 
  Downloading: 100%

kriswallsmith/assetic suggests installing leafo/lessphp (Assetic provides the integration with the lessphp LESS compiler) 
kriswallsmith/assetic suggests installing leafo/scssphp (Assetic provides the integration with the scssphp SCSS compiler) 
kriswallsmith/assetic suggests installing leafo/scssphp-compass (Assetic provides the integration with the SCSS compass plugin) 
kriswallsmith/assetic suggests installing ptachoire/cssembed (Assetic provides the integration with phpcssembed to embed data uris) 
monolog/monolog suggests installing doctrine/couchdb (Allow sending log messages to a CouchDB server) 
monolog/monolog suggests installing ext-amqp (Allow sending log messages to an AMQP server (1.0+ required)) 
monolog/monolog suggests installing ext-mongo (Allow sending log messages to a MongoDB server) 
monolog/monolog suggests installing mlehner/gelf-php (Allow sending log messages to a GrayLog2 server) 
monolog/monolog suggests installing raven/raven (Allow sending log messages to a Sentry server) 
Generating autoload files 
Clearing the cache for the dev environment with debug true 
Installing assets using the hard copy option 
Installing assets for Symfony\Bundle\FrameworkBundle into web/bundles/framework 
Installing assets for Acme\DemoBundle into web/bundles/acmedemo 
Installing assets for Sensio\Bundle\DistributionBundle into web/bundles/sensiodistribution

명령줄 결과에서 전체 내용을 볼 수 있습니다. Symfony 프레임워크 설치 과정 및 결과.

PHP Composer는 종속성을 정의합니다

Composer는 사용 시 자동으로 작곡가.json 파일을 찾습니다. 작곡가.json은 전체 프로젝트의 종속성 패키지를 정의하는 데 사용됩니다. 예:

{ 
  "require": { 
    "monolog/monolog": "1.2.*" 
  } 
}

종속 패키지에 대한 간단한 설명입니다. 우리 프로젝트에는 1.2부터 시작하는 모든 버전의 일부 모노로그/모놀로그 패키지가 필요합니다.

Composer는 PHP의 종속성 관리 도구입니다. Composer를 사용하면 소프트웨어를 게시할 때 많은 파일을 저장할 수 있고 종속 패키지의 버전을 제어할 수 있습니다.

위 내용은 이 글의 전체 내용입니다. 모든 분들의 학습에 도움이 되었으면 좋겠습니다. 더 많은 관련 내용은 PHP 중국어 홈페이지를 주목해주세요!

관련 권장 사항:

PHP 프레임워크 Laravel 플러그인 페이지 매김을 사용하여 사용자 정의 페이징을 구현하는 방법 정보

위 내용은 PHP 관리 종속성 도구인 Composer 설치 및 사용 정보의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.