Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems installing laravel with composer [duplicate]

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!

like image 322
matt Avatar asked Feb 04 '15 21:02

matt


People also ask

Can I install Laravel without Composer?

You do not need to run Composer on your server as well as locally, once you run composer install or composer update your project will have all its dependencies available and you can just upload it straight to your server. Hope it helps!!

Why is Composer needed for Laravel?

The main purpose of the composer is to install the dependencies or libraries for an application. The composer also provides the users to install the PHP applications available on the Packagist, where Packagist is the main repository that contains all the available packages.


2 Answers

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.

like image 65
Alan Storm Avatar answered Sep 29 '22 10:09

Alan Storm


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
like image 24
lukasgeiter Avatar answered Sep 29 '22 09:09

lukasgeiter