seckie's programming memo

プログラミングするにあたって調べたことなどのメモ。たまにひどい英語で書く。

Homebrew 導入後にやったこと

MacPorts からの乗り換え。Homebrew インストール手順は省略。
PHP + MySQL が動作する環境ができるまで。 参考にさせていただいた記事:
http://qiita.com/livejam_db/items/b70caccdeece036a3797

環境

brew doctor でまずは診断。

$ brew doctor
Warning: Broken symlinks were found. Remove them with `brew prune`:
  /usr/local/lib/node_modules/generator-website1

Warning: You have MacPorts or Fink installed:
  /opt/local/bin/port

This can cause trouble. You don't have to uninstall them, but you may want to
temporarily move them out of the way, e.g.

  sudo mv /opt/local ~/macports

Warning: Unbrewed .pc files were found in /usr/local/lib/pkgconfig.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected .pc files:
    /usr/local/lib/pkgconfig/jack.pc

Warning: You have a non-Homebrew 'pkg-config' in your PATH:
  /opt/local/bin/pkg-config

`./configure` may have problems finding brew-installed packages using
this other pkg-config.

MacPorts管理下のフォルダはどけろ、と文句を言われる

$ sudo mv /opt/local ~/macports
$ brew doctor
Warning: Unbrewed .pc files were found in /usr/local/lib/pkgconfig.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected .pc files:
    /usr/local/lib/pkgconfig/_jack.pc

まだ文句を言われるので直す

$ cd /usr/local/lib/pkgconfig/
$ mv /usr/local/lib/pkgconfig/jack.pc ~/Temp/jack.pc

下準備

$ brew tap homebrew/dupes
$ brew tap homebrew/versions
$ brew tap homebrew/homebrew-php

https://github.com/Homebrew/homebrew-php
"Install Multiple Versions" を確認

Apache インストール

$ brew install httpd
To have launchd start httpd at login:
    ln -sfv /usr/local/opt/httpd/*.plist ~/Library/LaunchAgents
Then to load httpd now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.httpd.plist
==> Summary
🍺  /usr/local/Cellar/httpd/2.2.27: 1322 files, 21M, built in 102 seconds

PHP 5.5 インストール

$ brew options php55 # optionsを確認
$ brew install php55

エラー出て止まる。いろいろ文句を言われたので直す

$ mv ~/.pearrc ~/Temp/_.pearrc
$ brew doctor
Warning: /usr/bin occurs before /usr/local/bin
This means that system-provided programs will be used instead of those
provided by Homebrew. The following tools exist at both paths:

    apr-1-config
    apu-1-config
    phar
    phar.phar
    php
    php-config
    phpize

Consider setting your PATH so that /usr/local/bin
occurs before /usr/bin. Here is a one-liner:
    echo export PATH='/usr/local/bin:$PATH' >> ~/.bash_profile

Warning: Homebrew's sbin was not found in your PATH but you have installed
formulae that put executables in /usr/local/sbin.
Consider setting the PATH for example like so
    echo export PATH='/usr/local/sbin:$PATH' >> ~/.bash_profile

パスが通っていないぞ、と。

$ vim ~/.bash_profile

# 以下一行を追加
export PATH="/usr/local/bin:/usr/local/sbin:$PATH"

再度試す

$ brew install php55
==> Downloading http://www.php.net/get/php-5.5.11.tar.bz2/from/this/mirror
Already downloaded: /Library/Caches/Homebrew/php55-5.5.11
==> ./configure --prefix=/usr/local/Cellar/php55/5.5.11 --localstatedir=/usr/local/var --sysconfdir=
3. Apache was not built using --enable-so (the apxs usage page is displayed)

The output of /usr/sbin/apxs follows:
./configure: /usr/sbin/apxs: /usr/bin/perl: bad interpreter: No such file or directory
configure: error: Aborting

READ THIS: https://github.com/Homebrew/homebrew/wiki/troubleshooting
If reporting this issue please do so at (not Homebrew/homebrew):
  https://github.com/homebrew/homebrew-homebrew-php/issues

... まだダメ

$ brew search perl
perl-build   perl514      perl516      perl518      perlmagick
$ brew install perl518
$ cd /usr/local/bin
$ ln -s /usr/local/Cellar/perl518/5.18.2/bin/perl ./perl
$ cd /usr/bin
$ sudo ln -s /usr/local/Cellar/perl518/5.18.2/bin/perl ./perl

どうやら MacPorts のファイル群をどけた時に perl へのパスが切れていたらしい

$ brew install php55
...
To enable PHP in Apache add the following to httpd.conf and restart Apache:
    LoadModule php5_module    /usr/local/opt/php55/libexec/apache2/libphp5.so

The php.ini file can be found in:
    /usr/local/etc/php/5.5/php.ini

✩✩✩✩ PEAR ✩✩✩✩

If PEAR complains about permissions, 'fix' the default PEAR permissions and config:
    chmod -R ug+w /usr/local/Cellar/php55/5.5.11/lib/php
    pear config-set php_ini /usr/local/etc/php/5.5/php.ini

✩✩✩✩ Extensions ✩✩✩✩

If you are having issues with custom extension compiling, ensure that
you are using the brew version, by placing /usr/local/bin before /usr/sbin in your PATH:

      PATH="/usr/local/bin:$PATH"

PHP55 Extensions will always be compiled against this PHP. Please install them
using --without-homebrew-php to enable compiling against system PHP.

✩✩✩✩ PHP CLI ✩✩✩✩

If you wish to swap the PHP you use on the command line, you should add the following to ~/.bashrc,
~/.zshrc, ~/.profile or your shell's equivalent configuration file:

      export PATH="$(brew --prefix homebrew/php/php55)/bin:$PATH"

To have launchd start php55 at login:
    ln -sfv /usr/local/opt/php55/*.plist ~/Library/LaunchAgents
Then to load php55 now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.php55.plist
==> Summary
🍺  /usr/local/Cellar/php55/5.5.11: 492 files, 40M, built in 3.1 minutes

ようやくインストール成功

Xdebug インストール

$ brew install php55-xdebug
...
To finish installing xdebug for PHP 5.5:
  * /usr/local/etc/php/5.5/conf.d/ext-xdebug.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 xdebug 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 xdebug module.
  * - If you see it, you have been successful!
==> Summary
🍺  /usr/local/Cellar/php55-xdebug/2.2.4: 5 files, 248K, built in 9 seconds

一発で入る

APCu インストール

$ brew install php55-apcu
==> Installing php55-apcu dependency: pcre
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/pcre-8.35.mountain_lion.bottle.
######################################################################## 100.0%
==> Pouring pcre-8.35.mountain_lion.bottle.tar.gz
🍺  /usr/local/Cellar/pcre/8.35: 146 files, 5.8M
==> Installing php55-apcu
==> Downloading http://pecl.php.net/get/apcu-4.0.2.tgz
######################################################################## 100.0%
==> PHP_AUTOCONF="/usr/local/opt/autoconf/bin/autoconf" PHP_AUTOHEADER="/usr/local/opt/autoconf/bin/
==> ./configure --prefix=/usr/local/Cellar/php55-apcu/4.0.2 --with-php-config=/usr/local/Cellar/php5
==> make
==> Caveats
To finish installing apcu for PHP 5.5:
  * /usr/local/etc/php/5.5/conf.d/ext-apcu.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 apcu 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 apcu module.
  * - If you see it, you have been successful!
==> Summary
🍺  /usr/local/Cellar/php55-apcu/4.0.2: 6 files, 116K, built in 9 seconds

一発で入る

MySQL インストール

$ brew install mysql
==> Installing mysql dependency: openssl
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/openssl-1.0.1g.mountain_lion.bo
######################################################################## 100.0%
==> Pouring openssl-1.0.1g.mountain_lion.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/openssl/certs

and run
  /usr/local/opt/openssl/bin/c_rehash

This formula is keg-only, so it was not symlinked into /usr/local.

Mac OS X already provides this software and installing another version in
parallel can cause all kinds of trouble.

The OpenSSL provided by OS X is too old for some software.

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/openssl/lib
    CPPFLAGS: -I/usr/local/opt/openssl/include

==> Summary
🍺  /usr/local/Cellar/openssl/1.0.1g: 429 files, 15M
==> Installing mysql
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/mysql-5.6.17_1.mountain_lion.bo
######################################################################## 100.0%
==> Pouring mysql-5.6.17_1.mountain_lion.bottle.tar.gz
==> Caveats
A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.

To connect:
    mysql -uroot

To have launchd start mysql at login:
    ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
Then to load mysql now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
Or, if you don't want/need launchctl, you can just run:
    mysql.server start
==> /usr/local/Cellar/mysql/5.6.17_1/bin/mysql_install_db --verbose --user=naokis --basedir=/usr/loc
==> Summary
🍺  /usr/local/Cellar/mysql/5.6.17_1: 9510 files, 342M

$ mysql.server restart

これも問題なく入る

root ユーザーにパスワード設定

手順を忘れたのでこちらを参考に:
http://webkaru.net/mysql/mysql-root-password/

$ mysql -u root
mysql> update mysql.user set password=password('root用の任意パスワード') where user = 'root';
mysql> flush privileges;
mysql> exit;

$ mysql -u root -p
Enter password: 

httpdの設定

PHPが動作するように設定(VirtualHost の設定は省略)

$ sudo vim  /usr/local/etc/apache2/httpd.conf
---
# php5 のモジュールの追加
LoadModule php5_module /usr/local/opt/php55/libexec/apache2/libphp5.so

# IfModule mime_module 内
AddType application/x-httpd-php .php

# IfModule dir_module 内
DirectoryIndex index.php index.html
---
$ sudo httpd -k restart