How to install PHPUnit on Linux

PHPUnit is a unit testing framework for PHP. The following article explains how you can install PHPUnit on your server or desktop machine:

In order to use PHPUnit you must first install PEAR.

sudo apt-get install php-pear

Next you have to update the PEAR channel in order to get updated channel data.

sudo pear channel-update pear.php.net

Then upgrade PEAR to the newest version.

sudo pear upgrade-all

Now to install PHPUnit we have to edit the PEAR config to allow it to autodiscover channels

sudo pear config-set auto_discover 1

Now we can install PHPUnit

sudo pear install pear.phpunit.de/PHPUnit

If you have any questions or suggestions let me know in the comments.

Jason Edwards

  • Rabin Karmachraya

    PHP Fatal error: Class ‘ActiveRecordConfig’ not found in
    > /srv/academyhq.localhost/webapp/application/core/AHQ_Loader.php on
    > line 17 PHP Stack trace: PHP 1. {main}() /usr/bin/phpunit:0 PHP 2.
    > PHPUnit_TextUI_Command::main() /usr/bin/phpunit:46 PHP 3.
    > PHPUnit_TextUI_Command->run()
    > /usr/share/php/PHPUnit/TextUI/Command.php:129 PHP 4.
    > PHPUnit_TextUI_Command->handleArguments()
    > /usr/share/php/PHPUnit/TextUI/Command.php:138 PHP 5.
    > PHPUnit_TextUI_Command->handleBootstrap()
    > /usr/share/php/PHPUnit/TextUI/Command.php:606 PHP 6.
    > PHPUnit_Util_Fileloader::checkAndLoad()
    > /usr/share/php/PHPUnit/TextUI/Command.php:778 PHP 7.
    > PHPUnit_Util_Fileloader::load()
    > /usr/share/php/PHPUnit/Util/Fileloader.php:76 PHP 8. include_once()
    > /usr/share/php/PHPUnit/Util/Fileloader.php:92 PHP 9.
    > set_controller()
    > /srv/academyhq.localhost/webapp/application/third_party/CIUnit/bootstrap_phpunit.php:265
    > PHP 10. CIUnit::set_controller()
    > /srv/academyhq.localhost/webapp/application/third_party/CIUnit/libraries/CIUnit.php:220
    > PHP 11. load_class()
    > /srv/academyhq.localhost/webapp/application/third_party/CIUnit/libraries/CIUnit.php:74
    > PHP 12. AHQ_Loader->__construct()
    > /srv/academyhq.localhost/webapp/application/third_party/CIUnit/core/Common.php:116
    > PHP 13.
    > AHQ_Loader->initialise_php_activerecord_from_codeigniter_database_config()
    > /srv/academyhq.localhost/webapp/application/core/AHQ_Loader.php:7

  • jasonsedwards

    Looks like you need to remove PHPUnit and reinstall it. Try doing an sudo apt-get autoremove after you uninstall it before installing it again.