I'm totally new to composer ;-)
I try to install mPDF 7.1 on my localhost (ubuntu 16.04) with composer.
1.) I installed composer 1.6.5.
2.) Downloaded mPDF 7.1 (https://github.com/mpdf/mpdf/releases) and unzipped folder to hdd.
3.) Open terminal in mpdf-7.1.0 folder and typed $ composer require mpdf/mpdf to start process
--> Error message is thrown:
Problem 1
- The requested package mpdf/mpdf No version set (parsed as 1.0.0) is satisfiable by mpdf/mpdf[No version set (parsed as 1.0.0)] but these conflict with your requirements or minimum-stability.
So I don't know what's the problem is and don't find any help searching the web. Can you help me?
Andreas
EDIT: I tried also:
$ composer require mpdf/mpdf:7.1.0 and
$ composer require mpdf/mpdf "^7.1.0"
throw same error message...
You don't need to download mPDF, that is what composer will do for you.
Do this:
Create an empty directory in which you will use mPDF
Run composer require mpdf/mpdf in the new directory
Composer will now install mPDF and create autoloading files
Require vendor/autoload.php in a PHP file
Done, you now can use mPDF in the file.
Make sure composer is installed globally. It works fine so.
Create an empty directory in which you will use any package, for example, mPDF
Run composer require mpdf/mpdf in the new directory
The command above does not work use sudo composer require mpdf/mpdf
If you want to specify any version of your package
Then specify thus composer require vendor/package:version
For example: composer require mpdf/mpdf:7.1.0
Composer will now install mPDF and create autoload.php in the vendor directory for autoloading files
mPDF installation is done. Now create a php file called mpdf.php for example, in same deirectory.
Require vendor/autoload.php in that PHP file.
Directory structure should be where you installed mPDF:
vendor
composer.json
composer.lock
mpdf.php
And the mpdf.php file is as follows:
<?php
require_once __DIR__ . '/vendor/autoload.php';
$mpdf = new \Mpdf\Mpdf();
$mpdf->WriteHTML('<h1>Hello world!</h1>');
$mpdf->Output();
Related
I am trying to coinbase PHP API, I have downloaded PHP library from GitHub and created an index.php file to start working, below is index codes
<?php
require_once('src/Client.php');
require_once('src/Configuration.php');
require_once('src/Authentication/ApiKeyAuthentication.php');
use Coinbase\Wallet\Client;
use Coinbase\Wallet\Configuration;
$apiKey="";
$apiSecret="";
$configuration = Configuration::apiKey($apiKey, $apiSecret);
$client = Client::create($configuration);
?>
And this is generating below error
Fatal error: Interface 'Coinbase\Wallet\Authentication\Authentication' not found in /home/exhakduz/api/coinbase-php-master/src/Authentication/ApiKeyAuthentication.php on line 8
I can't find any solution
Use composer instead, and require the composer autoloader within your index.php. The docs suggest to install the library with composer as well.
Install the library using Composer. Please read the Composer
Documentation if you are unfamiliar with Composer or dependency
managers in general.
Composer setup / installation
Note: All commands below need to be run from the same directory where your index.php is located.
First off you'll need to download and install composer. The current version available is 1.8.6. Download this phar to the same location as your index.php script. Also create a composer.json file with {} as the contents, composer will save your dependencies to this file.
Make sure composer.phar has execute permissions (if on linux run chmod +x ./composer.phar)
Run ./composer.phar require coinbase/coinbase. This should install the dependencies within a vendor directory.
Finally, you can require the autoloader composer generates when installing dependencies, and the missing Interface error you are seeing will be resolved.
The composer.json file should contain the following (bare minimum):
{
"require": {
"coinbase/coinbase": "^2.8"
}
}
Example using autoloader
<?php
require_once('vendor/autoload.php');
use Coinbase\Wallet\Client;
use Coinbase\Wallet\Configuration;
$apiKey="";
$apiSecret="";
$configuration = Configuration::apiKey($apiKey, $apiSecret);
$client = Client::create($configuration);
I'm quite new with Laravel and wrote my first app.
I'm using Laravel 5.4 with PHP 7.1.5 on Windows, but when I run the composer require barryvdh/laravel-dompdf command, I get following issues. I have followed many "possible solutions" but still it is not working.
This is the error:
Your requirements could not be resolved to an installable set of
packages.
Problem 1
- Installation request for barryvdh/laravel-dompdf ^0.8.1 -> satisfiable by barryvdh/laravel-dom
pdf[v0.8.1].
- barryvdh/laravel-dompdf v0.8.1 requires dompdf/dompdf ^0.8 -> satisfiable by dompdf/dompdf[v0.
8.0, v0.8.1, v0.8.2] but these conflict with your requirements or minimum-stability.
Don't composer update. If you have dompdf/dompdf in your composer.json just update it, specifying 0.8.* as version and running
composer update dompdf/dompdf
then
composer require barryvdh/laravel-dompdf
--
Running a generic composer update will affect all your other dependencies you may want keep as they currently are.
All the changes affected by your composer update command are then recorded in your composer.lock file.
When you'll move your project somewhere else or you'll deploy it on a server for example, the composer install command will read the composer.lock file and will install the exact version of your dependencies which are recorded in it. So you'll be sure about the version of your dependencies.
Run this command
composer require barryvdh/laravel-dompdf "^0.8.2" .
Delete your composer.lock file and run:
composer install
Check then dompdf/dompdf may updated e.g. 0.7.* or ~0.7.0
composer update;
composer require barryvdh/laravel-dompdf;
I'm trying to use https://github.com/phpWhois/phpWhois in my PHP scripts, but can't get it to work. I'm an absolute beginner when it comes to using Composer.
This is what I tried:
Cloned the git repo locally
Installed Composer for Windows
In Powershell, navigated to the local repository
Typed composer require. Composer first asked me: Search for a package:, where I simply pressed ENTER. Then, Composer installed various packages in the vendor directory (phpunit, symfony, sebastian, etc.), and it created an autoload.php file.
But if I include that autoload.php in my example script (the basic example on the phpWhois Github main page), it generates the following error:
Fatal error: Class 'phpWhois\Whois' not found in /home/myServer/www/myApp/api/whoistest.php on line 12
Well, the Installation manual on the Github page says I should run
php composer.phar require "phpwhois/phpwhois":"~4.0"
So I tried the following in the Powershell console:
composer require "phpwhois/phpwhois":"~4.0"
[UnexpectedValueException]
Could not parse version constraint :~4.0: Invalid version string ":~4.0"
Then this:
composer require "phpwhois/phpwhois"
Problem 1
Conclusion: remove phpwhois/phpwhois dev-master
Can only install one of: phpwhois/phpwhois[dev-master, 4.2.3].
Can only install one of: phpwhois/phpwhois[dev-master, 4.2.4].
Can only install one of: phpwhois/phpwhois[v4.2.5, dev-master].
Installation request for phpwhois/phpwhois dev-master -> satisfiable by phpwhois/phpwhois[dev-master].
Installation request for phpwhois/phpwhois ^4.2 -> satisfiable by phpwhois/phpwhois[4.2.3, 4.2.4, v4.2.5].
Then this:
composer require "phpwhois/phpwhois:~4.0"
which gave the same error as above.
I tried various other syntaxes to specify the version here, but none of them worked.
Any ideas?
Ok, let's start from the beginning.
Download the latest composer.phar from getcomposer.org (scroll down to manual install).
Put it in your project root directory.
Remove all your current require statements from your composer.json.
Open a terminal and navigate to your project root.
Execute php composer.phar require phpwhois/phpwhois.
Execute php composer.phar install.
Include the autoloader in your code: require vendor/autoload.php.
I'm having trouble setting up php-casperjs for my project. I've never used composer before, so I'm not exactly sure what I'm doing wrong.
I got xampp installed on Windows with php version 5.6.12
Here are the steps I completed so far.
Downloaded and installed composer. It launches successfully from the command prompt.
Downloaded php-casperjs and extracted composer.json and src/Casper.php into my project folder C:\xampp\htdocs\test
Navigated to the project folder in the command prompt and ran composer install command which installed 22 packages
Then I ran composer require phpcasperjs/phpcasperjs command and here I ran into problems. I get the following error message
Using version ^1.2 for phpcasperjs/phpcasperjs
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested package phpcasperjs/phpcasperjs No version set (parsed as 1.0.0) is satisfiable by phpcasperjs/phpcasperjs[No version
set (parsed as 1.0.0)] but these conflict with your requirements or
minimum-stability.
Installation failed, reverting ./composer.json to its original
content.
When I run the following php code
use Browser\Casper;
$casper = new Casper();
I get Fatal error: Class 'Browser\Casper' not found in C:\xampp\htdocs\test\test.php on line 3
Step1: Go to you project directory and create a file "composer.json"
codes for composer.json
{
"require": {
"monolog/monolog": "1.0.*"
}
}
Note: You can create you composer.json with your required packages but i just created a simple composer.json file with monolog/monolog package. For your understanding you can follow my steps (this). You can remove the package monolog later on.
Now navigate to the project directory where composer.json file located
Run the following command:
composer require phpcasperjs/phpcasperjs
And you faced the above problem because of wrong or mismatched version of the intended package. Keep in mind that you always can create composer.json with your custom packages and their versions and which will be your package manager. For more detail about composer please visit Link
Ok, so I am trying to learn composer. I installed composer using my server's SSH and ran this line:
php composer.phar require tomwalder/php-gds
And it did this:
Using version ^2.1 for tomwalder/php-gds
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Installing tomwalder/php-gds (v2.1.0)
Downloading: 100%
tomwalder/php-gds suggests installing google/apiclient (Allows you to use the JSON API Gateway/Datastore endpoints.
Tested with 1.1.6)
Writing lock file
Generating autoload files
Great, so now I look on my webserver and nothing seems to have changed. No files appear to be there. Where does composer install the files to?
Everything is a file called vendor in your current directory. Take a look at Composer documentation to get what you're looking for
The core point: a vendor directory is created in your webroot, with all the packages, but most importantly an autoload.php file. Include it from your main file with require 'vendor/autoload.php'; and magically all classes are available now with the autoloaders.
The cool thing is that you can add an autoload section to your composer.json for your own project, and it will work identically.