Laravel, how to manually install package without composer - php

Wanted to install Laravel-Excel (Maatwebsite) package manually without composer, but I dont know how.
Why? Because I have a laravel project in a free hosting server setup by other guy, and I can only access using Filezilla to edit/download/upload the codes.
If only Filezilla allow a command prompt that could use "composer update", then it will be easier.

I got solution!
I cant use composer on my company because of secure network. But i can download zip form github and install it manual. The below is my example for HTMLPurifier:
download and extract library mews/purifier to vendor directory https://github.com/mewebstudio/Purifier
add below line in vendor/composer/autoload_psr4.php
This sentence will load all of file from vendor/mews/purifier/src and autoload in namespace Mews\Purifier\
'Mews\\Purifier\\' => array($vendorDir . '/mews/purifier/src'),
Sometime you need add library into autoload_namespaces.php intead of, please read in
https://getcomposer.org/doc/04-schema.md#autoload
You got Mews\Purifier\Facades\Purifier not found if public config before finish step 3
$ php artisan vendor:publish
--provider="Mews\Purifier\PurifierServiceProvider"
add below json in vendor/composer/installed.json
This for composer history, providers and aliases will be load in config/app/php for register new provider
{
"name": "mews/purifier",
"version": "v2.0.12",
"type": "library",
"extra": {
"laravel": {
"providers": [
"Mews\\Purifier\\PurifierServiceProvider"
],
"aliases": {
"Purifier": "Mews\\Purifier\\Facades\\Purifier"
}
}
},
"autoload": {
"psr-4": {
"Mews\\Purifier\\": "src/"
}
}
},
Now you run this config, then vendor/mews/purifier/config will be move to config folder
$ php artisan vendor:publish
--provider="Mews\Purifier\PurifierServiceProvider"

Add the package to the vendor folder. You can upload it using filezilla
Add a reference in \vendor\composer\autoload_namespaces.php
Add a reference in \vendor\composer\autoload_psr4.php
Source laravel.io

it's easy to do it by following this
download the package and set the files in app folder
YourProject/app/Laravel-Excel/
and then add the path to composer.json in autoload
"autoload": {
...
"classmap": [
"database/seeds",
"database/factories"
"app/Laravel-Excel"
],
...
},
Run the composer dump-autoload
the solution refs to this question referance answer

download the package locally and then upload the package folder (found under vendor) along with the updated composer.json

Depending on how strict the server is, you could SSH into your Server. But doing it locally then uploading the required files is usually the way to go.
You might need to run composer autodump if you don't wipe the cache.

If everything works on local environment then copy your package and composer folder to server which is located at vendor

upload \vendor\maatwebsite
copy \vendor\maatwebsite\excel\src\config\excel.php to \config\excel.php

Related

Composer downloads the package and put in the vendor map but the service provider doesn't recognize it laravel 6

