Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the installation and use of Composer under Windows/Linux

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "what is the installation and use of Composer under Windows/Linux". In the daily operation, I believe that many people have doubts about the installation and use of Composer under Windows/Linux. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "what is the installation and use of Composer under Windows/Linux?" Next, please follow the editor to study!

Installation and use of Composer in Windows and Linux

One: install Composer

1. First of all, please make sure that you have correctly installed PHP,windows to open the command line window / linux to open the terminal, and execute php-v to see if you have typed the publication number correctly.

Windows

PS E:\ repository\ work > php-vPHP 7.0.32 (cli) (built: Sep 12 2018 15:54:08) (ZTS) Copyright (c) 1997-2017 The PHP GroupZend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies

Centos

[root@jmsiteos7] # php-vPHP 7.2.13 (cli) (built: Dec 6 2018 23:18:37) (NTS) Copyright (c) 1997-2018 The PHP GroupZend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.13, Copyright (c) 1999-2018, by Zend Technologies

If php is installed, but the environment variable is not set, you need to set the environment variable

Windows

Windows sets environment variables

Exit and reopen the command line window, and type php-v again to check the version number. If it is still not normal, please check that the php directory is correct

Centos

Enter the following two lines in the vi / etc/profile# file: PATH=$PATH:/usr/local/php72/bin/:/usr/local/php72/sbin/export PATH# will take effect immediately source / etc/profile

Type php-v again to check the version number. If it is still not normal, please check whether the php directory is correct.

two。 Download Composer

Php-r "copy ('https://install.phpcomposer.com/installer',' composer-setup.php');"

3. Install Composer

Php composer-setup.php

4. Remove installer

Php-r "unlink ('composer-setup.php');"

5. Partial installation

After the process of downloading Composer is completed correctly, you can copy the composer.phar file to any directory (such as the project root), and then use the php composer.phar command to use Composer!

6. Global installation

Centos

Open the terminal and execute the following command to move the previously downloaded composer.phar file to the / usr/local/bin/ directory:

Mv composer.phar / usr/local/bin/composer

Windows

Go to the PHP installation directory, copy composer.phar to the PHP installation directory, create a new composer.bat file under the PHP installation directory, and save the following code to this file

@ php "% ~ dp0composer.phar"% *

Reopen a command line window and try to execute composer-- version to see if the version number is printed correctly

Windows

PS E:\ repository\ work > composer-- versionComposer version 1.8.0 2018-12-03 10:31:16

Centos

[root@jmsite ~] # composer-- versionDo not run Composer as root/super user! See https://getcomposer.org/root for detailsComposer version 1.8.0 2018-12-03 10:31:16

The official explanation is that some Composer commands, including exec,install and update, allow third-party code to execute on your system.

This comes from its "plug-in" and "script" features. Plug-ins and scripts have full access to the user account running Composer. Therefore, it is strongly recommended that you avoid running Composer as superuser / root.

7. Upgrade Composer

Composer selfupdate

8. Set composer domestic source

Composer config-g repo.packagist composer https://packagist.phpcomposer.com II: using Composer

1. Based on composer.json

Create a composer.json file in the project's directory that describes the project's dependencies.

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

Indicates that you need to download any version of monolog starting with 1.2, and use the following command to install the code base

Composer install

two。 Based on require command

If you find it troublesome to create a composer.json file, you can also use the require command during installation

Composer require monolog/monolog

Composer will look for code base information and automatically create composer.json files and composer.lock files

3. Update all code bases in the project, or some of the code bases specified

# Update all code bases composer update# update the specified code base composer update monolog/monolog# update the specified multiple code bases composer update monolog/monolog phpaes/phpaes# can also match the code base composer update monolog/monolog phpaes/* through wildcards

4. Remove a code base, which cannot be removed if it is used by another code base

Composer remove monolog/monolog

5. Search for a code base in the source

Composer search monolog

6. View code base information

# display the installed code base composer show# to filter composer show monolog/*# specific code base information through wildcards composer show monolog/monolog

Automatic loading

In addition to downloading the code base, Composer also prepares an auto-load file that loads all the class files in the code base downloaded by Composer. To use it, you only need to add the following line of code to the boot file of your project

Require 'vendor/autoload.php';#$log = new Monolog\ Logger (' name'); $log- > pushHandler (new Monolog\ Handler\ StreamHandler ('app.log', Monolog\ Logger::WARNING)); $log- > addWarning (' Foo'); at this point, the study on "what is the installation and use of Composer under Windows/Linux" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report