このドキュメントについて
きっかけとしては、ECサイトmagentoインストール時に、php extension mcrypt must be loadedのエラーがでたため。
暗号化ライブラリを利用するパッケージやフレームワーク、magento、laravelなどはphp54-mcryptが必要となってきます。
php54-mcryptのextensionのMacOSへの設定方法について書いています。
環境
MacOSX
PHP 5.4.30 (cli) (built: Jul 29 2014 23:43:29)
php54-mcryptのインストールと設定
home brewインストールでのエラー
- 以下のようなエラーがでてしまう場合があります。
brew install php54-mcrypt
Error: No available formula for php54-mcrypt
Searching taps...
homebrew/php/php54-mcrypt
homebrew tapでの解決
Homebrewに「tap」というコマンドがあります。
このコマンドを使う事で、公式以外でフォーミュラを公開していたリポジトリをhomebrewの中に取り込むことができ、$ brewコマンドで扱えるようになります。
githubアカウントにアップしているフォーミュラがある場合は、それも取り込むことができます。
$ brew tap ユーザー名/リポジトリ名
リポジトリの追加方法には2通りあります。
- 1つめの方法
PHP 5.4 development on OS X with MySQL and Laravel 4
This command should return a list of formulas that can be installed, you’ll notice that they are all under a formula repository homebrew/php so we need to tap that repository so Homebrew knows can use it.
You’ll see some familiar git cloning feedback as Homebrew clones the repository but once it has been done run the brew search php54 command again and you’ll see all the formulas without that repository prefix now. Before we install PHP though we need to tap another repository for some dependencies. I’m also going to install the Xdebug module for PHP at the same time as it’s a useful development aid.
brew tap homebrew/php
brew tap homebrew/dupes
- 2つめの方法
Error: No available formula for php54-mcrypt on Mac OS X Mavericks
You will need to run brew tap homebrew/dupes and then brew tap josegonzalez/homebrew-php
Then run brew install php54-mcrypt again.
brew tap josegonzalez/homebrew-php
上記のうちのどちらかを実行することで以下のインストールができるかと思います。
brew install php54-mcrypt
(略)
To finish installing mcrypt for PHP 5.4:
* /usr/local/etc/php/5.4/conf.d/ext-mcrypt.ini was created,
do not forget to remove it upon extension removal.
* Validate installation via one of the following methods:
*
* Using PHP from a webserver:
* - Restart your webserver.
* - Write a PHP page that calls "phpinfo();"
* - Load it in a browser and look for the info on the mcrypt module.
* - If you see it, you have been successful!
*
* Using PHP from the command line:
* - Run "php -i" (command-line "phpinfo()")
* - Look for the info on the mcrypt module.
* - If you see it, you have been successful!
==> Summary
? /usr/local/Cellar/php54-mcrypt/5.4.35: 3 files, 56K, built in 33 seconds
php.iniファイルへ追記
上記のインストール完了メッセージにmcrypt.iniのファイルの場所をしめすメッセージがでています。
* /usr/local/etc/php/5.4/conf.d/ext-mcrypt.ini was created,
これをphpに読み込ませるようにしましょう。
私の場合は、php.iniに追記して、apacheを再起動しました。
[mcrypt]
extension="/usr/local/Cellar/php54-mcrypt/5.4.35/mcrypt.so"
参考サイト
- magento - php extension mcrypt must be loaded - Stack Overflow
- The mcrypt extension is missing | OS X Mavericks Install mcrypt in 10.9
- Installing mcrypt extension for PHP on OSX Mountain Lion - Stack Overflow
- Error: No available formula for php54-mcrypt on Mac OS X Mavericks
- PHP 5.4 development on OS X with MySQL and Laravel 4
おまけ
東洋経済オンラインで「エンジニア夫婦のあるある日記」を連載中です