Skip to content

Instantly share code, notes, and snippets.

@doole
Created October 27, 2016 08:17
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 doole/d7f9f7e9ded1841089b17d9312400a2e to your computer and use it in GitHub Desktop.
Save doole/d7f9f7e9ded1841089b17d9312400a2e to your computer and use it in GitHub Desktop.
Install mcrypt PHP extension on macOS
#!/bin/bash
# Install Xcode Command-Line Tools first (required)
xcode-select --install
# Check PHP version
PHP_VER=$(php -v | head -1 | awk '{ print $2 }')
# Extensions directory (default: empty string)
EXT_DIR=""
# El Capitan / Sierra workaround
if [ $(uname -r | head -c2) > 14 ]; then
EXT_DIR=/usr/local/lib/php/extensions/
mkdir -p $EXT_DIR
fi
# First, check if extension is already installed
php -m | grep mcrypt
# Update brew and install requirements
brew update
brew install autoconf
# Download PHP source and extract
cd /tmp
curl -O http://php.net/distributions/php-$PHP_VER.tar.bz2
tar -xjf php-$PHP_VER.tar.bz2
# Go to extension dir and compile
cd /tmp/php-$PHP_VER/ext/mcrypt/
phpize
./configure
make
# El Capitan / Sierra workaround
if [ $(uname -r | head -c2) > 14 ]; then
cp ./modules/mcrypt.so $EXT_DIR
else
sudo make install
fi
echo "extension=${EXT_DIR}mcrypt.so" | sudo tee -a /private/etc/php.ini
# Check if extension is installed
php -m | grep mcrypt
# Cleanup
rm -rf /tmp/php-*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment