Just in-case you’re not aware of Composer is, it’s simply a third-party package managing tool. It brings streamlined efficiency to adding new libraries to your projects by writing simple one-line commands.Contents Installation Prerequisites
Before you follow any of the guides below, you must ensure thatphp is already installed on your computer. Composer will not run properly without it and you will soon run into problems. In addition, you must set PHP as an environmental variable within your system for shortcut command access to the engine. See the following steps to do it on windows.Go to System Properties Go to the advanced tab Click Environment Variables. If not already present, create a new variable named PATH. If already present, go to the next step. Create a new variable value within the PATH variable, this value needs to be the path to your PHP folder, where the php.exe is located. In my case its C:\xampp\php After adding this value, press the OK button till all the windows are closed. Installing Composer Software on Windows
Note:If you don’t have sufficient rights on your computer to install any software, please see the next section, installing on Mac & others. As this is a workaround for Windows users with this issue.
The easiest way to install Composer on windows is by downloading the native Composer-Setup.exe. This installs the required files to your local computer that are ready to be utilized within your projects. See the following steps and sub-stepsStep 1 Download the Composer-Setup.exe file from the download page here . Install the software. Step 2 composer
If you got the response of ‘composer is not recognized as an internal or external command’, then you will need to set the composer bin path in your environmental variables. On my device, this bin folder is located in ‘C:\Users\CodeWall\AppData\Roaming\Composer\vendor\bin’. This is the value you will need to add to your PATH variable.Installing Composer Manually on Mac, linux & Windows
Composer can be installed via a PHP Archive file, namely composer.phar. This file is available from download page , underneath the Manual Download sub-heading. Opt for the latest version, at the time of writing it is 1.8.0. After the composer.phar file is downloaded,Step 1 Locate the composer.phar on your device and drag/move it to the root directory of your PHP project folder. Now open your command prompt and navigate to the projects root directory, for example, on mac it would be cd ~/phpProject or on Windows cd C:/phpProject Once here type the following command php composer.phar and composer should load in the terminal. If it doesn’t and the terminal complains about PHP not being a recognized command, then see the prerequisite of this tutorial.
That’s it with the PHP archived package, its now installed and ready to be utilized as and when, without physically installing to your system.Using Composer
Before you can utilize the power of Composer, see the following checklist is completeComposer is installed, if not, see Installation section. Both PATH variables for PHP and Composer so that they are accessible via shortcut commands in the terminal, if not, see the installation section.
Throughout these remaining examples, the demonstrations will be carried out with a Windows based system using it’s native command prompt. Some commands may differ on your operating system, but will be easy enough to find in the operating systems documentation.Initializing Composer with your project
Composer needs a kind-of-settings file to run properly, and ultimately for you to instruct it on what it should do. The composer.json file doesn’t come fresh-out-the-box so one must be created. Luckily, the composer engine helps with this task, literally walking you through each step of creation. See the following steps to build the .json file.Step 1 Open the command prompt. Go to your PHP project folder, for this example, the following command was used cd C:\project , make sure you replace the path in the example command with your project path. Then run the following command composer init Type in a Package Name, something descriptive of your project and hit enter. Add a small description of your project and hit enter. For the Minimum Stability input, it depends on the project at hand, you can see further details in the docs but for this example, just press enter, and it defaults to ‘stable’. For the Package Type, it can be either of the following, Package, Library, metapackage or composer-plugin. Pick what is relevant, but in this case, project was entered. License is another personal circumstance, if there is going to be a license, then you will need to specify it, if not, simply hit enter. The next line will ask you if you want to define your dependencies, at this moment, type no and press enter, and repeat the same for the dev-dependencies. Finally, type yes to confirm your settings and Composer to generate the file. See Figure 1 for an example of all these steps.
Figure 1. Step 2
Now let’s double check that the file was actually generated.Go to your project folder and locate a file named composer.json. Open the file and check the configuration you entered is present. If it is, then we are good to go! If not, go back to Step 1 and repeat all the sub steps. It should look similar to Figure 2 below.
Figure 2. Requiring a Package
Now for the fun part, the ability to download and install useful libraries with one line commands! There are actually two ways to do it, one via the command line direct. Or specifying the package within the composer.json file first then running a command. This probably sounds a bit confusing, but in the next couple of examples, you will will come to understand the meaning of two separate ways.Method 1. Requiring Packages using the Require command
This first way and my personal favorite is to simply use the Require command and let Composer do it’s magic. See the following steps to download a package named Guzzle, a excellent HTTP client library, but feel free to choose a library from packagist of your own, there is currently over 200 thousand to pick from!Open the command prompt and navigate to your projects root directory, for example cd C:\project Enter the following command for the packages default version composer require guzzlehttp/guzzle and press enter. If you need a specific version, skip this step and see step 3 . Requiring a specific version use the following command composer require guzzlehttp/guzzle ^versionNo ) and press enter. Give it a few seconds and the process should begin. The terminal will output some messages, and you may see that multipl
本文开发（php）相关术语:php代码审计工具 php开发工程师 移动开发者大会 移动互联网开发 web开发工程师 软件开发流程 软件开发工程师