LoginSignup
12
13

More than 5 years have passed since last update.

[Mac]Macでローカルサーバー環境構築(apache+php+mysql+phpmyadmin)

Last updated at Posted at 2016-02-18

OS X ElCapitanでの話。

apache起動

ターミナルで

sudo apachectl restart

http://localhost/
でIt worksが出ればok.

デフォルトでは、DocumentRootは
/Library/WebServer/Documents/
になる。

open /Library/WebServer/Documents/

などでFinderで確認できる。
ただ権限の問題で、そのままだとファイルの修正はやりづらい。

適宜virtualhost設定などで調整する。

/etc/apache2/extra/httpd-vhosts.conf
※/etc/apache2/httpd.conf

Include /private/etc/apache2/extra/httpd-vhosts.conf
のコメントアウト解除必要

ホストファイルいじる場合は、
http://qiita.com/kitanoow/items/35c1ebffd721f83ac7a0
このあたりで。

php読み込み

/etc/apache2/httpd.conf
#LoadModule php5_module libexec/apache2/libphp5.so
のコメントアウトを解除で。apache再起動

php -versionあたりでバージョンは確認。
(php ver 5.5.30が現在では確認できた)

Homebrewインストール(なければ)

インストールは、
http://brew.sh/index_ja.html
こちらよりコマンドがかいてあるので、それを実行。

mysqlのインストール・起動

brew update
brew install mysql

installした際のコメントの通り、
mysql.server startで起動

Starting MySQL
. SUCCESS!

で、起動OK

あとは、ユーザーの追加や設定など

my.cnfの位置は、
/usr/local/Cellar/mysql/5.7.11/mysql-test/std_data/mylogin-bad-cipher.cnf
/usr/local/Cellar/mysql/5.7.11/mysql-test/suite/federated/my.cnf
/usr/local/Cellar/mysql/5.7.11/mysql-test/suite/ndb/my.cnf
/usr/local/Cellar/mysql/5.7.11/mysql-test/suite/ndb_big/my.cnf
/usr/local/Cellar/mysql/5.7.11/mysql-test/suite/ndb_binlog/my.cnf
/usr/local/Cellar/mysql/5.7.11/mysql-test/suite/ndb_ddl/my.cnf
/usr/local/Cellar/mysql/5.7.11/mysql-test/suite/ndb_memcache/my.cnf
/usr/local/Cellar/mysql/5.7.11/mysql-test/suite/ndb_rpl/my.cnf
/usr/local/Cellar/mysql/5.7.11/mysql-test/suite/ndb_team/my.cnf
/usr/local/Cellar/mysql/5.7.11/mysql-test/suite/ndbcluster/my.cnf
/usr/local/Cellar/mysql/5.7.11/mysql-test/suite/rpl/extension/bhs/my.cnf
/usr/local/Cellar/mysql/5.7.11/mysql-test/suite/rpl/my.cnf
/usr/local/Cellar/mysql/5.7.11/mysql-test/suite/rpl_ndb/my.cnf
/usr/local/Cellar/mysql/5.7.11/support-files/my-default.cnf
※バージョンによって変わります。

編集しやすいように、
/usr/local/etc/my.cnf
あたりに適宜コピーしておく。

phpmyadmin

phpmyadmin一発は無理だったので。

brew tap homebrew/php/
brew install mhash

そのあとに、

brew install phpmyadmin

vhostsファイルに、

Alias /phpmyadmin /usr/local/share/phpmyadmin
<directory /usr/local/share/phpmyadmin/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    <ifmodule mod_authz_core.c>
        Require all granted
    </ifmodule>
    <ifmodule !mod_authz_core.c>
        Order allow,deny
        Allow from all
    </ifmodule>
</directory>

など記述。

接続で、”the local server's socket is not correctly configured”などで
こける場合は、php.iniで/tmp/mysql.sockの設定が必要かも。

謝辞 参考URL:
http://starzero.hatenablog.com/entry/2012/11/10/103047
http://qiita.com/hkusu/items/cda3e8461e7a46ecf25d
https://gist.github.com/gaspanik/3806983
https://soarcode.jp/posts/55

12
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
12
13