PHP management relies on of dependency relational tool Composer installation and use

  • 2021-07-13 04:35:05
  • OfStack

PHP Composer Installation

System requirements:

Composer requires an environment above PHP 5.3. 2 + to run. Several sensitive PHP settings and compile flags are also required, but the installer will issue a warning if there is any incompatibility.

For example, the extension of PHP requires that php without disable-phar be installed or recompiled

To install the package from the source address, rather than simply compressing the package, you will need to install version control tools for the package, such as git, svn, or hg.

Composer is multi-platform compatible and runs 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 that you fix the issues listed below and run this script again:

The phar extension is missing. 
Install it or recompile php without  In fact, in fact, the disable-phar

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

My local default development environment is PHP 5.2. 9, and when I tried to install it on PHP 5.2. 9, I was prompted that the version was too low and I needed to upgrade to PHP 5.3. 2 or later.

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. After confirming that my PHP environment is greater than or equal to PHP 5.3. 2.

PHP 5.3 Installing 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  In fact, in fact, the with-openssl

Downloading … 

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

Note:

I turned off the SSL module of XAMPP 1.7. 7 Apache, so Composer prompted me to warn, and it is recommended that I turn on the SSL module for security reasons. Do not open and do not affect the use.
The installation parameters PHP, 1 must be changed to the real PHP environment path, such as E:\ USB\ xampp_177\ php\ php.exe
Using Composer as the PHP path + command, in the environment we installed, we used the command E:\ USB\ xampp_177\ php/php. exe composer. phar.
The environment I installed is under Windows. If the PHP 5.3 environment is not under the default PHP command, the/usr/php/53/usr/bin/php should be adopted, 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

Usage: 
 [options] command [arguments]

Options: 
  In fact, in fact, the help      -h Display this help message. 
  In fact, in fact, the quiet     -q Do not output any message. 
  In fact, in fact, the verbose    -v Increase verbosity of messages. 
  In fact, in fact, the version    -V Display this application version. 
  In fact, in fact, the ansi       Force ANSI output. 
  In fact, in fact, the no-ansi      Disable ANSI output. 
  In fact, in fact, the no-interaction -n Do not ask any interactive question. 
  In fact, in fact, the profile      Display timing and memory usage information 
  In fact, in fact, the 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

So we have installed Composer in PHP 5.3 environment.

We can also install PHP 5.4 in a similar way.

PHP 5.4 Installing Composer

Download the XAMPP 1.8. 1 usb lite version to get the PHP 5.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 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 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  In fact, in fact, the 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

Thus, the Composer in the PHP 5.4 environment was successfully installed.

PHP Composer uses

Here I will simply demonstrate installing the Symfony framework using PHP Composer.

First, explain the standard format of 1 command:


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

The first parameter, PHP, is the native PHP development environment and points to the PHP run command.
The second parameter is downloaded in composer. phar mode.
The third parameter, an action command, such as create-project, is intended to create a new project from 1 package to the specified directory.
The fourth parameter is the directory of the local installation.
The fifth parameter is the version of the installation package.

According to the above we installed Composer in the PHP 5.4 environment, our installation command is:


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

0

Installation results:


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

1

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

PHP Composer Defining Dependencies

Composer will automatically look for the file composer. json when it is used. composer. json will be used to define dependency packages for the entire project. For example:


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

2

Depending on the simple description of the package, our project needs 1 monolog/monolog package of any version starting from 1.2.

Composer is a dependency management tool in PHP. With Composer, we can save a lot of files and control the version of dependent packages when releasing 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/


Related articles: