Home > Article > Development Tools > Installation of composer under XAMPP
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.
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.*" } }
Installation
1. Download Composer-Setup.exe
2. Click to install
3.Will Appeared and couldn't find many php dlls
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
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';
or safer to use,
if (is_file(__DIR__ . '/vendor/autoload.php')) { require_once __DIR__ . '/vendor/autoload.php'; }
If you don’t add this sentence , usually an error will be reported.
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!