Solved

How to load vendor files from Composer into specify directory

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

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
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…
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 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 …

910 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

22 Experts available now in Live!

Get 1:1 Help Now