Install PHP stats library on Ubuntu 16
Asked Answered
D

2

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?

Detached answered 22/3, 2017 at 20:57 Comment(7)
run php -m or phpinfo(); to see if the extension is actually loaded.Sate
Also, which php.ini did you change? There are multiple.Sate
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?Detached
phpinfo() and php -i tell you which one is used. (cli uses a different one than apache)Sate
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.Detached
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?Detached
consider accepting an answerChoplogic
D
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!

Detached answered 23/3, 2017 at 15:40 Comment(0)
C
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 !

Corticosterone answered 19/10, 2018 at 9:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.