MacでPHPの実行環境構築メモ
OS情報
事前準備
- Homebrew
- PhpStorm
PHPのリポジトリを追加する
$ brew tap homebrew/php
PHP5.5とデバッグツールのインストール
$ brew install homebrew/php/php55 $ brew install homebrew/php/php55-xdebug $ vim /usr/local/etc/php/5.5/php.ini date.timezone = 'Asia/Tokyo' とする
- xdebugについてはこちらを参考
環境確認
$ brew doctor
- ここで"Warning"が出た場合は、メッセージに沿って修正する
MySQLのインストール
- インストール
$ brew install mysql
- 起動
$ mysql.server start
- rootユーザーのパスワード設定
$ mysql -uroot mysql> set password for root@localhost=password('rootユーザーのパスワード'); mysql> exit
- MySQL のセキュリティ設定
$ mysql_secure_installation
Using existing password for root. Change the password for root ? ((Press y|Y for Yes, any other key for No) : n ... skipping. By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y Success. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y - Dropping test database... Success. - Removing privileges on test database... Success. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y Success. All done!
phpMyAdminのインストール
- インストール
$brew install phpmyadmin
- apacheの設定
$ sudo vim /etc/apache2/httpd.conf
LoadModule php5_module libexec/apache2/libphp5.so <= コメントを外す ~~~ <IfModule dir_module> DirectoryIndex index.html index.php </IfModule> <IfModule mine_module> AddType application/x-httpd-php .php </IfModule> ~~~ 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> ~~~
- config.inc.phpの修正
$ vim /usr/local/Cellar/phpmyadmin/4.6.4/share/phpmyadmin/config.inc.php
"localhost"を"127.0.0.1"に修正する
$cfg['Servers'][$i]['host'] = '127.0.0.1';
- phpMyAdminの起動確認
PhpStormの設定
- PhpStorm > Preferences > Languages & Frameworks > PHP
参考
その他
Warning: homebrew/php/php53: --homebrew-apxs was deprecated; using --with-homebrew-apxs instead!
Warning: homebrew/php/php53: --with-homebrew-apxs was deprecated; using --with-apache instead!
- "--with-homebrew-apxs"を指定すると、Apacheのhttpd.confに下記が自動で追記される
- --