Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to load vendor files from Composer into specify directory

Posted on 2016-11-29
13
Medium Priority
?
79 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
13 Comments
 
LVL 53

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 53

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 53

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 53

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 53

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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.

721 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