Installing PHP Dependency management tools under Windows composer

Source: Internet
Author: User
Tags autoload composer install
First of all, what is called composer?

OK, direct Baidu Wikipedia. Http://baike.baidu.com/view/1657652.htm

So how do I install composer under Windows?

Windows executes commands in a way that is less convenient than Linux. So we have to set the PHP environment variables, so that PHP can be run through DOS.

1. Environment variables, advanced system settings, properties, My Computer (right-click), select Path, edit, append later

;D: \xampp\php

Alt+r->cmd Open the DOS window and execute php-v. If there is an error in the middle, prompt a series of DLLs not found, modify php.ini,

Set the value of the Extension_dir to the absolute path, Extension_dir = "D:\xampp\php\ext", I've got a browscap.dll. Error hint not found, find Browscap in php.ini, and change its value to absolute path value

If it doesn't go wrong. To execute the PHP-V, the following results should be obtained:

2. Turn on SSL extensions

Modify php.ini, open extension = Php_openssl.dll

3. Go to the PHP directory and execute the PHP command.

It is recommended that by modifying the form of the registry, you can right-click on the file to be entered, and go directly to the cmd command of the file without executing cd/d every time D:/xampp/htdocs

Create a new file and paste the code:

Windows Registry Editor Version 5.00
[Hkey_classes_root\folder\shell\cmd]
@= "cmd fast track"
[Hkey_classes_root\folder\shell\cmd\command]
@= "cmd.exe/k cd%1"


Save As Xx.reg, run, click Yes, then find a folder, right click, you will see a CMD fast-track operation,

Back to the point: Go to Project file Htdocs, enter in DOS

Php-r "eval ('?> '. file_get_contents (' Https://getcomposer.org/installer '));"

Wait a moment and you'll see the following prompt:

4. In your project file, create a new Xx.bat file, and edit the following:

@ECHO OFF
SET subdir=%~dp0
PHP%subdir%\composer.phar%*
Then execute it. This file is to define the current path as composer, and of course you can not execute the file.

5. Here, the composer is basically installed. So next we're going to install the expansion pack,

Open the 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 fourth step file is executed, execute the composer install directly under the Htdocs directory

If the file for step fourth is not executed, PHP Composer.phar install is required

OK, the installation here is complete, the expansion package, also downloaded. Htdocs will be more than a vendor folder, Open will find, chrisboulton,lisachenko,monolog three more folders. Now let's take a look at automatic loading ...

We need to use the expansion pack again, require_once Root_path. ' vendor/autoload.php ';

You can then call the class name in the extension package directly.

Examples are as follows:

Require_once Root_path. ' vendor/autoload.php ';//root_path is the root directory

$redis = Resque::redis ();//Call vendor/chrisboulton/php-resque/lib/resque.php's class name directly here, without introducing the file

Var_dump ($redis);

This redis variable is a Redis class for Php-resque

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.