1

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...

unclexo
  • 3,691
  • 2
  • 18
  • 26
ab-oc
  • 39
  • 1
  • 1
  • 5
  • 3
    Possible duplicate of [How to install a specific version of package using Composer?](https://stackoverflow.com/questions/40914114/how-to-install-a-specific-version-of-package-using-composer) – Muhammad Omer Aslam Jun 26 '18 at 18:56
  • 1
    Not really a duplicate of that one. This one is more about an error due to running composer install incorrectly (in the wrong folder), and doesn't have much to do with specific versions (despite the error message). – mkasberg Jun 28 '18 at 14:50
  • Make sure composer is globally installed. Try `sudo composer require vendor/pacakge` in case of any problem. – unclexo Feb 11 '20 at 06:05

2 Answers2

4

You don't need to download mPDF, that is what composer will do for you.

Do this:

  1. Create an empty directory in which you will use mPDF
  2. Run composer require mpdf/mpdf in the new directory
    • Composer will now install mPDF and create autoloading files
  3. Require vendor/autoload.php in a PHP file
  4. Done, you now can use mPDF in the file.
Finwe
  • 6,372
  • 2
  • 29
  • 44
  • No composer.json in current directory – showtime Oct 23 '19 at 12:23
  • @BMX Lacking context. Maybe you can try searching the web for composer basics and then submit a separate question here if you still have problems. – Finwe Oct 23 '19 at 13:25
  • thats what the cmd will display if you try to do what you answered there. "No composer.json in current directory" – showtime Oct 23 '19 at 13:27
  • explain it in a better way so people dont get confused. – showtime Nov 06 '19 at 14:24
  • Confused how? Be more specific. I've just followed the 4 points and there were no problems. Not even any `No composer.json in current directory` message, only notice `./composer.json has been created`. – Finwe Nov 06 '19 at 17:20
  • I also followed similar 4 steps and encountered same 'No composer.json' error @BMX faced. I still haven't been able to overcome it. I use PHP 7.3.14-5+ubuntu18.04.1 – Sayuj3 Feb 11 '20 at 04:25
  • after running "composer require mpdf/mpdf" command i get this message " No composer.json in current directory, do you want to use the one at /data/projects/beanstalk/btl-v1? [Y,n]? ". – Sayuj3 Feb 11 '20 at 04:34
1
  1. Make sure composer is installed globally. It works fine so.
  2. Create an empty directory in which you will use any package, for example, mPDF
  3. Run composer require mpdf/mpdf in the new directory
    • The command above does not work use sudo composer require mpdf/mpdf
  4. 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
  5. Composer will now install mPDF and create autoload.php in the vendor directory for autoloading files
  6. mPDF installation is done. Now create a php file called mpdf.php for example, in same deirectory.
  7. 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();
unclexo
  • 3,691
  • 2
  • 18
  • 26