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

Process Analysis of Composer installation and configuration

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

Share

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

Composer installation and configuration process analysis, in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.

Installation and configuration of Composer under Windows and Linux

Introduction: Composer is a tool used by PHP to manage dependency relationships. You can declare the dependent external libraries (libraries) in your project, and Composer will help you install these dependent library files.

(1) Window installation 1.1 download Composer

Download the Composer.exe application (https://getcomposer.org/)) on the Composer official website

1.2 install Composer

The downloaded version is the latest version of Composer and the PATH environment variable is automatically set so that you can call Composer from any directory

Choose according to the version of the local php configuration, and then install it in the next step.

Global configuration

① search for "path"-> Open "Edit system environment variables"-"environment variables"

② configure Administrator user variabl

1.3 successful installation # win+R enter cmd to enter C:\ Users\ Administrator > composer _ / / _ / / / Composer version 2.1.9 2021-10-05 09:47:38 (II) Linux installation 2. 1 download Composer**# to the root directory to download * * [root@VM-12-9-centos /] curl-sS https://getcomposer.org/installer | phpComposer (version 2.1.9) successfully installed to: / / composer.pharUse it: php composer.phar # download succeeded # Tip: request failure may occur because of the external network Try more patiently and you will succeed.

If downloads fail frequently, you can use Aliyun's image to download.

# this image is synchronized with Packagist in real time. It is recommended to use the latest Composer version.

[root@VM-12-9-centos /] curl-sS mirrors.aliyun.com/composer/compos...

2.2 Global configuration # copy composer.phar to the directory where the composer is generated under the / usr/local/bin/ directory to facilitate the global use of [root@VM-12-9-centos /] mv composer.phar / usr/local/bin/composer2.3 to change the image source

As the request of foreign websites in China will be very slow, so we can change the domestic source to speed up the download of the source. There are many kinds of domestic mirror sources. Here are several commonly used ones. You can choose one of them according to your needs.

Aliyun Composer image [recommended]

Composer config-g repo.packagist composer https://mirrors.aliyun.com/composer/

Domestic cloud Composer image

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

Tencent Cloud Composer image

Composer config-g repo.packagist composer https://mirrors.cloud.tencent.com/composer/

Huawei Cloud Composer Image

Composer config-g repo.packagist composer https://repo.huaweicloud.com/repository/php/

An Changyun Composer image

Composer config-g repo.packagist composer https://yisu.compkg.org/2.4 installed successfully [root@VM-12-9-centos etc] # composer _ / _ ``_ _ / _ / _ \ / / / Composer version 2.1.9 2021-10-05 09:47:38 (III) Composer Command 3.1 check the version composer-- version# check the version and you will see the current version and update time [root@VM-12-9-centos /] # composer-- versionComposer version 2.1.9 2021-10-05 09GV 47GV 383.2 this upgrade # upgrade will default to the latest version composer self-update# * * Tip: * * The version upgrade command will download composer from the official version Phar image, speed will be limited! It is strongly recommended that the global configuration acceleration image 3. 3 execute the diagnostic command composer diagnose3.4 clear cache composer clear3.5 project update composer.lockcomposer update-- lock3.6 debugging # * * Composer debugging only needs to add-vvv before the command to print error messages * * # for example, download laravel named blog project composer-vvv create-project laravel/laravel blog3.7 installation dependency package # this command is limited to the project root only Directory operation composer install3.8 update dependency package # this command is limited to project root operation # update all dependency packages composer update### update specified dependency package composer update monolog/monolog### update multiple specified dependency packages composer update monolog/monolog symfony/dependency-injection### update dependency packages composer update monolog/monolog symfony/*3.9 remove dependency packages # remove specified dependencies based on wildcard matching Package composer remove monolog/monolog# remove dependency package based on wildcard matching composer remove monolog/monolog symfony/*3.10 search dependency package # search dependency package: output package and its description composer search monolog# search package only:-- only-namecomposer search-- only-name monolog# search dependency package based on wildcard search composer search mono*3.11 View dependency package # * * this command is limited to the project root directory using * * # search Look at * * current project * * installed dependency package composer show# filter according to the wildcard * * current project * * composer show laravel*# view * * current project * * specify the use of the dependency package composer show laravel/tinker (4) Project

In projects, we often use composer to download and update packages or libraries, but we often encounter all kinds of problems in using them. Next, we will solve common problems.

4.1 Pagoda panel installation Composer

The installation of composer requires php to open the putenv function, otherwise the installation will fail! Because the putenv function can set specific environment variables and is considered a potential security vulnerability, php disables it by default at the beginning of installation!

Delete disable function

For security reasons, the pagoda panel automatically disables some functions; because the corresponding functions are also used to install Composer, we should first delete the installation of Composer. For   to install Composer, you need to delete the PHP disable function: putenv ()   Tip: when using Composer, you need to do something according to the php version of the project (you need to delete how many PHP versions are installed). The following figure shows that the operation is based on php-8.0.

Non-pagoda panel management operation

# enter php.ini profile Editing-- > search (enter / enter search mode Search disable_functions) #-> delete putenv**### step 1: query php.ini path * * [root@VM-12-9-centos 74] # find /-name "php.ini" / www/server/php/56/etc/php.ini/www/server/php/80/etc/php.ini/www/server/php/74/etc/php.ini**### step 2: edit php.ini File * *: delete the function putenvvim / www/server/php/56/etc/php.ini**### step 3: search for "disable_functions" * * # ESC +: + / + disable_functions will automatically navigate to the specified location disable_functions = passthru Exec,system,**putenv**, chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait Step 4 of pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv**###: save the file and exit * * ESC +: wq!

Friendly reminder

Pagoda supports multiple versions of php. If you use composer in different versions of php, just turn on the putenv function in php!

4.2 PHP project usage

Composer.lock already exists

Usage scenario: since composer.lock exists when downloading code or git code or deploying a project, composer.lock should be deleted first

# composer.lock already exists in the project and needs to be deleted and reinstalled The composer.lock file will be regenerated after successful installation # case demonstration: * * # step 1: enter the project blog root directory * * cd www\ wwwroot\ blog**### step 2: delete the composer.lock file * * # Please check the file name and be careful with rm-rf composer.lock**### step 3: re-composer the package required for the project * * composer install

Tip: don't forget to run composer selfupdate regularly to keep Composer up-to-date!

This is the answer to the question about the process analysis of Composer installation and configuration. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

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