Home > Development Tools > composer > Installation of composer under XAMPP

Installation of composer under XAMPP

藏色散人
Release: 2019-09-10 13:47:30
forward
4380 people have browsed it

Many open source software needs to be installed through composer. Composer is a dependency management tool for PHP. It allows you to declare code libraries that your project depends on and it will install them for you in your project. The following column composer usage tutorial will introduce you to the installation method of composer under XAMPP.

Installation of composer under XAMPP

Declare relationships

Let’s say you are creating a project and you need a library for logging. You decide to use monolog. In order to add it to your project, all you need to do is create a > composer.json file that describes the project's dependencies.

{
    "require": {
        "monolog/monolog": "1.2.*"
    }
}
Copy after login

Installation

1. Download Composer-Setup.exe

2. Click to install

3.Will Appeared and couldn't find many php dlls

Installation of composer under XAMPP

I tried to put these dlls into the system32 file under the C drive,

still didn't work

I tried to add environment variables to support php,

still didn’t work

Later I found out that it was because

extension_dir = "\ xampp\php\ext" is a relative path. Composer cannot find the corresponding dll.

Just change it to extension_dir = "D:\xampp\php\ext". There is one more place that needs to be changed.

browscap = "D:\xampp\php\extras\browscap.ini"

After the modification is completed, you can install it.

Use

Installation of composer under XAMPP

Continue to explain, the third-party controls automatically generated by composer are generally in a folder called vendor, the Chinese translation is 'supplier' . It is needed when using,

require_once __DIR__ . '/vendor/autoload.php';
Copy after login

or safer to use,

if (is_file(__DIR__ . '/vendor/autoload.php')) {
    require_once __DIR__ . '/vendor/autoload.php';
}
Copy after login

Installation of composer under XAMPP

Installation of composer under XAMPP

If you don’t add this sentence , usually an error will be reported.

Installation of composer under XAMPP

Summary: Composer downloads code files from the sources of relevant libraries based on the declared dependencies, and generates PHP scripts for automatic class loading in the Composer directory based on the dependencies. When using it, introduce the "/vendor/autoload.php" file at the beginning of the project, and you can directly instantiate the classes in these third-party libraries.

The above is the detailed content of Installation of composer under XAMPP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:aliyun.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template