Solved

How to load vendor files from Composer into specify directory

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

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 52

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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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
 

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
 

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 52

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
 

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
 

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 52

Accepted Solution

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

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 52

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
 

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

Suggested Solutions

Title # Comments Views Activity
Wordpress Pagination Function Not working ? 7 39
Wordpress French and English Site 6 76
display balance of stars as greyed out 8 23
Ajax and PHP 9 29
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

840 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