OS X內建Apache+PHP的環境,因此只需設定就好。
1. 啟動apache
啟用/停用/重啟apache
sudo apachectl start sudo apachectl stop sudo apachectl restart
#查看apache的version
httpd -v
2. 根目錄及Root設定
確定apache可以正常運作後,可以開始設定root的部份
系統root目錄:/Library/WebServer/Documents/
user的根目錄:~/Sites
~/Sites是自己設定的,設定檔位於/etc/apache2/users/febr.conf,建立存檔後記得改權限並重啟apache
sudo vi /etc/apache2/users/febr.conf sudo chmod 755 /etc/apache2/users/febr.conf sudo apachectl restart
建立個網頁於~/Sites底下,開啟browser,http://localhost/~febr/試試是否正常運作
3.啟動php
sudo vi /etc/apache2/httpd.conf
找到這一行,將註解取消並重啟apache:
LoadModule php5_module libexec/apache2/libphp5.so
試試phpinfo()是否正常運作
4. 安裝MySQL
安裝並啟動
brew install mysql mysql.server start
如果要讓mac每次開機都自動執行mysql:
mkdir -p ~/Library/LaunchAgents ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
Fix Error:
sudo chmod -R 755 /usr/local/var/mysql rm -Rf /usr/local/var/mysql/Your-Machine-Name.local.err
Securing MySQL installation:
mysql_secure_installation Set root password? [Y/n] Y Remove anonymous users? [Y/n] Y Disallow root login remotely? [Y/n] Y Remove test database and access to it? [Y/n] Y Reload privilege tables now? [Y/n] Y
若是需要移除,照下列指令移除乾淨:
brew remove mysql brew cleanup launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist rm -Rf ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
5. phpmyadmin
安裝:
brew install phpmyadmin
接著設定/etc/apache2/httpd.conf,將此段加入:
Alias /phpmyadmin /usr/local/share/phpmyadminOptions Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny Allow from all
phpmyadmin設定檔目錄:
cd /usr/local/Cellar/phpmyadmin/版號/share/phpmyadmin
cp config.sample.inc.php config.inc.php
若登入失敗並出現#2002 Cannot log in to the MySQL server
將
$cfg['Servers'][$i]['host'] = 'localhost';
更改為
$cfg['Servers'][$i]['host'] = '127.0.0.1';
重開apache後,就可以看到localhost/phpmyadmin畫面了