Home » Php » ubuntu – Installing Lapack on PHP

ubuntu – Installing Lapack on PHP

Posted by: admin July 12, 2020 Leave a comment

Questions:

I am trying to install Lapack to use it with PHP (http://php.net/manual/en/book.lapack.php) as it is the only PHP library that I have found that contains computations for singular values.

I am on a Ubuntu 14.04 server with Apache2.

I have installed gfortran and liblapack-dev as instructed on other websites, but they all stop short of describing how to include it. In short, I get an qerror when calling a static function from Lapack, saying that it is not a defined class.

I figure that my next step is enabling the extension, but despite following this question (How to check which PHP extensions have been enabled/disabled in Ubuntu Linux 12.04 LTS?) I found no mention of Lapack. How should I resume to install Lapack for PHP? Thanks!

How to&Answers:

Installing Lapack from source

Note: Tested on Ubuntu 16.04.

Install prerequisites:

sudo apt-get install php5-dev git svn cmake gfortran liblapack-dev

Follow the instructions here (copied for convenience):

svn co https://icl.cs.utk.edu/svn/lapack-dev/lapack/trunk lapack
cd lapack
mkdir build
cd build
cmake -D BUILD_SHARED_LIBS=ON -D LAPACKE=ON ../
make 
sudo make install

This will create the Lapack shared library.
Now clone the php extension from source:

git clone https://github.com/ianbarber/php-lapack

And follow the instructions as described there:

cd php-lapack
phpize
./configure
make 
sudo make install

Check if the extension is installed: php -m | grep -i lapack

Note that the extension is most likely incompatible with PHP 7, as it has not been updated for over 5 years.