Composer. How to install a specific version of package based on user php version?











up vote
1
down vote

favorite












I have a two version of my package: for php7 and for php5. Is it possible to make composer determine when installing the package which version of php the user has, and depending on this, install the correct version of my package?










share|improve this question









New contributor




Zhalgas Zhamaliev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1




    Is the question incomplete? Maybe have two composer.json files. Just telling.
    – Praveen Kumar Purushothaman
    6 hours ago

















up vote
1
down vote

favorite












I have a two version of my package: for php7 and for php5. Is it possible to make composer determine when installing the package which version of php the user has, and depending on this, install the correct version of my package?










share|improve this question









New contributor




Zhalgas Zhamaliev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1




    Is the question incomplete? Maybe have two composer.json files. Just telling.
    – Praveen Kumar Purushothaman
    6 hours ago















up vote
1
down vote

favorite









up vote
1
down vote

favorite











I have a two version of my package: for php7 and for php5. Is it possible to make composer determine when installing the package which version of php the user has, and depending on this, install the correct version of my package?










share|improve this question









New contributor




Zhalgas Zhamaliev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I have a two version of my package: for php7 and for php5. Is it possible to make composer determine when installing the package which version of php the user has, and depending on this, install the correct version of my package?







php composer-php dependency-management






share|improve this question









New contributor




Zhalgas Zhamaliev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Zhalgas Zhamaliev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 6 hours ago





















New contributor




Zhalgas Zhamaliev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 6 hours ago









Zhalgas Zhamaliev

83




83




New contributor




Zhalgas Zhamaliev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Zhalgas Zhamaliev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Zhalgas Zhamaliev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 1




    Is the question incomplete? Maybe have two composer.json files. Just telling.
    – Praveen Kumar Purushothaman
    6 hours ago
















  • 1




    Is the question incomplete? Maybe have two composer.json files. Just telling.
    – Praveen Kumar Purushothaman
    6 hours ago










1




1




Is the question incomplete? Maybe have two composer.json files. Just telling.
– Praveen Kumar Purushothaman
6 hours ago






Is the question incomplete? Maybe have two composer.json files. Just telling.
– Praveen Kumar Purushothaman
6 hours ago














2 Answers
2






active

oldest

votes

















up vote
2
down vote



accepted










TL;DR: Yes.



By default, composer uses the version of the php executable to determine, which version of the package to install. This can be overridden in the config section of composer.json, for example:



"config": {
"vendor-dir": "vendor",
"platform": {
"php": "5.6"
}
}


When someone requires your package, this version is compared to the one specified in the requirements list of your package's composer.json:



"require": {
"php": ">=7.2.0",
}


So if, for example, version 1 of your package requires php 5.6, and version 2 requires php 7.0, someone who runs composer require your-package with php 5.6 will have version 1 installed. If someone runs it with an older version than required by any of your versions, they'll get an error stating that composer could not find a package that satisfies all the requirements, the php version being one of them.






share|improve this answer





















  • Thank you. Your answer helped me a lot
    – Zhalgas Zhamaliev
    3 hours ago


















up vote
0
down vote













Install only one composer you can access this composer with different php version