I forked an api handler from git that I need to update to be laravel 6 (api handler that i forked what is not laravel 6 compatible) compatible but I keep getting composer errors
So when I run composer update it install the package from the git and put it correctly on in the vendor folder. what works fine then I add the class to the config/app.php like this
'providers' => [
Name\ApiHandler\ApiHandlerServiceProvider::class,
],
what will throw this error in laravel
In ProviderRepository.php line 208:
Class 'Name\ApiHandler\ApiHandlerServiceProvider' not found
so far I have tried:
composer clear-cache
rm -rf .cache/composer/*
clear the bootstrap composer
delete composer.lock
delete the vendor
and then after that composer update but it keeps throwing the error. But when I am in mine editor and go to the config/app.php and click on Name\ApiHandler\ApiHandlerServiceProvider::class, while holding ctrl it finds the class and goes to the vendor map so mine idea shows that the class is correctly imported
this is how the composer.json looks of the laravel project
"repositories": [
{
"type":"package",
"package": {
"name": "name/laravel-api-handler",
"version":"dev-laravel-6",
"source": {
"url": "https://github.com/name/laravel-api-handler",
"type": "git",
"reference":"branch name"
}
}
}
],
"require": {
"name/laravel-api-handler": "dev-laravel-6",
},
the api handler composer.json
"autoload": {
"psr-4": {
"name\\ApiHandler\\": "src"
}
},
"extra": {
"laravel": {
"providers": [
"name\\ApiHandler\\ApiHandlerServiceProvider"
]
}
},
the map structure is vendor/name/laravel-api-handler/src
also the the custom package doesnt show up in the Discovered Package when running Composer update or Composer install
Am I missing something because I cant figure out what is going wrong
To resolve it,
remove the bootstrap/cache/config.php file. Then run again.
Run below commands one by one
composer dump-autoload
php update
Import the ApiHandler facade into your classes:-
use ApiHandler\Facades\ApiHandlerServiceProvider;
On top
Try to remove/rename your vendor folder. Then do composer install. Then please check again. If that doesn't work, do composer update. Not sure about what is happening under hood, but composer update did the trick in my case.
So after doing research to editing custom packages into your project apparently composer doesn't autoload "type":"package" what is not mentioned in there documentation anywhere. link where it get explained

Use a non-namespace composer package in a custom Laravel package [duplicate]

I am a Composer beginner and I am trying to make one project dependent of another one, while both project only exist on my local machine.
The composer.json in my library project (ProjectA) is:
{
"name" : "project/util",
"type" : "library"
}
I initialized git in the base folder of this project.
My composer.json in the project depending on the first one (ProjectB):
{
"repositories": [
{
"name" : "util",
"type" : "git",
"url" : "/d/workspaces/util"
}
],
"require": {
"project/util" : "*"
},
}
When I run composer install from ProjectB, I get the following error:
[RuntimeException]
Failed to clone , could not read packages from it
fatal: repository '' does not exist
I asume something is wrong with the url of the repository, but I am not sure what else to write there.
Autoload local package using composer (without going to packagist every time you change).
There are many ways to do so, I will be covering 2 of them:
In all cases we have 2 main parties:
- the local package (the code that we do not want to publish on packagist to be able to autoload it in our project composer).
- the main project (the code base that needs to use the local package code, can be another package and or any project).
Method 1: (direct namespace)
Open the main project composer.json file and autoload the local package namespaces using any method (PSR-4, PSR-0, ...).
example:
if in the composer.json of the local package we have:
"autoload": {
"psr-4": {
“Local\\Pack\\": "library"
}
},
"autoload-dev": {
"psr-4": {
"Local\\Pack\\Tests\\": "tests"
}
},
then in the composer.json of the main project we should have:
"autoload": {
"psr-4": {
"Mahmoudz\\Project\\": "src",
"Local\\Pack\\": "../path/to/local/pack/library” << referencing the other local package
}
},
"autoload-dev": {
"psr-4": {
"Mahmoudz\\Project\\Tests\\": "tests"
}
},
Advantages:
- you don’t touche the vendor directory (running composer update by mistake will not override your local changes)
- you don’t need your package to be on packagist to use it
- you work in one place (the local package) and the changes are automatically loaded in the main project
Disadvantages:
- you cannot publish the composer.json on production (needs editing before publishing to require the real package)
Method 2: (local repository)
Download the local package from a local repository.
local package:
1. initialize git in the package (even if you don’t want to use it - no need to commit anything)
2. add composer.json file. In the file make sure you have the following:
"name": "vendor-name/package-name",
"autoload": { … // use whichever method you prefer, but make sure it’s being loaded correctly
"minimum-stability": "dev"
composer dump-autoload
main project:
1. edit your composer.json to contain the following:
"repositories": [
{
"type": "vcs",
"url": "/full/path/to/the/local/package/package-name"
}
],
"require": {
"vendor-name/package-name": "dev-master"
},
composer update vendor-name/package-name
now check your vendor directory you should see the vendor-name/package- name
NOTE: whenever you make change in the local package (not the vendor) you need to git commit then you can composer update the main project, it will get the latest copy of the repo to the main project vendor directory.
Advantage:
- you don’t touch the vendor directory (running composer update by mistake will not override your local changes) - you don’t need your package to be on packagist to use it
Disadvantage:
- you have to keep committing your changes (in the local package) and then running composer update in the main project
- you cannot publish the composer.json on production (needs editing before publishing to require the real package)
I think you've just got the syntax wrong. The type should just be VCS, and then composer figures out what type of VCS it is.
So in your project B, the entry for repositories should be:
"repositories": [
{
"type": "vcs",
"url" : "/d/workspaces/util"
}
],
You don't need to name what library is available in /d/workspaces/util. Composer will scan the composer.json file in that directory and know what project name is available there, and use the project from that directory in preference to a version listed on packagist or other repository.
The easiest way is to use type=path https://getcomposer.org/doc/05-repositories.md#path
{
"repositories": [
{
"type" : "path",
"url" : "/d/workspaces/util"
}
],
"require": {
"project/util" : "*"
},
}
I found this tutorial really useful: https://johannespichler.com/developing-composer-packages-locally/ when I was facing issues with local package production
Note the symlink condition allowing the vendor folder to be a symlink which then means you no longer need to composer update each time you want to see change
"options": {
"symlink": true
}
In addition to Danack's solution: Changing the path from /d/ to d:/ worked for me.
Like this:
"repositories": [
{
"type": "vcs",
"url" : "d:/workspaces/util"
}
],
NOTE: This answer assumes that you have something like a Package Registry or GIT repository where you
can retrieve the releases of your package. If you do not yet have this. https://getcomposer.org/doc/05-repositories.md
Composer enables us to autoload a local development package without contaminating the composer.lock file.
When Composer finds a conflict between two or more packages it wil autoload only one of these packages.
You can use the autoload-dev to autoload a specific folder for development. (https://getcomposer.org/doc/04-schema.md#autoload-dev)
The autoload-dev (and autoload) settings do not touch the composer.lock file
In your projects composer.json file:
"repositories": {
"99999999": {
"type": "composer",
"url": "https://gitlab.com/api/v4/group/99999999/-/packages/composer/packages.json"
}
}
"require": {
"a-vendor-name/test-package": "1.0.*"
},
"autoload-dev": {
"classmap": [
"./../../packages/a-vendor-name/test-package"
],
"exclude-from-classmap": [
"vendor/a-vendor-name/test-package"
]
}
In this example the packages directory lives outside the project root and contains its own package GIT repositories.
autoload-dev because we only want this folder to load when we are developing. (https://getcomposer.org/doc/04-schema.md#autoload-dev)
classmap to load the packages from a local directory. (https://getcomposer.org/doc/04-schema.md#classmap)
exclude-from-classmap to disable loading the package within the vendor directory.
Will also suppress the warning about multiple classes with the same namespace. (https://getcomposer.org/doc/04-schema.md#exclude-files-from-classmaps)
Running DEVELOPMENT (default behaviour):
composer update a-vendor-name/test-package // or any other composer command
Your package will still be downloaded from your Package Registry. This downloaded package is not only ignored in you applications code, its also possible to update it according to the project composer.json file. Which in turn will update the composer.lock file, the right way.
Running DTAP / PRODUCTION by using the --no-dev flag:
composer update a-vendor-name/test-package --no-dev // or any other composer command
In addition to #Glen Solsberry's solutions, if you're running in a docker container like me, you can add a volume to your docker-compose.yml file like:
services:
theservicename:
...
volumes:
- ../:/var/www
- /path/to/src/package:/var/www/vendor/path/to/src/package
...
When you make changes locally they will reflect in the container.

Composer download repository in Gitlab as archive

TL;DR
I need a way to make composer download my package as an archive so it excludes files and directories I don't want to be included that are on my .gitattributes as export-ignore
Background info
I have files in my composer package repository that I don't want to be included in projects that use this package (DataFixtures, Tests, CI configuration). I have setup a .gitattributes file which excludes those folders and files with export-ignore.
This works fine when downloading the package as a zip manually but it, of course, doesn't when you checkout the code with git.
This is where my problem starts, I have added the repository manually to the composer.json since it is a private gitlab instance. Whenever I run composer update it uses GIT to download the code. I probably need a way to either make composer remove the files that are on the .gitattributes or force it to download my repository as an archive.
composer.json example
"repositories": [
{
"url": "git#<my-gitlab-server>:composer-libraries/testproject.git",
"type": "git"
}
],
......
"require": {
"myownvendor/testproject": "^1.0",
}
Is there a way to solve this?
Try setting the preferred-install method for this repository to dist in your composer.json:
{
"config": {
"preferred-install": {
"myownvendor/testproject": "dist"
}
}
}
Alternatively, install dependencies by running
$ composer install --prefer-dist
For reference, see:
https://getcomposer.org/doc/06-config.md#preferred-install
https://getcomposer.org/doc/03-cli.md#install

How to fix Composer error: "could not scan for classes inside dir"?

I'm trying to install composer in terminal by entering this command:
php composer.phar install
it starts to install required packages but I'm getting this error type:
[RuntimeException]
Could not scan for classes inside "app/commands" which does not appear to be a file nor a folder
How can I overcome this issue?
Usually this happens when you have some corrupted files or any composer update has crashed or interrupted.
To solve, just delete the vendor folders and run
composer install
When you install Laravel it creates a
app/commands
folder. Looks like it's not there. Just create it or remove from composer.json:
"classmap": [
"app/commands", /// <--- this line
],
And run
composer update
artisan dump-autoload
The last one is similar to composer dump-autoload, but it does some Laravel stuff too.
If you don't have any commands you don't really need it. If you plan to create artisan commands, create that folder and it should work.
I had the same problem. In my case, I noticed that there was no app/commands folder in my laravel install. I created the commands folder and composer dump-autoload was working again!
You should be able to solve this issue by simply running:
rm -rf vendor/autoload.php vendor/autoload_runtime.php vendor/composer && composer install
This cleans up the corrupted files without having to remove the entire vendor folder or cleaning up the global cache.
As others have mentioned, this usually happens if you interrupt a running Composer (e.g., Ctrl+C during composer update). But it does not corrupt all of the files, only the composer internals – which the command above then removes.
This is an older question with valid answers, but somebody might find this helpful.
My problem was that I've had App instead of app in my directory path. Maybe this will help someone.
I am Xampp user on Windows 10. I try all of the above methods but none of them work for me. I fixed my problem with this method, and Hopefully, it will help others.
Create a directory C:\bin
Append ;C:\bin to your PATH environment variable (related help)
Download https://phar.phpunit.de/phpunit-5.7.phar and save the file as C:\bin\phpunit.phar
Open a command line (e.g., press Windows+R » type cmd » ENTER)
Create a wrapping batch script (results in C:\bin\phpunit.cmd):
C:\Users\username> cd C:\bin
C:\bin> echo #php "%~dp0phpunit.phar" %* > phpunit.cmd
C:\bin> exit
Open a new command line and confirm that you can execute PHPUnit from any path:
C:\Users\username> phpunit --version
PHPUnit x.y.z by Sebastian Bergmann and contributors.
This method solves my problem. Hope It will save your day too.
I had the same issue. For me it happened after I deleted a class dir and forgot to update composer.json.
The fix was simply updating the classmap array in composer.json
I think it happens because composer cache error. Try to clear its cache:
composer clearcache
then run the installer again
composer create-project --prefer-dist laravel/laravel blog
It generally happens when composer is unable to autoload classmap. Check whether the location to the file or folder is correct.
This happens due to your composer.lock file.
For instance in my case I was getting:
Could not scan for classes inside ".../vendor/drupal/core-composer-scaffold/PEAR/" which does not appear to be a file nor a folder
That directory indeed did not exist. However, search for 'PEAR' inside of your composer.lock... 'app/commands' in this case- and you will find the modules definition:
{
"name": "drupal/core-composer-scaffold",
"version": "8.9.11",
"source": {
"type": "git",
"url": "https://github.com/drupal/core-composer-scaffold.git",
"reference": "c902d07cb49ef73777e2b33a39e54c2861a8c81d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/drupal/core-composer-scaffold/zipball/c902d07cb49ef73777e2b33a39e54c2861a8c81d",
"reference": "c902d07cb49ef73777e2b33a39e54c2861a8c81d",
"shasum": ""
},
"require": {
"php": ">=4.4.0"
},
"require-dev": {
"phpunit/phpunit": "*"
},
"type": "class",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"classmap": [
"PEAR/"
]
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
"."
],
"license": [
"BSD-2-Clause"
],
"authors": [
{
"name": "Helgi Thormar",
"email": "dufuz#php.net"
},
{
"name": "Greg Beaver",
"email": "cellog#php.net"
}
],
"description": "The PEAR Exception base class.",
"homepage": "https://github.com/pear/PEAR_Exception",
"keywords": [
"exception"
],
"time": "2019-12-10T10:24:42+00:00"
},
Our important piece is:
"autoload": {
"classmap": [
"PEAR/"
]
},
Composer is attempting to autoload from that directory, which is why you get a composer crash- that directory doesn't exist. Likely the same thing in your case of 'app/commands'.
Remove the entire package from your composer.lock- which for clarity is the longer code posting above. Then rerun your 'composer require' for that package. Example: composer require drupal/core-composer-scaffold.
In my case I needed a specific version, the default would give me version 9, I needed 8. My command was composer require drupal/core-composer-scaffold:^8.
Once this is done your composer install will run without a hitch.
Here is another debugging idea:
I accidentally added the vendor/ folder to my repository which then got deployed.
After removing it from the repository, the error message
composer RuntimeException Could not scan for classes inside polyfill-php80/Resources/stubs which does not appear to be a file nor a folder
disappeared.
in most of cases it is happen because of copy or cloning so try to remove or rename VENDOR folder from the magento installation and rerun "composer install".
In my case, I was installing wordpress plugins by composer, especially yoast (wordpress-seo) and woocommerce from packagist.org. I changed the sources to wpackagist and it started to work ok:
"require": {
"wpackagist-plugin/wordpress-seo": "dev-trunk",
"wpackagist-plugin/woocommerce": "dev-trunk"
}

Composer Not Generating Autoloads For Library

I've set up two projects, an 'init' and a library, which is required by the init. They both have PSR-0 autoloads set, but the autoload values from the library are not added to the vendor/composer/autoload_namespaces.php in the init project.
Sample composer.json from the Library:
{
"name": "lxp/library",
"description": "A test library",
"autoload": {
"psr-0": {
"LXP\\Library": "src/"
}
}
}
Sample composer.json from the project that requires that library:
{
"name": "lxp/init",
"name": "A test init",
"autoload": {
"psr-0": {
"LXP\\Init": "src/"
}
},
"repositories": [
{
"type": "composer",
"url": "http://satis.repo.redacted/"
}
],
"require": {
"lxp/library": "dev-master"
}
}
The library contains the class LXP\Library\Something in the file src/LXP/Library/Something.php.
The project that requires the library contains the class LXP\Init\Now in the file src/LXP/Init/Now.php.
When running composer install in the 'init' project, it downloads the library project and puts it in vendor correctly, but vendor/composer/autoload_namespaces.php doesn't contain the library's autoload information, only that of the current project.
What am I doing wrong? If I run dump-autoload in the library project then the autoload_namespaces.php file is correct, and a quick bootstrap script confirms that it does indeed pick up the class.
EDIT - This is a problem with the satis-generated packages.json. To fix it, I had to add the autoload information from the library's composer.json into the json file I supply to satis, which seems like an unnecessary duplication and so I'm probably doing it wrong. Is there a single place that autoload information can be stored for satis libraries? For example, can satis read the composer.json files that exist in the libraries it scans?
EDIT #2 - Satis does not read the composer.jsons from repositories specified as 'package' type. This is obvious in hindsight, because 'package' is used for libraries that do not have a composer.json, and is a way to wrap composer-like dependency management around them.
Changing the satis.json's repository to 'vcs' type meant that the composer.json was read, and the information (including the autoload specification) was parsed and stored in the packages.json.
#Seldaek - thank you for suggesting that my satis config was the problem, and I hope that this clarifies satis / composer behaviour for anyone else in my position.
I see two possible mistakes you may have done that would cause this:
You forgot to update your satis repo so the autoload config for lxp/init is not up to date in there
You are running composer install from a lock file, and that means composer just reads the info from the composer.lock file and does not update package metadata to the latest version available in satis. To solve this you should run composer update instead.
Try composer dump-autoload command.
It depends how you installing your library via Composer. For example, when downloading it as package type (same I believe with composer type), Composer never reads the composer.json file, so instead you should use vcs or git type. See: GH-6846.
Here is composer.json which should work:
{
"require": {
"lxp/library": "dev-master"
},
"repositories": [
{
"type": "vcs",
"url": "http://satis.repo.redacted/"
}
]
}
Then run: composer install.
For troubleshooting, try running:
composer dump-autoload -o -vvv.
composer diagnose -vvv

Categories