I wanted to get several Git repositories then place it on a certain directory on my Git-tracked project. My current project structure:
- custom
- plugins
- file.txt
When the user do a composer install, I wanted it to fetch this Git repo then place it under new directory on my project named provisioning.
- custom
- plugins
- provisioning
- nginx
- file.txt
Am I using the Composer the right way?
By default, the composer will install dependencies to vendor directory. If you need to install everything into directory names provisioning the use
"config": {
"vendor-dir": "plugins"
},
in your composer.json file and then run composer install command
Further details in How to specify Composer install path?
Related
I'm trying to install some packages outside the /vendor folder via the installer-paths composer directive.
After the deploy those packages aren't installed in the deployment, but the ones in the vendor folders are.
There is any way to allow the Cloud build to install composer packages outside vendor folder?
I'm deploying a Wordpress website to GAE php72, using a composer based boilerplate Bedrock.
I've tried to set the those paths to target custom folders inside the /vendor folder and it works, maybe there is some sort of security rules that allows composer install only to write into vendor?
Here is part of composer.json:
{
// ...
{
"composer/installers": "^1.7",
"wpackagist-plugin/wordpress-seo": ">=6.0",
"wpackagist-theme/twentynineteen":"1.0"
},
"extra": {
"installer-paths": {
"web/app/mu-plugins/{$name}/": ["type:wordpress-muplugin"],
"web/app/plugins/{$name}/": ["type:wordpress-plugin"],
"web/app/themes/{$name}/": ["type:wordpress-theme"]
},
"wordpress-install-dir": "web/wp"
}
//...
}
I've also tried to use composer post-install-cmd scripts to copy the packages from /vendor folder to the desired location, but the build fails with message:
Step #1 - "builder": Script cp vendor/plugins/* web/app/plugins handling the post-install-cmd event returned with error code 1
Step #1 - "builder": cp: target 'web/app/plugins' is not a directory
Step #1 - "builder": > cp vendor/plugins/* web/app/plugins
I don't think it would be possible since, as Google Cloud Platform documentation states that composer specifically adds the packages to your app's vendor/ directory, where autoload.php is generated.
I actually found that deploying with:
gcloud beta app deploy --no-cache
installs all packages successfully even outside the /vendor folder.
When I want to make a pull request for a Laravel package on GitHub I do it at the moment in the following way:
Create new Laravel project
Require & install the package
Delete the add-on files from the project in the vendor folder
Fork GitHub and clone files into the project folder
Make changes to package and test everything.
Add, commit, push and do the pull request.
I find this a bit cumbersome - is that actually the correct way of doing it?
For example if I want create a PR for the voyager package I would have to
do the following commands for step 1. & 2.
>laravel new create-pr
>cd create-pr
>composer require tcg/voyager
>php artisan voyager:install
then remove the folder tcg/voyager and clone the fork as new folder tcg/voyager.
If I skip composer require tcg/voyager and directly clone the fork into tcg/voyager I cant install the package because of
First, fork the official repository tcg/voyager into your personal repository iwasherefirst2/voyager. Then
1) Create a new Laravel Project
2) Add repository iwasherefirst2/voyager to composer.json:
"repositories": [
{
"type": "vcs",
"url": "https://github.com/iwasherefirst2/voyager.git"
}
],
3) Now install tcg/voyager with --pref-source this will automatically install
iwasherefirst2/voyager into vendor/tcg/voyager and setup the git connection.
composer require tcg/voyager --prefer-source
Now you may change files inside vendor/tcg/voyager and push them (they will be pushed to your local repository `iwasherefirst2/voyager).
Remarks
1) If you would like to have the package folder in the root of your application package/voyager, you may create a symlink like this:
ln -s vendor/tcg/voyager package
2) To see modified files in vendor you may call composer status -v
$ composer status -v
You have changes in the following dependencies:
/path/to/app/vendor/symfony/yaml/Symfony/Component/Yaml:
M Dumper.php
3) If you run composer update you will get a warning if it overwrites any of your files
$ composer update
Loading composer repositories with package information
Updating dependencies
- Updating symfony/symfony v2.2.0 (v2.2.0- => v2.2.0)
The package has modified files:
M Dumper.php
Discard changes [y,n,v,s,?]?
Anybody knows how to composer install for all subfolders too? Does the composer support it? Now I need to execute this command in each subfolder or add all subfolder's vendor folder to git.
I found solution in Linux:
https://www.bram.us/2014/02/16/installing-dependencies-in-all-subfolder-organised-projects/
But how to do the same in Windows?
Example.
I have a project in C:\grav with composer.json in it.
But also I have plugins folder C:\grav\user\plugins with composer.json in some of subfolders:
I want to execute composer install in C:\grav to install all dependencies in each C:\grav\user\plugins\* too.
Grav plugin or theme
In order to support the correct installation folders for Grav plugins and themes,
you would need to add the composer/installers to the require section of your plugins.
Normally the plugins would land in the vendor folder, too - but, the Grav Installer tells Composer the correct position inside a Grav project, see
see https://github.com/composer/installers/blob/master/src/Composer/Installers/GravInstaller.php#L6
So, when writing plugins or themes for grav each composer.json must indicate the type as grav-plugin or grav-theme, else Composer can't match the package to the installer.
{
"name": "your/some-grav-plugin",
"type": "grav-plugin",
"require": {
"composer/installers": "^1.0.23"
}
}
Grav main project
Now, in your main grav project's composer.json, just add the plugins.
Then run composer install. That means the package is fetched, the composer installer is fetched, based on the package type the matching installer is triggered and the grav installer drops the file into the correct folder....
But how to do the same in Windows?
Uhm... Composer works cross-platform. Not a problem.
I have installed composer.
My project dir tree looks something like this
/home/myproject/public_html/myproject.com
I initially installed it in:
/home/myproject/public_html/myproject.com/bin/composer/
But later moved it to:
/home/myproject/usr/local/bin/composer
Questions:
Where to I create composer.json ?
In the official docs they mention that in order to install new packages I need to write a require key in the json format in that file, does this mean that I dont have to upload the package through ftp?
The docs further say that I can simply install dependencies like ths:
php composer.phar install
I dont understand the workflow of this process (im fairly new).. what exactly do I need to do to get some packages going (like Respect)
Composer has 2 basic elements for you to consider:
The composer.php file itself - this can be located anywhere on your system - usually it is convenient to have it in you search path so you can invoke it by name (no path) from the command line.
Composer.json - this file is the configuration for your project. This is usually best located at the top level of your project. Ideally this is a directory outside the scope of your web server - so that it will never be exposed or served.
Symfony2 has some great documentation and examples of composer in use.
Also be aware that some packages you reference via composer will themselves have composer files - to ensure they match your required dependancies - and they may also have their own dependancies that need to be considered.
I would install composer.json in the following
/home/myproject/composer.json
It would be out of scope of the web server and could be used to manage many assets e.g.
public_html/
libs/
config/
docs/
vendor/
Where to I create composer.json ?
You should create composer.json to your project root like /home/myproject/public_html/myproject.com/composer.json. If all files of your application live inside your myproject.com folder.
In the official docs they mention that in order to install new
packages I need to write a require key in the json format in that
file, does this mean that I dont have to upload the package through
ftp?
Yes as long as you're not in shared hosting because most of them don't allow CLI (SSH).
The docs further say that I can simply install dependencies like this
php composer.phar install
Yes you can simple type the above command and composer.json will install the latest version of your package.
Composer.json (Respect Package)
{
"require": {
"respect/validation": "dev-master"
}
}
Now run composer install will install the require package.
For further packages
{
"require": {
"respect/validation": "dev-master",
"doctrine/orm": "2.*"
}
}
Now run update composer update it will download the doctrine/orm as well.
I am trying to install fuelphp.
And getting the error as
Composer is not installed. Please run "php composer.phar update" in the root to install Composer
In my xampp/php directory I run a command
php -r "eval('?>'.file_get_contents('https://getcomposer.org/installer'));"
But once i run php composer.phar install composer could not find a composer.json in e:\xampp\php
How can i resolve and run fuelphp successfully can anyone help.
As of 1.7.1, we no longer supply the composer.phar file in the zip. It only has a limited shelf life (30 days before it starts complaining).
Instead we suggest you install composer yourself, either locally (specific for this fuelphp installation) or globally so you only have to install it once for all your projects.
Composer is a tool for dependency management in PHP, like npm for Node.js, bundler for ruby, and others.
It reads a file called composer.json with the dependent libraries your project needs and, finally, installs (downloads) them for you.
Fuelphp can be installed using composer, but there are several packages.
So, you need to create the composer.json with all needed fuelphp packages. Open notepad, save a file with the name composer.json (be sure to save it with ".json" extension) and put this content:
{
"require": {
"fuelphp/upload": "2.0.1",
"fuelphp/event": "0.2.1",
(...)
}
}
Note you need to insert at "(...)" the others fuelphp packages and the needed versions. You can check them all at https://packagist.org/ (type fuelphp at search). Packagist is the main Composer repository.
More information about Composer at this link.
Let me know if you need more information about it.
If you are running FuelPHP 1.7, the download comes with all Composer files you need. You need to run php composer.phar install in the root directory of FuelPHP (the same directory that contains the public folder and the fuel folder.
As long as you have v1.7 (I'm not sure if earlier versions contain the files), that directory will contain composer.json and composer.phar.
In folder fuelphp-1.7 (latest), there are two files: composer.phar and composer.json you need to cd into that folder and run:
php composer.phar install
If you don't have php in your path, you should do something like:
e:\xampp\bin\php\php5.4.16\php.exe composer.phar install
Use the full path to your php.exe. Remember your current working directory should be fuelphp folder where composer.phar and composer.json are.