How to recompile php for MAMP in mac osx to support webp

The default compile of MAMP didn’t bring web image format with it. In order to use function imagewebp, the php must be recompiled from source.

Here are steps of how to in recompile php for MAMP:

First, open http://localhost/MAMP/index.php?language=English&page=phpinfo and get “ Configure Command ” part of phpinfo output. This is the example of mine

3C0A1A8D C12E 4780 9C1F B8796B9F65C8

Copy the value out to a text editor, we will need to append and change some values of the configuration

Second, run commands below to install some libs missing.

brew install webp libpq imap-uw

Third, download and unzip php source code

cd /Applications/MAMP/bin/php
wget http://cn2.php.net/get/php-7.0.15.tar.bz2/from/this/mirror -O php-7.0.15.tar.bz2
# if your download speed is slow with wget, you may use axel to make a multi thread download like this
# axel -n 30 -o php-7.0.15.tar.bz2 http://cn2.php.net/get/php-7.0.15.tar.bz2/from/this/mirror
tar xvf php-7.0.15.tar.bz2
cd php-7.0.15

Fourth, change with-imap with-imap-ssl with-pdo-pgsql option, and append –with-webp-dir=/usr/local/lib to the end. After this, you will get configure command like this

'./configure' \
'--with-apxs2=/Applications/MAMP/Library/bin/apxs' \
'--with-gd' '--with-jpeg-dir=/Applications/MAMP/Library' \
'--with-png-dir=/Applications/MAMP/Library' \
'--with-zlib' '--with-zlib-dir=/Applications/MAMP/Library' \
'--with-freetype-dir=/Applications/MAMP/Library' \
'--prefix=/Applications/MAMP/bin/php/php7.0.15' \
'--exec-prefix=/Applications/MAMP/bin/php/php7.0.15' \
'--sysconfdir=/Applications/MAMP/bin/php/php7.0.15/conf' \
'--with-config-file-path=/Applications/MAMP/bin/php/php7.0.15/conf' \
'--enable-ftp' '--enable-gd-native-ttf' '--with-bz2=/Applications/MAMP/Library' \
'--with-ldap' '--with-mysqli=mysqlnd' '--enable-mbstring=all' \
'--with-curl=/Applications/MAMP/Library' '--enable-sockets' '--enable-bcmath' \
'--with-imap=shared,/usr/local/Cellar/imap-uw/2007f' \
'--with-imap-ssl=/usr/local/lib' \
'--enable-soap' '--with-kerberos' '--enable-calendar' \
'--with-pgsql=shared,/Applications/MAMP/Library/pg' \
'--enable-exif' '--with-libxml-dir=/Applications/MAMP/Library' \
'--with-gettext=shared,/Applications/MAMP/Library' \
'--with-xsl=/Applications/MAMP/Library' '--with-pdo-mysql=mysqlnd' \
'--with-pdo-pgsql=shared,/usr/local/Cellar/libpq/10.3' \
'--with-mcrypt=shared,/Applications/MAMP/Library' \
'--with-openssl=/Applications/MAMP/Library' \
'--enable-zip' '--with-iconv=/Applications/MAMP/Library' \
'--enable-opcache' '--enable-intl' '--with-tidy=shared' \
'--with-icu-dir=/Applications/MAMP/Library' '--enable-wddx' \
'--with-libexpat-dir=/Applications/MAMP/Library' '--with-readline' '--with-mhash' \
'YACC=/Applications/MAMP/Library/bin/bison' \
--with-webp-dir=/usr/local

Run the configure command above and then

make -j 8
make install
cp libs/libphp7.so ../php7.0.15/modules/libphp7.so

Finally: Restart MAMP and go to phpinfo page, you will get WebP Support enabled in the phpinfo page.

Comments:

  • About Thread Safety: I got a Thread Safety enabled version when compiled like this, but the default is non-zts. So all the extensions like memcached, redis and so on also need to be reinstalled. You can install these extensions with pecl refer to this install instructions.
  • About error “libphp7.so requires version 6.0.0 or later, but libaprutil-1.0.dylib provides version 4.0.0”: If you cannot start Apache after recompile, then you can run script /Applications/MAMP/bin/startApache.sh and see the error info. If you got the error above, you can resolve it by make a file linkln -s /usr/local/Cellar/apr-util/1.5.4_1/libexec/lib/libaprutil-1.0.dylib /usr/local/opt/apr-util/lib/libaprutil-1.0.dylib

Have any other question? You are welcome to contact with me by email gyq5319920@gmail.com.

This entry was posted in PHP, mac开发. Bookmark the permalink.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


Verify Code   If you cannot see the CheckCode image,please refresh the page again!