PHP Management Dependency (dependency) Relationship tool Composer installation and use _php tips

Source: Internet
Author: User
Tags autoload autoloader curl mongodb server openssl php development environment zend couchdb

PHP Composer Installation

System Requirements:

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

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

To install packages from a source address, rather than a simple compressed package, you will need to install the package's version control tools, such as Git, SVN, or HG.

The Composer is compatible with multiple platforms and is run for Windows,linux and OS X.

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. 
Make sure so 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, and 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 the PHP 5.2.9, the hint 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 23 2011 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 Com Poser. 
If you are encounter issues, try to change the following:

the OpenSSL extension is missing, which'll reduce the Securit Y 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

Attention:

I turned off the SSL module for XAMPP 1.7.7 Apache, so composer prompted me to warn me to open the SSL module for security reasons. Does not open and does not affect the use.
Parameters for Installation | PHP, be sure to change to a real PHP environment path, such as | E:\USB\xampp_177\php\php.exe
Use composer for PHP path + command, in our installed environment, the use of the method is: E:\usb\xampp_177\php/php.exe composer.phar command.
I installed the environment is under Windows, if under Linux, and the PHP 5.3 environment is not 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 0209bd31a0ac3aeb2a68fc81e2d03c71072bef33: [O 
 ptions] command [arguments] options:–help-h Display this help message. 
 –QUIET-Q does 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 don't ask any interactive question. –profile Display Timing and memory usage information–working-dir-d If specified, use the given directory as work

ing 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 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 then 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 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 yo ur dependencies to the lateSt version according to Composer.json, and updates the Composer.lock file.

 Validate Validates a Composer.json

So our composer in the PHP5.3 environment has been installed.

A similar approach can also be installed in 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 12 2012 23:48:31) 
Copyright (c) 1997-2012 the PHP Group 
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies

When you are sure the version is higher than the 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 Com Poser. 
If you are encounter issues, try to change the following:

the OpenSSL extension is missing, which'll 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

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 the PHP 5.4 environment has also been installed successfully.

PHP Composer Use

Here I simply demonstrate the use of PHP composer to install the Symfony framework.

First, I'll explain 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 is downloaded for the Composer.phar mode.
The third parameter, for action commands, such as Create-project, is designed to create a new project from a package to a specified directory.
The fourth parameter is the locally installed directory.
The fifth parameter is the version of the installation package.

According to the above we installed in the PHP5.4 environment composer, 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 results:

Installing Symfony/framework-standard-edition (v2.2.1) –installing symfony/framework-standard-edition (v2.2.1) down 
loading: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/an Notations (v1.1) downloading:100%–installing Doctrine/cache (v1.0) downloading:100%–installing Doctrine/coll 
  Ections (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 (v 1.2.0-BETA1) DownloadIng:100%–installing doctrine/orm (2.3.3) downloading:100%–installing JMS/CG (1.0.0) downloading:100%–ins Talling phpoption/phpoption (1.2.0) downloading:100%–installing jms/parser-lib (1.0.0) downloading:100%–inst Alling Jms/metadata (1.3.0) downloading:100%–installing jms/aop-bundle (1.0.0) downloading:100%–installing J Ms/di-extra-bundle (1.3.0) downloading:100%–installing jms/security-extra-bundle (1.4.0) downloading:100%–in 
  Stalling 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 Mono Log/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/ex Tensions (v1.0.0) downloading:100% kriswallsmith/assetic suggests installing leafo/lessphp (Assetic provides the inte Gration with the lessphp less compiler) Kriswallsmith/assetic suggests installing leafo/scssphp (assetic provides the int Egration with the scssphp scss compiler) Kriswallsmith/assetic suggests installing Leafo/scssphp-compass (assetic provide s the integration with the Scss Compass plugin) kriswallsmith/assetic suggests installing ptachoire/cssembed (Assetic Pro Vides the integration with phpcssembed to embed data URIs) Monolog/monolog suggests installing doctrine/couchdb (Allow SE Nding log messages to a CouchDB server) Monolog/monolog suggests installing EXT-AMQP (Allow sending log messages to an AM  
QP 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 rave N/raven (Allow sending log messages to a Sentry server) generating autoload files clearing the cache for the dev environ ment with debug true installing assets using the hard copy option installing assets for Symfony\bundle\frameworkbundle I Nto web/bundles/framework Installing assets for Acme\demobundle to Web/bundles/acmedemo installing for assets

 Undle\distributionbundle into Web/bundles/sensiodistribution

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

PHP Composer Define 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 simple description, our project requires some Monolog/monolog packages starting with any version of 1.2.

Composer is a dependency management tool in PHP. By composer We can save a lot of file numbers and control the version of a dependency package when we publish the software.

PHP Composer Project

Composer Project official: http://getcomposer.org

Composer GitHub Project: Https://github.com/composer/composer

PHP Composer Package list: https://packagist.org/

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.