SierraにHomebrewでMySQL, Apache,PHPをインストール

Homebrew自体の準備

brew update
brew doctor

MySQL

brew install mysql
mysql_secure_installation
mysql.server start
//loginで開始するように設定
brew services start mysql

Apache

brew tap homebrew/dupes
brew tap homebrew/apache
//デフォルト8080で動作
brew install httpd24
//loginで開始するように設定
brew services start homebrew/apache/httpd24

PHP

brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/homebrew-php
//既存のPHPがあれば
brew unlink php55
//httpd.confに php7_module の行を追加
brew install php71 --with-httpd24

Apacheの設定
/usr/local/etc/apache2/2.4/httpd.conf

//設定済のはず
LoadModule php7_module /usr/local/opt/php71/libexec/apache2/libphp7.so
//修正する
ServerName localhost:8080
//index.phpを書き加える
DirectoryIndex index.php index.html
//コメント解除
Include /usr/local/etc/apache2/2.4/extra/httpd-vhosts.conf
LoadModule rewrite_module libexec/mod_rewrite.so
//末尾に追加
<FilesMatch .php$>
SetHandler application/x-httpd-php
</FilesMatch>

vhostの設定
/usr/local/etc/apache2/2.4/extra/httpd-vhosts.conf

<VirtualHost *:8080>
    ServerName localhost
    DocumentRoot "/usr/local/var/www/htdocs"
    <Directory "/usr/local/var/www/htdocs">
        AllowOverride All
        Require all granted
    </Directory>
    CustomLog "/usr/local/var/log/apache2/localhost.access.log" common 
    ErrorLog "/usr/local/var/log/apache2/localhost.error.log"
</VirtualHost>
 
<VirtualHost *:8080>
    ServerName SSS.dev
    DocumentRoot "XXX/public"
    <Directory "XXX/public">
        AllowOverride All
        Require all granted
    </Directory>
    CustomLog "/usr/local/var/log/apache2/SSS.dev.access.log" common 
    ErrorLog "/usr/local/var/log/apache2/SSS.dev.error.log"
</VirtualHost>

PHPの設定
/usr/local/etc/php/7.1/php.ini

date.timezone = Asia/Tokyo
default_charset = "UTF-8"
mbstring.language = Japanese
mbstring.internal_encoding = UTF-8
mbstring.detect_order = UTF-8,SJIS,EUC-JP,JIS,ASCII

その他、PHP開発用

brew install php71-xdebug

MySQLでグループ毎に連番をふる

targetのseq列に、group_idごとの連番をふります。
targetには主キーであるid列があるとします。

UPDATE target as t1
INNER JOIN 
 (
    SELECT tA.group_id, COUNT(tA.group_id) AS seq, tA.id AS dmyid
    FROM target as tA, target as tB
    WHERE tA.group_id = tB.group_id AND tA.id >= tB.id
    GROUP BY tA.group_id, tA.id
) as t2
ON t1.id = t2.dmyid
SET t1.seq = t2.seq;

Install MySQL on Yosemite

  • Yosemite 10.10.3
  • MySQL Community Server 5.6.24
  1. MySQL公式サイトから、Mac OS X ver. 10.9 (x86, 64-bit), DMG Archive をダウンロードして実行
  2. ~/.bash_profil を編集して、PATHに/usr/local/mysql/bin を追加
    export PATH=/usr/local/mysql/bin:$PATH
  3. パスワードの設定
    mysqladmin -u root password {new-password}
  4. sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

起動・停止は、システム環境設定のMySQLから可能。