About PHP Management dependent tools Composer installation and use

Source: Internet
Author: User
Tags autoload autoloader mongodb server php development environment couchdb
Composer is a tool used in PHP to manage dependency (dependency) relationships. You can declare your dependencies on the External tool Library (libraries) in your project, and composer will help you install these dependent library files.

PHP Composer Installation

System Requirements:

Composer need to php5.3.2+ above the environment to run. There are several sensitive PHP settings and compilation flags that are required, but the installer warns you when there are any incompatibilities.

For example, the requirement of PHP extension is to install or recompile PHP Without–disable-phar

In order to install the package from the source address, rather than simply compressing the package, you will need to install a version control tool for the package, such as Git, SVN, or HG.

The Composer is a multi-platform compatible operation for Windows,linux and OSX.

Error message for installation failure:

Curl-ss Https://getcomposer.org/installer | PHP #!/usr/bin/env php Some settings on your machine make Composer unable to work properly. Make sure, the fix the issues listed below and run this script again:the Phar extension is missing. Install it or recompile php without–disable-pharyour php (5.2.9) is too old and you must upgrade to PHP 5.3.2 or higher.

My local default development environment is PHP 5.2.9, when I try to install on PHP 5.2.9, the prompt version is too low, need to upgrade to PHP 5.3.2 or higher version.

So I downloaded the XAMPP 1.7.7 USB Lite version.

e:\usb\dropbox\phpstorm\php53>e:\usb\xampp_177\php\php.exe-v php 5.3.8 (CLI) (Built:aug 11:50:20) Copyright (c) 1997-2011 the PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies

The PHP environment under XAMPP 1.7.7 is 5.3.8. Verify that my PHP environment is greater than or equal to PHP5.3.2.

PHP 5.3 Installation 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 could cause stability issues with Composer. If you encounter issues, try-to-change the following:the OpenSSL extension is missing, which would reduce the security and Stability o f Composer. If possible you should enable it or recompile PHP with–with-openssldownloading ... Composer successfully installed To:e:\usb\dropbox\phpstorm\php53\composer.phar use it:php Composer.phar

Attention:

I closed the SSL module for XAMPP 1.7.7 Apache, so composer prompted me to warn that I was advised to turn on the SSL module for security reasons. Does not open and does not affect use.
Parameters at the time of installation | PHP, be sure to change to a real PHP environment path, such as | E:\USB\xampp_177\php\php.exe
Using composer as the PHP path + command, in our installed environment, use the method: E:\usb\xampp_177\php/php.exe Composer.phar command.
I installed the environment under Windows, if under Linux, and the PHP 5.3 environment is not under the default PHP command, you should use | /usr/php/53/usr/bin/php, for example:

Curl-ss Https://getcomposer.org/installer | /usr/php/53/usr/bin/php

After the installation is complete, check the installation version.

E:\usb\dropbox\phpstorm\php53>e:\usb\xampp_177\php/php.exe composer.phar-v Composer version 0209bd31a0ac3aeb2a68fc81e2d03c71072bef33

Check the PHP composer command:

E:\usb\dropbox\phpstorm\php53>e:\usb\xampp_177\php/php.exe Composer.phar ___/____/___ ____ ___ ____ ____ ___ __ _____ / /  / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/ / /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ / \____/\____/_/ /_ //_/. ___/\____/____/\___/_//_/Composer version 0209bd31a0ac3aeb2a68fc81e2d03c71072bef33usage: [Options] com  Mand [arguments]options:–help-h Display this help message.  –quiet-q does not output an 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 don't ask any interactive question. –profile Display Timing and memory usage information–working-dir-d If specified, use the given directory as Worki ng directory.  Available commands:about Short information about Composer archive Create A archive of this Composer package Config Set config options create-projECT Create new project from a to 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

This way our composer in the PHP5.3 environment has been installed.

Similar method we can also install PHP 5.4 environment.

PHP 5.4 Installation Composer

Download the XAMPP 1.8.1 USB Lite version and get the PHP5.4.7 environment.

e:\usb\dropbox\phpstorm\php53>e:\usb\xampp_181\php\php.exe-v php 5.4.7 (CLI) (Built:sep 23:48:31) Copyright (c) 1997-2012 the PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies

After determining that the version is higher than PHP 5.3.2, start the installation:

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 could cause stability issues with Composer. If you encounter issues, try-to-change the following:the OpenSSL extension is missing, which would reduce the security and Stability o f Composer. If possible you should enable it or recompile PHP with–with-openssldownloading ... Composer successfully installed To:e:\usb\dropbox\phpstorm\php54\composer.phar use it:php Composer.phar

After the installation is complete, check the installation version.

E:\usb\dropbox\phpstorm\php54>e:\usb\xampp_181\php/php.exe composer.phar-v Composer version 0209bd31a0ac3aeb2a68fc81e2d03c71072bef33

In this way, the composer in PHP 5.4 environment is also installed successfully.

PHP Composer Use

Here I simply demonstrate the installation of the Symfony framework using PHP composer.

Let's take a look at the standard format of the command:

PHP Composer.phar create-project symfony/framework-standard-edition path/2.2.1

The first parameter PHP is the local PHP development environment, pointing to the PHP Run command.
The second parameter, downloaded for Composer.phar mode.
The third parameter, for action commands, such as Create-project, is intended to create a new project from a package to the specified directory.
The fourth parameter is a locally installed directory.
The fifth parameter is the version of the installation package.

According to the above composer we installed in the PHP5.4 environment, our installation commands are:

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

Installation Result:

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 do Ctrine/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) do Wnloading: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) Downloadi Ng:100%–installing Jms/aop-bundle (1.0.0) downloading:100%–installing jms/di-extra-bundle (1.3.0) downloading:1   00%–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-bu Ndle (v2.2.1) downloading:100%–installing kriswallsmith/assetic (V1.1.0-ALPHA4) downloading:100%–installing SYMF Ony/assetic-bundle (v2.1.2) downloading:100%–installing monolog/monolog (1.4.1) downloading:100%–installing SYMF Ony/monolog-bundle (v2.2.0) downloading:100%–installing Swiftmailer/swiftmailer (v4.3.0) downloading:100%–instal Ling Symfony/swiftmailer-bundle (v2.2.0) downloading:100%–installing twig/extensions (v1.0.0) downloading:100%kriswallsmith/assetic sugges TS Installing leafo/lessphp (Assetic provides the integration with the lessphp less compiler) kriswallsmith/assetic sugges TS Installing leafo/scssphp (Assetic provides the integration with the scssphp SCSS compiler) Kriswallsmith/assetic sugges TS 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/mono Log suggests installing DOCTRINE/COUCHDB (allow sending log messages to a COUCHDB server) Monolog/monolog suggests install ing 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 m Essages 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 a Ssets for Symfony\bundle\frameworkbundle to web/bundles/framework installing assets for Acme\demobundle into web/ Bundles/acmedemo installing assets for Sensio\bundle\distributionbundle into web/bundles/sensiodistribution

From the command line results, we see the installation process and results for the entire symfony framework.

PHP Composer Defining dependencies

Composer will automatically look for Composer.json this file when it is in use. Composer.json will be used to define the dependency package for the entire project. For example:

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

Depending on the package's simple description, our project requires some Monolog/monolog packages starting from 1.2 for any version.

Composer is a dependency management tool in PHP. With composer we can save a large number of files and control the version of a dependent package when releasing the software.

The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.