Solved

How to load vendor files from Composer into specify directory

Posted on 2016-11-29
13
13 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 52

Expert Comment

by:Scott Fell, EE MVE
Comment Utility
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
 

Author Comment

by:Black Sulfur
Comment Utility
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 52

Expert Comment

by:Scott Fell, EE MVE
Comment Utility
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
 

Author Comment

by:Black Sulfur
Comment Utility
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
 

Author Comment

by:Black Sulfur
Comment Utility
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
 

Author Comment

by:Black Sulfur
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
Comment Utility
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
 

Author Comment

by:Black Sulfur
Comment Utility
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
 

Author Comment

by:Black Sulfur
Comment Utility
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 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
Comment Utility
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
 

Author Comment

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

Expert Comment

by:Scott Fell, EE MVE
Comment Utility
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
 

Author Comment

by:Black Sulfur
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now