-3

I am on a shared hosting with multiple domains of my own. I bought a new one and specifically for it I was required to use php 8.2 or above. Using MultiPHP manager I did set it to PHP 8.2 (ea-php82) and run the php -v command in the domain's directory and it said:
PHP 8.2.18 (cli) (built: Apr 18 2024 09:00:42) (NTS)

Copyright (c) The PHP Group

Zend Engine v4.2.18, Copyright (c) Zend Technologies

Now when I run the composer command composer install I get a bunch of errors saying I am using 8.1So I entered these commands:

[foo@foo foo.com]$ which php
/usr/local/bin/php
[foo@foo foo.com]$ /usr/local/bin/php -v
PHP 8.2.18 (cli) (built: Apr 18 2024 09:00:42) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.18, Copyright (c) Zend Technologies
[foo@foo foo.com]$ which composer
/opt/cpanel/composer/bin/composer

Then as required I enter this command and this happens:

[foo@foo foo.com]$ /usr/local/bin/php /opt/cpanel/composer/bin/composer install
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Your lock file does not contain a compatible set of packages. Please run composer update.

  Problem 1
    - Root composer.json requires php ^8.2 but your php version (8.1.28) does not satisfy that requirement.
  Problem 2
    - laravel/framework is locked to version v11.4.0 and an update of this package was not requested.
    - laravel/framework v11.4.0 requires php ^8.2 -> your php version (8.1.28) does not satisfy that requirement.
  Problem 3

Now if last possible thing that I tried was to use ignore platform requirements and that resulted in an error too:

[foo@foo foo.com]$ /usr/local/bin/php /opt/cpanel/composer/bin/composer install --ignore-platform-reqs
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Nothing to install, update or remove
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

   Error

  Call to undefined method ReflectionFunction::isAnonymous()

  at vendor/laravel/framework/src/Illuminate/Container/Container.php:680
    676▕      */
    677▕     protected function getClassForCallable($callback)
    678▕     {
    679▕         if (is_callable($callback) &&
  ➜ 680▕             ! ($reflector = new ReflectionFunction($callback(...)))->isAnonymous()) {
    681▕             return $reflector->getClosureScopeClass()->name ?? false;
    682▕         }
    683▕
    684▕         return false;

      +3 vendor frames

  4   [internal]:0
      Illuminate\Foundation\Application::Illuminate\Foundation\{closure}()
      +6 vendor frames

  11  artisan:13
      Illuminate\Foundation\Application::handleCommand()


   Error

  Call to undefined method ReflectionFunction::isAnonymous()

  at vendor/laravel/framework/src/Illuminate/Container/Container.php:680
    676▕      */
    677▕     protected function getClassForCallable($callback)
    678▕     {
    679▕         if (is_callable($callback) &&
  ➜ 680▕             ! ($reflector = new ReflectionFunction($callback(...)))->isAnonymous()) {
    681▕             return $reflector->getClosureScopeClass()->name ?? false;
    682▕         }
    683▕
    684▕         return false;

      +4 vendor frames

  5   artisan:13
      Illuminate\Foundation\Application::handleCommand()

Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
[foo@foo foo.com]$

Any solutions?

I have tried using MultiPHP manager in cPanel. I have tried giving different php version paths. I have tried using the composer's ignore platform requirements command as well.

5
  • 2
    Have you spoken to the hosting company about this? If you're on shared hosting there's not a lot you can probably do about it without their help Commented Apr 29, 2024 at 22:01
  • I could but this doesn't make sense does it though? Like if I use a specific php version then how is it possible that the version I specified is not being used. Also, this is a personal project so I am in no hurry. It would be good if I learn how to solve this myself. Commented Apr 29, 2024 at 22:04
  • That's why you need to speak to them - it looks like something is wrong with their setup. Commented Apr 29, 2024 at 22:05
  • 1
    Check which PHP version the composer runs on: stackoverflow.com/a/56379908 Commented Apr 30, 2024 at 2:43
  • Usually, you should not run any Composer command on your production host. Run them locally to generate your composer.lock, and run them during deployment on your deployment server Commented Apr 30, 2024 at 6:47

1 Answer 1

-1

Update your composer.json

"require": {
    "php": "^8.2.18",
Sign up to request clarification or add additional context in comments.

1 Comment

Please add some explanation to your answer such that others can learn from it. There is no version of PHP matching that constraint yet, and neither would this requirement help if Laravel itself requires a more recent version than currently used

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.