Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to load vendor files from Composer into specify directory

Posted on 2016-11-29
13
Medium Priority
?
81 Views
Last Modified: 2016-11-29
I don't know what other topic to choose because when I type Composer there is no such topic on experts exchange.

I have installed composer and when I download a package a get a vendor folder, a lock file and a son file that download to a specific location on my computer. If I have 20 folders/websites in my localhost for example, how do I get Composer to download the vendor folder etc. into one of those locations?
0
Comment
Question by:Black Sulfur
  • 8
  • 5
13 Comments
 
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 41905934
My file structure seems similar where my phar file is top level and has a .lock and .json. Then each sub folder contains separate projects each with their own .lock and .json.

- TOP LEVEL WEB FILES FOLDER
- - composer.phar
- - composer.lock
- - composer.json

- - PROJECT FOLDER A
- - - - VENDOR FOLDER
- - - - composer.lock
- - - - composer.json

- - PROJECT FOLDER B
- - - - VENDOR FOLDER
- - - - composer.lock
- - - - composer.json

- - PROJECT FOLDER C
- - - - VENDOR FOLDER
- - - - composer.lock
- - - - composer.json
1
 
LVL 1

Author Comment

by:Black Sulfur
ID: 41905948
So, are you saying I should download whatever I need and then copy/paste it to the actual folder on localhost I want to use it in?
0
 
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 41905957
This is my local file structure. Each project is a different domain.  In this case, I am only worried about what is on local for development.
1
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Author Comment

by:Black Sulfur
ID: 41906059
Sorry, I am not explaining properly.

I am using MAMP on a mac and have a htdocs folder. Inside that folder I have for example

htdocs
----website 1
----website 2
----website 3

But when I run composer and for example install twig then it doesn't go into any of those folders, it downloads to the name of my mac folder. If I wanted Carbon for example to download to website 2 folder, is that possible or is that not the way it works?
0
 
LVL 1

Author Comment

by:Black Sulfur
ID: 41906091
I tried to do this step by step to find the problem. I put the composer.json file in the directory I wanted to download the package to and then in console I typed in "composer install" and I got the following error:

Composer could not find a composer.json file in /Users/myusername

To initialize a project, please create a composer.json file
0
 
LVL 1

Author Comment

by:Black Sulfur
ID: 41906194
Am I meant to use terminal and actually browse to the directory by typing in cd/directoryname and then run composer in the directory of my choice?
0
 
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 41906205
I believe you just need to set the path for the vendor folder https://getcomposer.org/doc/00-intro.md

I am doing this in phpstorm and have set up the path to my phar and each individual project as noted.
1
 
LVL 1

Author Comment

by:Black Sulfur
ID: 41906218
I did as suggested and ran this in terminal:

mv composer.phar /usr/local/bin/composer

I can now just type "composer" when I open terminal and it works. But I still don't understand how to install a package to a specific directory within localhost. Am I meant to browse to that folder in terminal?
0
 
LVL 1

Author Comment

by:Black Sulfur
ID: 41906240
Okay, I think I got it working. I browsed via terminal to the directory I wanted to install a package and it worked! :)
0
 
LVL 54

Accepted Solution

by:
Scott Fell,  EE MVE earned 2000 total points
ID: 41906287
I can't test on a Mac right now, but in windows I can and it is similar except for the file layout.

1) In my PROJECT FOLDER B I create a composer.json file
{
  "name": "vendor_name/package_name",
  "description": "description_text",
  "minimum-stability": "stable",
  "license": "proprietary",
  "authors": [
    {
      "name": "author's name",
      "email": "email@example.com"
    }
  ],
  "require": {

    "twig/twig": "v1.27.0"
  
  }
}

Open in new window


2) In the command line, I move to the PROJECT FOLDER B, which is
cd C:\Users\path_to\folder\WebRoot\PROJECT FOLDER B

Open in new window


3) php composer.phar install is run in the command line (while at the project folder)
>php C:\path_to\composer.phar install

Open in new window



You will just need to replace windows file structure with Mac.
1
 
LVL 1

Author Comment

by:Black Sulfur
ID: 41906326
Okay, great. So I am doing the same as you then but just on a Mac. Great!
1
 
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 41906564
For what it's worth, I use JetBrains PHP storm and this part is actually done by one initial set up for the project, then just a right click to add dependency.
1
 
LVL 1

Author Comment

by:Black Sulfur
ID: 41906747
I have seen that software and it looks great, but since I'm not an expert yet and not making any money, I can't justify the price tag so I use free tools like brackets and sublime. But hopefully one day I'll be in the position to afford php storm.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question