The Ultimate Guide to Setting Up Composer with XAMPP on Windows 10 & 11

The Ultimate Guide to Setting Up Composer with XAMPP on Windows 10 & 11

Learn how to manually set up Composer with XAMPP on Windows 10 & 11 to send verification OTPs and security codes from your PHP web application.

Composer is a popular package manager for PHP that allows developers to easily manage their project's dependencies. If you're developing a web application that requires sending verification OTPs and security codes, you'll need to set up Composer with XAMPP. In this tutorial, we'll go through the steps required to manually install Composer on your XAMPP environment.

System Requirements

Before we begin, let's make sure that your system meets the requirements for running Composer. The latest version of Composer requires PHP 7.2.5 or higher to run. However, if you're stuck with a legacy PHP version, you can still use the long-term-support version (2.2.x) of Composer, which offers support for PHP 5.3.2+. Additionally, a few sensitive PHP settings and compile flags are also required, but when using the installer, you'll be warned about any incompatibilities.

You can find the Composer installer file here.

Check your PHP version in CMD:

  1. Open CMD or a terminal

  2. Navigate to the PHP folder in your XAMPP / WAMP:

    Note: your XAMPP / WAMP location could be different, navigate to the /php folder where you have installed XAMPP / WAMP.

  3. Run this command:

     php -v
    

If you're having issues with Composer, you can check whether the "composer\vendor\bin" path has been added to the Environment PATH variable. This is required for Composer to work correctly.

  1. Search for "Environment variables"

  1. Click "Environment Variables..."

  2. Under User variables, Double click "Path" to edit.

    1. Check if the "composer\vendor\bin" path has been added to the Environment PATH variable.

If the "composer\vendor\bin" path is not available under the "Environment Path variable" after running the installer from the composer download link, let's see how to manually install it.

Manual Composer Setup

  1. Navigate to your XAMPP's PHP folder (\xampp\php).

  2. Create a new text file in that folder and paste the following code:

     php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
     php -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
     php composer-setup.php
     php -r "unlink('composer-setup.php');"
    

    This code downloads the Composer installer and verifies its integrity using SHA-384. If the hash matches the expected value, the installer is considered verified, and the setup process can continue.

  3. Save the file and rename it to "ComposerSetup.bat". Make sure to set the save as type to "All Files".

  4. Run the file by double-clicking on it (You might have to right-click and run it as admin).

    By running the "ComposerSetup.bat" file, the installer will be executed, and Composer will be installed into your XAMPP's PHP folder.

  5. Next, we need to add Composer to the Environment PATH variable.

  6. To do this, search for "Environment variable" (without the quotes) on the Windows search bar like before and navigate to the "Environment Path variables" window.

  7. Add the path to the "composer.phar" file from the \xampp\php folder.

    By adding the path to the composer.phar file to the Environment PATH variable, you ensure that Composer is available system-wide, which means that you can run Composer commands from any directory in the command prompt or terminal.

  8. Restart your machine and run the following code in the terminal to check if Composer was installed correctly:

     composer --version
    

    This code should output the version of Composer that you installed, which confirms that it was installed correctly.

Conclusion

Manually setting up Composer with XAMPP / WAMP is not difficult, but it requires some technical knowledge. By following these steps, you should be able to set up Composer and add it to the Environment PATH variable without any problems. With Composer installed you can easily manage libraries and packages in your PHP web application. I hope this blog was helpful to you, and if you have any questions, feel free to leave them in the comments section below.