PHP: Class 'Phar' not found PHP: Class 'Phar' not found php php

PHP: Class 'Phar' not found


Try specifying the path to the extension:

php -d extension=phar.so composer.phar <your_script>

Other options:

Based on the information you provided, there are a few possibilities:

  • You are using a different php.ini. Check the output of phpinfo() to confirm, and ensure that you are editing the active one.

  • /usr/lib/php/modules/phar.so is not readable. Ensure that the web server user can read this file.

  • Your web server has not been restarted since you last added the phar-related information to php.ini. Restart your webserver.


This works for me:

php -d extension=phar.so composer.phar [... your command ...]

This includes the phar extension for the current runtime. Works for shared / VPC servers.


On CentOS ...

  • phar.so is contained in the php-common package.
  • the phar executable is contained in the php-cli package.
  • php-mbstring and php-bz2 also seems to be required.

When php -m | grep phar returns nothing, one has to add these .ini files for the CLI:

sudo cp /etc/php-zts.d/phar.ini /etc/php-cli.d/phar.inisudo cp /etc/php-zts.d/mbstring.ini /etc/php-cli.d/mbstring.inisudo cp /etc/php-zts.d/bz2.ini /etc/php-cli.d/bz2.ini

Alternatively, one can add the same module .ini files as the webserver uses:

sudo cp /etc/php-zts.d/* /etc/php-cli.d/

It should look alike this:

$ php --iniConfiguration File (php.ini) Path: /etcLoaded Configuration File:         /etc/php.iniScan for additional .ini files in: /etc/php-cli.d/Additional .ini files parsed:      /etc/php-cli.d/bz2.ini,/etc/php-cli.d/mbstring.ini,/etc/php-cli.d/phar.ini

Then one can run it:

$ php ./composer.phar   ______  / ____/___  ____ ___  ____  ____  ________  _____ / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___// /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/                    /_/

And move it below the $PATH:

sudo mv ./composer.phar /usr/local/bin/composer