How to Install and Use Composer on Windows – a Complete Guide
Installing composer is quick and easy, however, for some people, this process is quite troublesome, therefore, today we’ll discuss how to install composer on windows, in addition, we’ll also discuss how to use the Composer on Windows.
- How to Install Composer on Windows
- How to Use Composer on Windows
- Solve an Error: PHP Startup: Unable to load dynamic library
- How to Change The PHP Version
I. How to Install Composer on Windows
Installing composer can be done with a few easy steps:
1 Download the installer file
2 Run the installer file
Next, run the installer file
Important: During the installation process, we need to connect to the Internet, because the installer will download composer and some of necessary components.
Step 1 First, a setup window will appear tell us that the installer will download and setup composer, just click Next >.
Step 2 Next, specify the location of the PHP file (php.exe file) that will be used on the command line along with composer itself.
This file is usually located in the PHP directory. If you use XAMPP, for example: installed in E:\xampp, then the location is in the E:\xampp\php directory, so the result become E:\xampp\php\php.exe as follow:
Then, Click Next > to continue
Furthermore, Composer will test whether PHP can do the job.
NOTE: If an error occurred, please read the solution in the section: III. How to Solve Error When Installing Composer: “PHP Startup: Unable to load dynamic library”
Step 3 Next, specify whether yo need to use a proxy. If you use a proxy, then check the option “Use a proxy server to connect to the Internet” and write the proxy address and its port, for example:
Click Next > to continue
Step 4 Next the window will display the resume of the settings, click “Install” to continue.
Step 5 The installer will download Composer and related components and then install it on the computer.
Step 6 There is a notice tell us that there is a change in the Windows Environment, this means that now the composer can run on a command prompt.
There are two variables added to the system environment:
- In the “User variables” section: PATH variable with a value of the location of composer’s binary file (C:\Users\agusph\AppData\Roaming\Composer\vendor\bin)
- “System Variables” section: PATH variable with the value of the location of php.exe file (E:\xampp\php)
Step 7 The installation processes have completed, click Finish to close the installation window.
Step 8 Next, test whether the composer can run properly. Open a command prompt and run the command:
composer --version, if successful, the version of composer will be shown:
Done. Next, will discuss how to use composer in windows
II. How to Use Composer in Windows
After successfully installing composer on windows, the next problem for new users is how to use it, especially defining the directory, well, here we will discuss how to do it.
Composer works on the directory where the command prompt run, for example, when we want to install or update a package in the directory of “E:\xampp\htdocs\Minify\src” then we have to point the cursor to that directory.
- Open a command prompt and navigate the cursor to a directory where we will install the package, e.g: E:\xampp-7.0.6\htdocs\Minify\src
- Next, run the command
composer require matthiasmullie/minify. The command usually provided by the author. In this example, we can find the command on the front page of PHP Minify package.
Wait until the process complete (sometimes takes a long time)
- To ensure that the installation process is successful, open the folder where we have installed the package.
How to Use Composer Behind a Proxy
If we use the internet connection behind a proxy, then we have to make adjustments to the command prompt.
To do so, before using the composer, run the command (for HTTP)
set http_proxy:proxy_name:port_number and
set https_proxy:proxy_name:port_number for https, for example:
III. How to Solve an Error When Installing Composer on Windows: PHP Startup: Unable to load dynamic library
Sometimes the composer installation processes do not run smoothly (an error occurred), typically the error message is “PHP Startup: Unable to load dynamic library …”
This error occurs when the installer does some test running the PHP, but PHP can not load the necessary modules. Those modules are listed in the PHP configuration file (php.ini)
To overcome this, do the following steps:
- Open the php.ini file, usually located in the PHP folder, if you use xampp then this file is in the “xampp\php” folder.
- Next, search (CTRL + F) a word of extension_dir, then look at the value, it is usually a relative path, eg “\xampp\php\ext”, then change it to absolute path, eg “E:\xampp\php\ext”
- Next, again, use (CTRL + F) to search the rest of the relative path and change it to the absolute path.
- Save the file and restart the installation process
Done. you should now not encounter such problem again.
IV. How to Change the PHP Command Line Path In Composer
After successfully installing the composer, later we may want to update our PHP software to the new version and we want to adjust it to our composer.
To update PHP used by the composer, we only need to change the environment path, to do so:
- Open Windows Environment: right-click on My Computer and select Properties. Then, select Advanced system settings and click the “Environment Variables” button
- In the “System variables” section, select the “Path” variable and click edit. Search PHP path we used in our composer, and then change it to our new php.exe file, for example, the previous is “E:\xampp\php” then I change to “E:\xampp-7\php”
Click OK to save the changes
- Test it by running the command
composer --version, if successful the version of the composer will appear.
- However, if there is an error message, usually: “PHP Startup: Unable to load dynamic library …”, then repeat the previous section III. How to Solve an Error When Installing Composer in Windows: “PHP Startup: Unable to load dynamic library”
Loves articles on webdevzoom.com? join our newsletter to get quality article right to your inbox. Nothing else, just quality stuff!!!