Install the php dependency management tool composer in windows. what is composer first?
Okay, paste Baidu Encyclopedia directly. Http://baike.baidu.com/view/1657652.htm
So how to install composer in windows?
In windows, it is not as convenient as in linux. Therefore, we must first set the php environment variable so that php can run through dos.
1. my computer (right-click)-> Properties-> Advanced System Settings-> Advanced-> environment variables, select PATH, edit, and append
; D: \ xampp \ php
Alt + r-> cmd open the dos window and execute php-v. If an error is reported in the middle, the system prompts that a series of dll files are not found. modify php. ini,
Set the value of extension_dir to absolute path, extension_dir = "D: \ xampp \ php \ ext", and I have a browscap in the middle. dll not found error prompt, find php. in ini, change the value of browscap to the absolute path value.
If no error occurs. Run php-v and you will get the following results:
2. enable ssl extension
Modify php. ini and open extension = php_openssl.dll.
3. go to the php directory and run the php command.
We recommend that you modify the registry. you can right-click the file to be accessed and directly enter the cmd command of the file, instead of executing cd/D every time: /xampp/htdocs
Create a file and paste the code:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT \ folder \ shell \ cmd]
@ = "CMD Quick Start"
[HKEY_CLASSES_ROOT \ folder \ shell \ cmd \ command]
@ = "Cmd.exe/k cd % 1"
Save as xx. reg. when running the command, click yes, find a folder, right-click it, and you will see an operation item for cmd Express connect,
Back to question: go to the project file htdocs and enter it in dos
Php-r "eval ('?> '. File_get_contents ('https: // getcomposer.org/installer '));"
Wait a moment and you will see the following prompt:
4. create a new xx. bat file in your project file and edit the file as follows:
@ ECHO OFF
Set subdir = % ~ Dp0
Php % SUBDIR % \ composer. phar % *
Run the following command. This file defines the current path as composer. of course, you may not execute this file.
5. here, composer is basically installed. Then we will install the extension package,
Open composer. json in htdocs and enter the extension we want to install:
The format is roughly as follows:
{
"Require ":{
"Chrisboulton/php-resque": "1.2 ",
"Lisachenko/go-aop-php ":"*",
"Monolog/monolog": "1. 2 .*"
}
}
6. if the file in step 4 is executed, run the composer install command in the htdocs directory.
If the file in step 4 is not executed, php composer. phar install is required.
Now, the installation is complete, and the extension package is also downloaded. Htdocs will have one more vendor folder. after opening it, it will find three more folders: chrisboulton, lisachenko, and monolog. Now let's take a look at automatic loading ......
We need to use the extension package again, require_once ROOT_PATH. 'vendor/autoload. php ';
Then you can directly call the class name in the extension package.
Example:
Require_once ROOT_PATH. 'vendor/autoload. php'; // ROOT_PATH is the root directory.
$ Redis = Resque: redis (); // you can call the class name of vendor/chrisboulton/php-resque/lib/resque. php directly. you do not need to introduce this file.
Var_dump ($ redis );
This redis variable is a redis class of php-resque.