5

I am setting up a fresh server for laravel application. I have installed composer and chosen php5.6.15 from my cpanel. But when I run php -v command in terminal it shows my current version as php5.2.19.

Here is my php.ini file on my server it show 5.6 version

enter image description here

I have uploaded my code to server using git. When I run command composer install it gives me this error.

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - laravel/framework v5.1.28 requires php >=5.5.9 -> your PHP version (5.4.43) or value of "config.platform.php" in composer.json does not satisfy that requirement.
    - laravel/framework v5.1.28 requires php >=5.5.9 -> your PHP version (5.4.43) or value of "config.platform.php" in composer.json does not satisfy that requirement.
    - Installation request for laravel/framework v5.1.28 -> satisfiable by laravel/framework[v5.1.28].

I am using laravel 5.1. If I downgrade it to 5.0 it gives dependency errors with other packages. Here is my composer.json file.

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=5.4.43",
        "laravel/framework": "5.1.*",
        "bestmomo/scafold": "dev-master",
        "illuminate/html": "5.*",
        "barryvdh/laravel-debugbar": "^2.0",
        "intervention/image": "^2.3",
        "doctrine/dbal": "^2.5",
        "davejamesmiller/laravel-breadcrumbs": "^3.0",
        "yajra/laravel-datatables-oracle": "^5.11",
        "zizaco/entrust": "dev-laravel-5"
    },
    "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 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",
    }
}

I have php56 available under /usr/php/php56 and I can run it by making alias to it or just typing complete path. I also made an alias to it and after that php -v shows me 5.6.15 but when I run composer install it still gives the same above output.

I may be unable to set default version of php cli to 5.6 or it is something with laravel framework support on bluehost servers. I think bluehost support is less concerned because I have composer which can do rest piece of work. Your help to sort out this issue is very much appreciated.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
tmw
  • 1,424
  • 1
  • 15
  • 26
  • are you sure you want to build and download dependencies on a remote (probably production environment)? It sounds like a bad practice. It's better to create a package (even a zip ) with your project and deploy it to a remove server than to build it there (with dependencies) – mkbrv Jan 19 '16 at 22:00
  • @mikibrv you are suggesting that I should deploy my complete source from my local machine with all composer packages installed which are under `vendor/` directory?? – tmw Jan 20 '16 at 09:00
  • 1
    yes. I guess that is the safest and best way to deploy a web app (php - java - whatever). It's a package that you've already built and tested, you know what it is there (somehow similar to a GIT TAG). Most of the time you don't even need to upload the vendor directory (but then you would have to use some versioning like GIT). I have made myself a script that simply creates a zip from the app - bootstrap - public - vendor directories and .htaccess file – mkbrv Jan 20 '16 at 14:32
  • @mikibrv You are supposed to mirror local and production environment, that's what provisioning is for. This way developers can work in identical environments. The vendor dir should never be uploaded, you must run `composer install` in production or testing and `composer update` in development. – user2094178 Jan 24 '16 at 19:24
  • 1
    that makes no sense. If you want to mirror local with production, you will upload the vendor folder each time it changes and also make sure it does not happen to often. In case you do composer install in production, first of all you will have down time during the procedure and in case something unexpected happens, you cannot debug. – mkbrv Jan 26 '16 at 17:45
  • @tahirwaseer i changed my php version 5.6 after that i coudn't install composer i will get this error https://drive.google.com/open?id=0ByoLPyyQ3jAjZ0ZHTmJlSExPNDQ what can i do for this ? – Prudential Developer Apr 11 '16 at 12:06
  • @PrudentialDeveloper You can make phar extension available by enabling it in php.ini file of your current php version. Open your php.ini file in some editor say vim and find extensions section and un-comment `"extension= phar.so"`. If you cannot find it add this line and save file. Similar thread is [link](http://stackoverflow.com/questions/27437206/composer-installing-the-json-extension-is-missing) here which can help you solve your problem. Keep in mind thread mentioned in link gives solution for `json.so` extension. You have to do for `phar.so`. – tmw Apr 11 '16 at 17:39
  • @tahirwaseer for laravel 5.2 i need php version 5.6 if i use 5.4 i can't use laravel 5.2 – Prudential Developer Apr 11 '16 at 18:04
  • @tahirwaseer i used this link to install composer and create Laravel project [LINK](http://blog.stickyrice.net/archives/2014/laravel-putty-shared-hosting/) – Prudential Developer Apr 11 '16 at 18:07

1 Answers1

1

You should execute it like the following:

/usr/php/php56 composer.phar

I have to do something similar at HostGator for composer to work.

To grab composer.phar just run php -r "readfile('https://getcomposer.org/installer');" | php.

user2094178
  • 9,204
  • 10
  • 41
  • 70
  • I have the exact same problem as OP. I uploaded php-5.6.17 to my root folder in my server. When I run the command /php-5.6.17 composer.phar, I just get "php-5.6.17 is a directory" in response. Same for if I do the command "/usr/php/56 composer.phar," since /usr/php/php56 is not a valid directory in my case. Obviously I'm looking for a file and not a directory, but I'm not sure which file I'm looking for. I have php56s, but no php56. Not only that, but when I execute the command with php56, it says I need to use php-cli. Do you have any ideas on how I could fix this? Thank you. – Jameson Feb 17 '16 at 19:39
  • Ah, got it. I had to run the command: /usr/php/56/bin/php composer.phar install – Jameson Feb 17 '16 at 21:01
  • im in public_html path.... how can i execute this line `/usr/php/php56 composer.phar` – Prudential Developer Apr 11 '16 at 05:31
  • @user2094178 im also try to install composer im getting error https://drive.google.com/open?id=0ByoLPyyQ3jAjZ0ZHTmJlSExPNDQ help me on this – Prudential Developer Apr 11 '16 at 12:07
  • for Hostgator (shared hosting) use /opt/php56/bin/php composer.phar – Žiga Jul 18 '16 at 16:20