Difference between require and install vs create-project in composer - php

I don't get how the create-project works in composer. Lets take Laravel as example.
I can install this PHP framework with the following command:
composer create-project laravel/laravel --prefer-dist
This command installs the framework for me leaving me with a few folder in the root of my dir:
app
bootstrap
public
vendor
Plus some files.
But when I simply use the following composer command:
composer require laravel/laravel --prefer-dist
composer install
Then this only installs the vendor folder. No other files and folders are downloaded by composer.
How come? What is so different? How does composer know what other files to get when I use the create-project laravel/laravel command and why do I only get the vendor folder when I do require laravel/laravel?

require will add a dependency to the composer.json file and load it into the vendor directory as you have correctly noticed.
create-project on the other hand will clone the dependency, i.e. use the dependency as a template for a new project. Take a look at the repository behind laravel/laravel: https://github.com/laravel/laravel

Related

How to start cloned rep Yii2

How can i start project cloned from bitbucket, based on Yii2, on my localhost?
Composer is installed.
When i clone it, composer update give me nothing. composer create-project --prefer-dist yiisoft/yii2-app-basic inside this project dont work, with error "folder is not empty".
When i use this command composer create-project --prefer-dist yiisoft/yii2-app-basic without clone rep, its work good, and i cant clone in just created folder?
How i can run cloned yii2 project on my localhost? Help pls. Sorry for my grammar.
Error after composer update (install)
Repository content.
Pluggins in install-plugins.bat
`php composer.phar require --prefer-dist mihaildev/yii2-ckeditor "*"
php composer.phar require kartik-v/yii2-widget-select2 "#dev"
php composer.phar require kartik-v/yii2-widget-datetimepicker "*"
php composer.phar require --prefer-dist yiisoft/yii2-imagine
php composer.phar require zelenin/yii2-slug-behavior "~1.5.1"
php composer.phar require --prefer-dist moonlandsoft/yii2-phpexcel "*"
php composer.phar require guzzlehttp/guzzle
php composer.phar require electrolinux/phpquery
UPD: Screen repository
It seems like, for some reason, the publisher of the repository added the dependencies to an extra file instead of them being added to the composer.json the usual way.
You can deal with this a couple of ways, both should give you the same results.
Option 1:
Install the Yii2 app into a new folder:
composer create-project --prefer-dist yiisoft/yii2-app-basic
Clone the repository you want to use into another folder.
Drag&drop the contents of the cloned repository into the Yii2 folder, it will overwrite the Yii2 files, preserving the ones that don't change and adding the ones that don't exist.
Add the extra dependencies, either by running the install-plugins.bat script or by hand running them one by one in the console.
Your project should be runnable now.
Option 2:
Clone the repository you want.
Copy the Yii2 composer.json into the root folder of the repository.
Run composer install
Add the extra dependencies, either by running the install-plugins.bat script or by hand running them one by one in the console.
Either way should give you the same results, you will end up having a vendor folder in the root of your project with all the dependencies, specified by composer.json and composer.lock that you need to run the project.

Laravel installed but nothing inside the folder

I ran following 3 sets of command in order to install laravel via command prompt :
1) composer
2) cd D:\xampp\htdocs\Laravel
3) composer create-project --prefer-dist laravel/laravel Laravel
It said that the download was successful , but when i opened the laravel folder , it is empty. So, i tried reinstalling it but it showed as below :
[InvalidArgumentException]
Project directory Laravel/ is not empty.
Any help on this ?
You should run:
composer dump-autoload
and if does not work you should:
re-install composer
and
composer create-project --prefer-dist laravel/laravel blog "5.8.*"
You should let composer installer create the folder for you.
Hence your updated list of commands would be:
CMD
cd D:\xampp\htdocs\
composer create-project --prefer-dist laravel/laravel demo_project
demo_project is the name of the folder/project name that would be created inside htdocs

Laravel composer.json fully istallation

Is there any way to install laravel from only composer.json file by using
composer install
command. If i just copy composer.json from existing project it creates only vendor directory, but not app, database, etc.
I just want to load all laravel core files, project file structure and my custom package by using install command of composer.
Can someone help me with this?
You can install laravel with the command composer create-project --prefer-dist laravel/laravel <project_name> if you only want to use composer, this command is mandatory since it creates the directories you want.
See the documentation
I don't think you can.
Create a new laravel project or clone an old project from git. Then replace/update the composer.json, then run composer update, if its a new project or composer install, if you cloned a repo
I didn't find solution for this, maybe it's impossible.
So, i just create my package and manually copy my custom composer.json to project.

Install cakePHP 3.0 with composer issue

I used command to install new CakePHP project:
composer create-project --prefer-dist cakephp/app project-name
but it always display this error:
[RuntimeException]
Could not scan for classes inside "database/seeds" which does not appear to be a file nor a folder
Picture attached
Does anyone know how to solve this problem?

Composer downloads project under php folder

My composer.phar file is under xampp/php folder. When I download cakephp through composer (by using command : php composer.phar create-project --prefer-dist cakephp/app myProject), it downloads the project folder (i.e. myProject folder) under : xampp/php/myProject. Although it should download the project under htdocs folder.
How to download a project through composer under htdocs folder?
Just indicate complete path to your project:
php composer.phar create-project --prefer-dist cakephp/app /path-to-htdocs/myProject
(disclaimer: I just tried with a global composer instalation, not throught a .phar, but it should work too)

Categories