5

I'm trying to install the PHP statistics package on my Ubuntu 16.04 LTS server, and I'm stuck.

First off, config stuff:

$ apache2 -v
 Apache/2.4.18 (Ubuntu)

$ php -v
PHP 7.0.15-0ubuntu0.16.04.4 (cli) ( NTS )

$ pear -V
PEAR Version: 1.10.1

I have successfully added pear using apt-get as well as php-all-dev.

When I try to install the stats package with pecl, I get the following:

$ pecl install stats
pecl/stats is already installed and is the same as the released version 1.0.5

I have also added extension=stats.so to my php.ini and restarted apache.

But when I try to run any of the stats functions, I get the following error:

Fatal error: Uncaught Error: Call to undefined function stats_standard_deviation() in /var/www/html/testing/stats_library.php:14 Stack trace: #0 {main} thrown in /var/www/html/testing/stats_library.php on line 14

What am I missing?

LukeSkywalker
  • 153
  • 1
  • 8
  • run `php -m` or `phpinfo();` to see if the extension is actually loaded. – cweiske Mar 23 '17 at 08:00
  • Also, which php.ini did you change? There are multiple. – cweiske Mar 23 '17 at 09:18
  • Stats does not show up on the output of `php -m` or `phpinfo();`. I edited `/etc/php/7.0/apache2/php.ini`. Which one should I edit? – LukeSkywalker Mar 23 '17 at 14:09
  • phpinfo() and php -i tell you which one is used. (cli uses a different one than apache) – cweiske Mar 23 '17 at 14:20
  • `phpinfo();` uses the `apache2/php.ini` and `php -i` uses `/etc/php/7.0/cli/php.ini`. I added `extension=stats.so` to the cli ini, with no success. – LukeSkywalker Mar 23 '17 at 14:48
  • I just ran `pecl channel-update pecl.php.net` and got the following error: `PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/stats.so' - /usr/lib/php/20151012/stats.so: cannot open shared object file: No such file or directory in Unknown on line 0` -- Shouldn't `pecl install` have created a stats.so file? – LukeSkywalker Mar 23 '17 at 14:56
  • consider accepting an answer – f7n Nov 13 '19 at 14:33

2 Answers2

9

I was able to successfully add the extension by adding the version to the install command like this:

$  pecl install stats-2.0.3

I then added extension=stats.so to my php.ini and restarted apache. Everything works now!

LukeSkywalker
  • 153
  • 1
  • 8
3

So, first of all there is 2 PHP versions.

The CLI (command line) and the FPM used by your server.

The php stats module is a C library so we need to compile it, usually this is done with the PECL tool.

  1. Check if PECL is working

pecl list

  1. Install the stats module, if you use PHP7+ you should specify the package version as by default it pull the PHP5 version from the repo. Here is the repo https://pecl.php.net/package/stats

pecl install stats-2.0.3

This will compile and install the stats module. If you have an error check that you have the php-dev installed. On ubuntu

[Optionnal - adapt to your php version]

sudo apt-get install php7.2-dev

Then run again pecl install and it should work.

  1. Activate the extension.

Now we need to active the extension, and here is the catch. You need to edit both php.ini to have it work on CLI and FPM

For the CLI it's easy just do php -ini to find the path of the .ini file. For FPM, to be sure you can run <?php phpinfo(); ?> on your serveur and check the Loaded Configuration File.

Then edit both file adding

extension=stats.so

usualy this will probably be :

  • /etc/php/7.2/fpm/php.ini
  • /etc/php/7.2/cli/php.ini

And now (the ultimate trap!) don't forget to restart Apache AND FPM

sudo service apache2 restart

sudo service php7.2-fpm restart

Now you can check with the CLI with php -m and should see the stats module activated. For FPM just check in your phpinfo();

I hope this can help !

Kaizoku Gambare
  • 3,143
  • 3
  • 29
  • 41