How can I enable the PHP BC Math extension for a site?

Hi Laura,

Here’s how you can compile BC Math for PHP 7.0.3 and other versions of PHP in Local:


References:


Based off of the guides above, here’s how you can compile BC Math.

Download the version of PHP you’re running

  1. Go to https://php.net/get/php-7.0.3.tar.gz/from/a/mirror (change 7.0.3 with the appropriate version)
  2. Extract the .tar.gz into the site’s app folder. The extracted folder should be adjacent to the public folder.

Download dependencies

  1. Right-click on the site in Local’s sidebar
  2. Go to “Open Site SSH”
  3. Run apt-get update && apt-get install -y build-essential autoconf pkg-config

Compile the extension

  1. Enter cd /app/php*/ext/bcmath
  2. Enter /opt/php/7.0.3/bin/phpize
  3. Enter ./configure --with-php-config=/opt/php/7.0.3/bin/php-config
  4. Enter make && make install. You should see something like Installing shared extensions: /opt/php/7.0.3/lib/php/extensions/no-debug-non-zts-20151012/
  5. Run ls -la PATH_FROM_ABOVE to see what the new extension filename is. It’ll be bcmath.so

Configuring PHP to use the extension

To finish up, follow the steps after Configure PHP to use the extension in this thread: How do I compile additional PHP extensions? - Local Classic FAQs - Local Community


Pre-compiled BC Math extension for PHP 7.0.3

For your convenience, here’s a precompiled version for PHP 7.0.3 that I created using the steps above.

To use it, you can do the following:

bcmath.so.zip (67.9 KB)

  1. Download and extract the zip into the site’s app folder so it should look something like app/bcmath.so
  2. Right-click on the site in Local and go to “Open Site SSH”
  3. Run: mv /app/bcmath.so /opt/php/7.0.3/lib/php/extensions/no-debug-non-zts-20151012/bcmath.so
  4. Run: echo -e '\n\nextension = /opt/php/7.0.3/lib/php/extensions/no-debug-non-zts-20151012/bcmath.so' >> /conf/php/7.0.3/php.ini
  5. Restart the site in Local
  6. Check the PHP info for BC Math by clicking on the i by the PHP version number in Local
1 Like