LoginSignup
13
13

More than 5 years have passed since last update.

Mac OSXでphp-mcryptを使う

Last updated at Posted at 2014-11-16

このドキュメントについて

きっかけとしては、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を再起動しました。

php.ini

[mcrypt]
extension="/usr/local/Cellar/php54-mcrypt/5.4.35/mcrypt.so"

参考サイト

おまけ

東洋経済オンラインで「エンジニア夫婦のあるある日記」を連載中です

エンジニア夫婦のあるある日記

あるある日記.jpg

13
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
13