composer scripts use older php version

2019-06-27 20:17发布

I host more and more sites on webfaction. Great provider! I ran into some problems though which I think are Linux related. Hope someone can help.

SSH command php -v defaults to an older version of php, So I created an alias in my .bash_profile:

alias composer="php70 $HOME/composer.phar"
alias php="php70"

When I preform a php -v now it returns PHP 7.0. So far, so good!

PHP 7.0.0 (cli) (built: Dec  4 2015 12:58:58) ( NTS )

But now when I run a composer install and put a php -v in the scripts -> post-install-cmd list in my composer.json file:

{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
    "php": ">=5.5.9",
    "laravel/framework": "5.1.*"
},
"require-dev": {
    "fzaninotto/faker": "~1.4",
    "mockery/mockery": "0.9.*",
    "phpunit/phpunit": "~4.0",
    "phpspec/phpspec": "~2.1"
},
"autoload": {
    "classmap": [
        "database"
    ],
    "psr-4": {
        "App\\": "app/"
    }
},
"autoload-dev": {
    "classmap": [
        "tests/TestCase.php"
    ]
},
"scripts": {
    "post-install-cmd": [
        "php -v",
        "php artisan clear-compiled",
        "php artisan optimize"
    ],
    "pre-update-cmd": [
        "php artisan clear-compiled"
    ],
    "post-update-cmd": [
        "php artisan optimize"
    ],
    "post-root-package-install": [
        "php -r \"copy('.env.example', '.env');\""
    ],
    "post-create-project-cmd": [
        "php artisan key:generate"
    ]
},
"config": {
    "preferred-install": "dist"
}

}

Now tt returns the old php version again, see this screenshot:

screenshot composer install

Maybe this seems completely logic to you guys/girls, but I'm stuck here.

1条回答
做自己的国王
2楼-- · 2019-06-27 21:09

Well, Composer doesn't use your alias to execute PHP.

You could use php70 -v in composer.json, but its better to symlink the newer PHP version to /bin/php, so that Composer can pick it up:


Create a ~/bin folder

mkdir ~/bin

Then symlink the newer PHP version /usr/local/bin/php70 to just~/bin/php

ln -s /usr/local/bin/php70 ~/bin/php

Finally, add this line to .bash_profile to append this folder to your environment variable PATH.

export PATH="$HOME/bin:$PATH"
查看更多
登录 后发表回答