Join Joseph LeBlanc for an in-depth discussion in this video Installing Composer, part of PHP: PEAR, PECL, and Composer.
Composer's distributed separately from PHP as a stand-alone executable FAR file. Let's install this file and put it in one of our command line paths. Before downloading Composer make sure you have Apache, MySQL and PHP set up on your computer. I've set up Apache, MySQL, and PHP according to the directions in Installing Apache, MySQL and PHO with David Gassner. Specifically, I went to chapter two, and watched, activating Apache on Mountain Lion, and also, activating PHP on Mac OS X.
With PHP and Apache ready to go, let's install composer. Go to getcomposer.org and click Download. There are two terminal commands presented for installing composer. The first one is based on curl and the second one is based on some PHP code. Let's see if we have curl installed. We do have curl installed, so we can use curl. Copy this inside a line, and then Paste it into terminal. This is going to download in installer's script and then feed it through PHP.
The composer and installer scripts checks our PHP installation to make sure that everything is ready to go, if there are any problems its going to alert us. In this case, we have a problem we need to add detect unicode equals off to the end of our PHP INI file, so lets do that now. Type in sudo, and then pico, which is a text editor, and then Copy the path to the php.ini file. Paste that in, and then Copy the PHP INI setting.
Now hit ENTER, and then go to the end of the file. To do this in pico, hold down Ctrl and press V. Now, that we're at the end of the file, Paste in the setting. Finally, press Ctrl + X and then type Y for yes to save the changes. Hit Return to accept the file name. And then, you'll be taken back to the Terminal Command Prompt. So now our PHP installation is ready for Composer. I'm going to press the Up key two times, and that'll get us back into the command for downloading the installer script. When I hit Return, it begins downloading Composer.
Composer is now downloaded to my computer. If I type in ls, you'll see composer.phar at the bottom. I can run Composer by typing in PHP and then composer.phar. Now, typing in PHP composer.phar every time isn't very convenient if you're going to be using it in other places in your file system. So, let's move the composer.phar file into palace where it will be more convenient. I'm going to move composer.phar into user local bin. This is a path that's in our command line path, so I'll be able to access it from any point in the file system... To do this, type cp then composer.phar and then a space and then /user/local/bin.
It's giving me permission denied, because user local bin is a protected folder. To get around that, I'm going to press the Up key, and then go back to the beginning of the command and preface it with sudo. If it asks for your password, be sure to enter it. Now, I can type it composer.phar and it will run the command. This can also be set up so that we can just type composer instead of composer.phar. To do that type in mv for move and /usr/local/bin/composer.phar, then type a space, then type /user/local/bin/composer.
Again, this is a protected directory, so we're going to start this command with sudo. Now, just type composer. Composer is now set up and ready to go on this computer. When you want to set up composer on a new computer, just use the insulation script. It'll make sure your PHP configuration is suitable for Composer, then download the latest copy. Once, Composer is downloaded, move it to a place within your command line path.
- Installing on Mac and Linux
- Discovering channels and packages with PEAR
- Coding with PEAR packages
- Starting a new application with Composer
- Installing and maintaining packages with Composer
- Finding and installing PECL extensions