Installing composer
Posted by: sash_007 (---.live.vodafone.in)
Date: January 08, 2021 03:46AM

Hello

i want to know how to install and use composer on wampserver
i am using php version 7.2.18

any help will be appreciated thanks

Options: ReplyQuote
Re: Installing composer
Posted by: RiggsFolly (Moderator)
Date: January 08, 2021 11:29AM

I just wrote this, so if you have any comments to improve it, please feel free to comment.




How to Install Composer in WAMPServer

Composer of course is a command line tool, that uses PHP, so the first thing to do is make sure you can get to a php.exe from anywhere when running from a Terminal/Command Prompt.

WAMPServer does not need OR more importantly like you to use the normal Windows method of achieving this which is to add to the PATH environment variable.
This is not a problem we can do this by creating a little bat/cmd file that will add a folder containing a php.exe to the PATH only for the duration of the existance of the Command Prompt you open to use composer. This way it will never even be noticed by WAMPServer as having been temporarily added to the PATH.

I use this batch file to do this, I call it `phppath.cmd` and I save it to any folder that is already on the Windows PATH, so I can run it from anywhere when using a command prompt window.
I have a `C:\bin` folder for this, that is already on my PATH, you could also just drop it into the C:\windows folder as that is always on the PATH.

File called phppath.cmd
@echo off
REM **********************************************************************
REM * PLACE This file in a folder that is already on your PATH
REM * Or just put it in your C:\Windows folder as that is on the
REM * Search path by default
REM * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
REM * EDIT THE NEXT 3 Parameters to fit your installed WAMPServer
REM * - baseWamp : is the drive and folder where you installed WAMPServer
REM * - defaultPHPver : is the version of PHP that will be pathed
REM *                   if no Parameter is put on the bat file
REM * - composerInstalled : Where I installed Composer
REM * This next one probably does not need changing but is there just in case
REM * - phpFolder : The folder structure that contains the Multiple
REM *               possible version of PHP WAMPServer has installed
REM **********************************************************************

set baseWamp=C:\wamp64
set defaultPHPver=8.0.1
set composerInstalled=%baseWamp%\composer

set phpFolder=\bin\php\php

if %1.==. (
    set phpver=%baseWamp%%phpFolder%%defaultPHPver%
) else (
    set phpver=%baseWamp%%phpFolder%%1
)

PATH=%PATH%;%phpver%
php -v
echo ---------------------------------------------------------------

REM IF PEAR IS INSTALLED IN THIS VERSION OF PHP

IF exist %phpver%\pear (
    set PHP_PEAR_SYSCONF_DIR=D:\wamp\bin\php\php%phpver%
    set PHP_PEAR_INSTALL_DIR=D:\wamp\bin\php\php%phpver%\pear
    set PHP_PEAR_DOC_DIR=D:\wamp\bin\php\php%phpver%\docs
    set PHP_PEAR_BIN_DIR=D:\wamp\bin\php\php%phpver%
    set PHP_PEAR_DATA_DIR=D:\wamp\bin\php\php%phpver%\data
    set PHP_PEAR_PHP_BIN=D:\wamp\bin\php\php%phpver%\php.exe
    set PHP_PEAR_TEST_DIR=D:\wamp\bin\php\php%phpver%\tests

    echo PEAR INCLUDED IN THIS CONFIG
    echo ---------------------------------------------------------------
) else (
    echo PEAR DOES NOT EXIST IN THIS VERSION OF php
    echo ---------------------------------------------------------------
)

REM IF COMPOSER EXISTS ADD THAT TOO
REM **************************************************************
REM * IF A COMPOSER EXISTS ADD THAT TOO
REM *
REM * Ensure you have set variable 'composerInstalled' above
REM *
REM * Done this way as W10 has issues with setting path with (86)
REM * in the path inside an IF with parentheses, would you believe
REM **************************************************************

IF NOT EXIST %composerInstalled% GOTO NOCOMPOSER

echo COMPOSER INCLUDED IN THIS CONFIG
set COMPOSER_HOME=%composerInstalled%
set COMPOSER_CACHE_DIR=%composerInstalled%
PATH=%PATH%;%composerInstalled%
composer -V
echo TO UPDATE COMPOSER ITSELF do > composer self-update
echo ---------------------------------------------------------------
GOTO END

:NOCOMPOSER
echo ---------------------------------------------------------------
echo COMPOSER IS NOT INSTALLED
echo ---------------------------------------------------------------

:END

set baseWamp=
set defaultPHPver=
set composerInstalled=
set phpFolder=

Call this from the command prompt as either
>phppath
to path the default php version
OR
>phppath 7.4.22
to path a specific version of PHP

The rest of this tutorial assumes you have done the above and `phppath.cmd` is working


Now to Install Composer
I will install composer into `c:\wamp64\composer` it could be placed anywhere and in any folder as long as you then amend the above batch file parameter `composerInstalled` to match

1. Start a command prompt, and create a folder to contain composer
Use whichever PHP version you want from the ones you have installed within WAMPServer

- phppath 8.0.1
- CD \wamp64
- MKDIR composer
- CD composer


2. Go to https://getcomposer.org/download`,
- DO NOT USE Windows Installer
- find the section "Command-line installation"

There are 4 lines there, copy one line at a time from the web page and Paste into you command prompt window and press enter (to execute the copied line)

Composer is installed

To make it a little easier to run we now create a composer.bat file so we can run composer like it were a processor.
While still in the composer folder copy and paster this line to create a composer.bat file

echo @php "%~dp0composer.phar" %*>composer.bat

Now you can start a command prompt any time you like, run `phppath.php` and it will temporarily PATH everything for you.
You can then run composer by keying `composer` at the command prompt,
test that by
- starting a new command prompt
>phppath
>composer

You should see something like
Composer version 2.0.8 2020-12-03 17:20:38

Finally If you get problems
You can just delete the compsoer folder and start again as nothing is placed in any kind of configuration for WAMPServer or Windows.

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.2.4 32bit & 64bit)
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.19>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-

Options: ReplyQuote


Sorry, only registered users may post in this forum.