Skip to content

Instantly share code, notes, and snippets.

@saippuakauppias
Last active November 30, 2022 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saippuakauppias/fac2a33dfe420adb4a6cf19c257eef46 to your computer and use it in GitHub Desktop.
Save saippuakauppias/fac2a33dfe420adb4a6cf19c257eef46 to your computer and use it in GitHub Desktop.
Build PHP7 with lmdb support (or another needed) on MacOS in Homebrew

This method is suitable for compiling PHP from the source code not only for LMDB, but also through it you can perform any kind of configuration before installation.

Install lmdb

Unfortunately, it is currently not possible to change the database size and it is fixed at a size of 1MB (this restriction is defined in the library itself). To get around this, you need to patch the library itself before installation. Look here as: https://gist.github.com/saippuakauppias/95b6f7b139b3d117b7dac4aeead9f5b4

Proper way (not worked)

Build php7 from sources

--interactive: Download and patch formula, then open a shell. This allows the user to run ./configure --help and otherwise determine how to turn the software package into a Homebrew package.

brew install --build-from-source --interactive php

==> Installing php ==> Downloading https://www.php.net/distributions/php-7.3.11.tar.xz ==> Patching patching file acinclude.m4 Hunk #5 succeeded at 2504 (offset 85 lines). ==> Entering interactive mode Type exit to return and finalize the installation Install to this prefix: /usr/local/Cellar/php/7.3.11 ➜ php-7.3.11 #

./configure --with-lmdb=/usr/local/opt/lmdb
# ??? 
# need more args in `configure` or `make install`?
make
make test
exit

Hacker-style way

Update brew & patch formula

brew update
brew edit php

Need find --enable-dba and add below:

--with-lmdb=#{Formula["lmdb"].opt_prefix}

Build from sources

brew install --build-from-source php

Verify

In another terminal tab

php -v
php -i | grep lmdb
@saippuakauppias
Copy link
Author

If build falls with:

Last 15 lines from /Users/sks/Library/Logs/Homebrew/php/02.configure:
checking for pthreads_lib... pthread

Configuring SAPI modules
checking for Apache 2 handler module support via DSO through APXS...

Sorry, I cannot run apxs.  Possible reasons follow:

1. Perl is not installed
2. apxs was not found. Try to pass the path using --with-apxs2=/path/to/apxs
3. Apache was not built using --enable-so (the apxs usage page is displayed)

The output of /usr/local/opt/httpd/bin/apxs follows:
apxs:Error: /usr/local/opt/apr/libexec/bin/apr-1-config not found!.

configure: error: Aborting

you need to run:

brew edit apache2

and find --enable-suexec and add below:

"--enable-so",

and then:

brew reinstall --build-from-source apache2

@saippuakauppias
Copy link
Author

saippuakauppias commented Nov 30, 2022

brew tap shivammathur/php
brew edit shivammathur/php/php@7.3
# edit
brew reinstall --build-from-source shivammathur/php/php@7.3
# add to zshrc
brew link shivammathur/php/php@7.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment