10

Problem: I'm wanting to explore laravel 5, and failing miserably at installing it. I'm using this guide: http://laravel.com/docs/5.0 and need someone to help me understand the instructions.

Background and What I've Tried

I'm running Mac OSX 10.10.2 (Yosemite) and MAMP.

So far, I've downloaded Composer to my home folder using terminal. There is just a composer.phar file sitting there.

When I run:

composer global require "laravel/installer=~1.1"

I get the message:

Changed current directory to /Users/MYUSERNAME/.composer
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files

I assume that is ok because when I run the following in terminal, I get the composer logo and a list of options

~ MYUSERNAME$ composer

I'm not 100% sure what the following means, from the Laravel Docs:

"Make sure to place the ~/.composer/vendor/bin directory in your PATH so the 
laravel executable can be located by your system." 

Because I can't figure it out, the following steps throw errors, such as:

-bash: laravel: command not found

I've been going through a few forums, and it's suggested that I need to update my PHP.ini file - this seems more related to Composer install, and not specifically Laravel. Because composer is working, this seems to be a dead end.

Ideally, I want to install Laravel 5 to the directory

HomeFolder/sites/test

because Composer.phar is in my home folder, I think the command should be:

php composer laravel new sites/test 

or just

composer laravel new sites/test

As mentioned, it just (correctly) throws errors.

Question: If anyone can help solve my total user error, by explaining what "Make sure to place the ~/.composer/vendor/bin directory in your PATH so the laravel executable can be located by your system." means to a n00b, that'd be really appreciated.

Many thanks!

matt
  • 777
  • 2
  • 12
  • 25

3 Answers3

21

Laravel is a PHP framework (makes writing PHP applications easy)

Composer is a PHP package and dependency manager. (makes installing and updating third party code libraries easy)

When you run

$ composer global require "laravel/installer=~1.1"

You're using composer to install the laravel/installer=~1.1 package into composer's "global" project folder (usually ~/.composer). This is what installed the command line program named laravel.

The command line program named laravel is a shell script for installing the PHP framework (Also named Laravel).

Your "Unix Path" is a list of folders where a command line script will search for an executable. Usually is has folders like /usr/bin, /usr/local/bin, etc. This is why when you run ls, you're actually running /usr/bin/ls -- the shell knows to check each folder in the path for a location. You can view your current path by typing

$ echo $PATH

So, the problem is composer installed the laravel command line program to a folder that's not in your unix path. You need to add this folder to your unix path. You can do this by running the following (assuming you're using bash, which is OS X's default shell)

$ PATH=$PATH:~/.composer/vendor/bin

If you run that, you should be able to run the laravel command line program and continue your installation.

Most people add this to their .bash_profile or .bashrc files. The Unix Stack Exchange has a lot of good information if you're interested in learning how to do this.

Community
  • 1
  • 1
Alana Storm
  • 164,128
  • 91
  • 395
  • 599
  • really love the detailed answer, I used this in combination with the tutorial from @lukasgeiter answer and have it working. Thank you both for the explanation, and getting me up and running! – matt Feb 04 '15 at 22:03
  • @alan-storm Is it recommended to leave the php composer vendor folder in the home directory where it is installed? – Mark A Nov 01 '16 at 21:52
  • @MarkA I want to say yes, but I'm not sure what, exactly, you're asking. "home directory" and vendor folder are a a little vague without context. Sounds like you might want to ask a new question instead of commenting on an old one – Alana Storm Nov 02 '16 at 00:02
  • @AlanStorm For example, npm puts all of the packages further up in the global directory. Would it be better to have composer moved to a global directory instead of the home directory? – Mark A Dec 12 '16 at 22:23
  • @MarkA Still seems like you might want to ask a new question instead of commenting. – Alana Storm Dec 13 '16 at 21:25
  • I struggled with the docs as-well, this did the trick. – Mike Dec 15 '16 at 16:58
  • Every framework that i have use before was so easy to install (2min)... first time with php and laravel, 5h later, no New Project :D – Vasil Valchev Jan 06 '17 at 20:33
  • Even in 2017 you just saved my life, and every time again installing laravel takes me more time than developing the project itself. –  Mar 30 '17 at 20:39
4

You can add the directory to the PATH variable by editing /etc/paths.
Here's a tutorial on how to do that.

Just add a line with:

~/.composer/vendor/bin

Then the laravel new command should work fine


If everything fails you can still use the composer create-project command to make a new laravel instance:

composer create-project laravel/laravel sites/test --prefer-dist
lukasgeiter
  • 147,337
  • 26
  • 332
  • 270
4

I added C:\Users\Leon\AppData\Roaming\Composer\vendor\bin instead of ~/.composer/vendor/bin to the Path variable.

Here is instructions on changing the path variable on Windows 10: http://windowsitpro.com/systems-management/how-can-i-add-new-folder-my-system-path

ellie owen
  • 51
  • 1