Install and use the dependency management tool Composer in PHP, dependencycomposer

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

Install and use the dependency management tool Composer in PHP, dependencycomposer

Install PHP Composer

System Requirements:

Composer needs PHP5.3.2 + and above to run. Several sensitive PHP settings and compilation flags are also required, but the installer issues a warning when there is any incompatibility.

For example, PHP extension requires that php without-disable-phar be installed or re-compiled.

To install a software package from the source address, instead of simply compressing the file package, you will need to install the software package's version control tools, such as git, svn, or hg.

Composer is compatible with multiple platforms and runs on Windows, Linux, and OSX.

Error message of 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 that you 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, you must upgrade to PHP 5.3.2 or higher.

My local development environment is PHP 5.2.9 by default. When I try to install it on PHP 5.2.9, the system prompts that the version is too low and needs to be upgraded to PHP 5.3.2 or later.

So I downloaded 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

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

Install Composer in PHP 5.3

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-opensslDownloading…Composer successfully installed to: E:\USB\Dropbox\phpstorm\php53\composer.phar Use it: php composer.phar

Note:

I disabled the SSL module of XAMPP 1.7.7 Apache, so Composer prompts me to warn me that I should enable the SSL module for security reasons. It is not enabled or affected.
Parameter during installation | PHP, which must be changed to the actual PHP environment path, for example, | E: \ USB \ xampp_177 \ php \ php.exe
Use Composer as the PHP path + command. In our installation environment, use the E: \ USB \ xampp_177 \ php/php.exe composer. phar command.
The environment I installed is in Windows. If it is in Linux and the PHP 5.3 environment is not in the default PHP Command, |/usr/php/53/usr/bin/php should be used, 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] 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

In this way, we have installed the Composer in the PHP5.3 environment.

You can install PHP 5.4 in a similar way.

Install Composer in PHP 5.4

Download XAMPP 1.8.1 usb lite to 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

After confirming that the version is later 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 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-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 the PHP 5.4 environment is successfully installed.

PHP Composer usage

Here I will only demonstrate how to use PHP Composer to install the Symfony framework.

First, we will 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 and points to the PHP running command.
The second parameter is downloaded in composer. phar mode.
The third parameter is an action command, such as create-project, to create a new project from a software package to a specified directory.
The fourth parameter is the local installation directory.
The fifth parameter is the version of the installation package.

According to the above-mentioned Composer installed in the PHP5.4 environment, our installation command is:

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 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

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

PHP Composer define dependency

Composer will automatically search for the file composer. json when used. Composer. json is used to define the dependent packages of the entire project. For example:

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

The dependency package is simple description. Our project requires some monolog/monolog packages of any version starting from 1.2.

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

PHP Composer Project

Composer official: http://getcomposer.org

Composer Github: https://github.com/composer/composer

PHP Composer packages: https://packagist.org/


When you install composer setup in wamp, The following error occurs: The openssl extension is missing.

No. Change the integration package phpstudy. Openssl is configured by default. Phpstudy extension management is very convenient and can be checked during use .. Supports one-click switching from php5.2 to 5.6

Yii2 encountered the following error when using composer for installation ,......

You have not enabled mongodb extension in php ~~~~ It's okay with Composer.

Open your php. ini and enable mongodb extension (remove the previous)

Restart your server (apache, iis ...)

Try again.

I don't know if it's linux. Search for it.

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.