/usr/bin/php /usr/local/bin/composer
/usr/bin/php7.1 /usr/local/bin/composer
/usr/bin/php7.0 /usr/local/bin/composer





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });






    Zhalgas Zhamaliev is a new contributor. Be nice, and check out our Code of Conduct.










     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371333%2fcomposer-how-to-install-a-specific-version-of-package-based-on-user-php-version%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted










    TL;DR: Yes.



    By default, composer uses the version of the php executable to determine, which version of the package to install. This can be overridden in the config section of composer.json, for example:



    "config": {
    "vendor-dir": "vendor",
    "platform": {
    "php": "5.6"
    }
    }


    When someone requires your package, this version is compared to the one specified in the requirements list of your package's composer.json:



    "require": {
    "php": ">=7.2.0",
    }


    So if, for example, version 1 of your package requires php 5.6, and version 2 requires php 7.0, someone who runs composer require your-package with php 5.6 will have version 1 installed. If someone runs it with an older version than required by any of your versions, they'll get an error stating that composer could not find a package that satisfies all the requirements, the php version being one of them.






    share|improve this answer





















    • Thank you. Your answer helped me a lot
      – Zhalgas Zhamaliev
      3 hours ago















    up vote
    2
    down vote



    accepted










    TL;DR: Yes.



    By default, composer uses the version of the php executable to determine, which version of the package to install. This can be overridden in the config section of composer.json, for example:



    "config": {
    "vendor-dir": "vendor",
    "platform": {
    "php": "5.6"
    }
    }


    When someone requires your package, this version is compared to the one specified in the requirements list of your package's composer.json:



    "require": {
    "php": ">=7.2.0",
    }


    So if, for example, version 1 of your package requires php 5.6, and version 2 requires php 7.0, someone who runs composer require your-package with php 5.6 will have version 1 installed. If someone runs it with an older version than required by any of your versions, they'll get an error stating that composer could not find a package that satisfies all the requirements, the php version being one of them.






    share|improve this answer





















    • Thank you. Your answer helped me a lot
      – Zhalgas Zhamaliev
      3 hours ago













    up vote
    2
    down vote



    accepted







    up vote
    2
    down vote



    accepted






    TL;DR: Yes.



    By default, composer uses the version of the php executable to determine, which version of the package to install. This can be overridden in the config section of composer.json, for example:



    "config": {
    "vendor-dir": "vendor",
    "platform": {
    "php": "5.6"
    }
    }


    When someone requires your package, this version is compared to the one specified in the requirements list of your package's composer.json:



    "require": {
    "php": ">=7.2.0",
    }


    So if, for example, version 1 of your package requires php 5.6, and version 2 requires php 7.0, someone who runs composer require your-package with php 5.6 will have version 1 installed. If someone runs it with an older version than required by any of your versions, they'll get an error stating that composer could not find a package that satisfies all the requirements, the php version being one of them.






    share|improve this answer












    TL;DR: Yes.



    By default, composer uses the version of the php executable to determine, which version of the package to install. This can be overridden in the config section of composer.json, for example:



    "config": {
    "vendor-dir": "vendor",
    "platform": {
    "php": "5.6"
    }
    }


    When someone requires your package, this version is compared to the one specified in the requirements list of your package's composer.json:



    "require": {
    "php": ">=7.2.0",
    }


    So if, for example, version 1 of your package requires php 5.6, and version 2 requires php 7.0, someone who runs composer require your-package with php 5.6 will have version 1 installed. If someone runs it with an older version than required by any of your versions, they'll get an error stating that composer could not find a package that satisfies all the requirements, the php version being one of them.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered 5 hours ago









    Bartosz Zasada

    2,48521021




    2,48521021












    • Thank you. Your answer helped me a lot
      – Zhalgas Zhamaliev
      3 hours ago


















    • Thank you. Your answer helped me a lot
      – Zhalgas Zhamaliev
      3 hours ago
















    Thank you. Your answer helped me a lot
    – Zhalgas Zhamaliev
    3 hours ago




    Thank you. Your answer helped me a lot
    – Zhalgas Zhamaliev
    3 hours ago












    up vote
    0
    down vote













    Install only one composer you can access this composer with different php version



    /usr/bin/php /usr/local/bin/composer
    /usr/bin/php7.1 /usr/local/bin/composer
    /usr/bin/php7.0 /usr/local/bin/composer





    share|improve this answer

























      up vote
      0
      down vote













      Install only one composer you can access this composer with different php version



      /usr/bin/php /usr/local/bin/composer
      /usr/bin/php7.1 /usr/local/bin/composer
      /usr/bin/php7.0 /usr/local/bin/composer





      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        Install only one composer you can access this composer with different php version



        /usr/bin/php /usr/local/bin/composer
        /usr/bin/php7.1 /usr/local/bin/composer
        /usr/bin/php7.0 /usr/local/bin/composer





        share|improve this answer












        Install only one composer you can access this composer with different php version



        /usr/bin/php /usr/local/bin/composer
        /usr/bin/php7.1 /usr/local/bin/composer
        /usr/bin/php7.0 /usr/local/bin/composer






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 5 hours ago









        Raju Sadadiya

        13




        13






















            Zhalgas Zhamaliev is a new contributor. Be nice, and check out our Code of Conduct.










             

            draft saved


            draft discarded


















            Zhalgas Zhamaliev is a new contributor. Be nice, and check out our Code of Conduct.













            Zhalgas Zhamaliev is a new contributor. Be nice, and check out our Code of Conduct.












            Zhalgas Zhamaliev is a new contributor. Be nice, and check out our Code of Conduct.















             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371333%2fcomposer-how-to-install-a-specific-version-of-package-based-on-user-php-version%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

            ts Property 'filter' does not exist on type '{}'

            mat-slide-toggle shouldn't change it's state when I click cancel in confirmation window