mac搭建PHP开发环境
在Mac系統上搭建Php服務器環境:
LAMP: Linux Apache MySQL PHP
MAMP: MACOS APACHE(自帶) MYSQL(需自己安裝) PHP(自帶)
一.APACHE 服務器軟件
存放網站目錄 MACOS默認自帶
啟動:sudo apachectl start
關閉:sudo apachectl stop
重啟:sudo apachectl restart
apache 配置文件:/etc/apache2/httpd.conf 修改Apache配置文件后需要重啟服務
開啟網站服務 進行測試
localhost
127.0.0.1
找到Documents(www)目錄,制作替身到桌面快捷方式
打開Finder 快捷鍵:Cmd+shift+g,輸入:/Library/WebServer,制作替身,直接拖拽到桌面
測試首頁 index.html index.htm index.php
修改默認首頁 index.html index.php /private/etc/apache2/httpd.conf
沒有權限修改,這時候要修改文件權限,執行命令 sudo chmod 0777 /Library/WebServe/Documents/
注意:默認順序是按照上面三個文件的順序,如果有index.html則該頁為首頁,沒有的話依次后推,可以自己試下。
二.開啟php解析引擎
在Apache配置文件中找到php進行開啟,具體步驟:
1.定位到/private/etc/apache2/httpd.conf文件,搜索“php”,
2.把配置文件中的相應行注釋去掉
LoadModule php5_module libexec/apache2/libphp5.so
3.修改后重啟Apache服務 sudo apachectl restart
4.測試PHP解析器是否成功開啟,修改index.php內容為
刷新頁面,顯示輸出php信息,成功。
如果此時出現403拒絕訪問提示,如:You don’t have permission to access / on this server.
解決方法為:定位到
1>.確保:
DocumentRoot "/Library/WebServer/Documents"
<Directory "/Library/WebServer/Documents">
這兩個路徑一致;
2>.修改權限為:
<Directory "/Library/WebServer/Documents">
Options Indexes FollowSymLinks
AllowOverride None
</Directory>
之間的#的沒有復制過來,那是被注掉的內容,留下這兩個即可,多余的注掉
兩個注意事項完成后,再次刷新,即可測試成功。
三.MySQL安裝,配置。
1.下載MySQL安裝包,這里用的是mysql-5.6.21-osx10.9-x86_64.dmg版本,點擊安裝;
如果安裝不成功,(在mac10.10系統以上可能會有這個問題),在第三步的時候自定義,把第三項勾掉(start item),即可安裝成功。
如果需要圖示,請參照網址http://coolestguidesontheplanet.com/get-apache-mysql-php-phpmyadmin-working-osx-10-10-yosemite/
2.配置終端使用mysql(數據庫操作命令)還有mysqladmin(數據庫設置密碼命令),類似于win系統上配置path路徑
命令如下:
sudo ln -s /usr//local/mysql-5.6.21-osx10.8-x86_64/bin/mysql /usr/bin/
sudo ln -s /usr/local/mysql-5.6.21-osx10.8-x86_64/bin/mysqladmin /usr/bin
3.打開系統偏好設置,會出現一個mysql圖標,點擊,然后start
4.終端設置數據庫密碼,指令如下:
mysqladmin -u root password root //這里把密碼設置成root方便記憶
然后登陸
mysql -u root -p
輸入密碼,登陸成功。
5.檢測數據庫
編輯index.php,內容如下:
提示成功,要寫本機127.0.0.1,不能用localhost
四.NaviCat桌面數據庫管理工具。
破解版安裝,注冊。這里用navicat101_premium_en.dmg
安裝成功后,選擇connect MySQL,輸入名稱,IP地址,密碼登陸成功,雙擊localhost,看到四個數據庫。
五.安裝phpmyadmin(web版數據庫管理工具)
1.下載,解壓,這里用的phpMyAdmin-4.2.9-all-languages.zip,修改文件夾名稱為phpmyadmin.放到www目錄下,刪除該目錄下其他文件。
2.修改配置文件:libraries/config.default.php
3.cmd+f,找到localhost,修改為127.0.0.1
找到AllowNoPassword,值改為true,為了能夠空密碼也能登陸。
4.刷新瀏覽器,用數據庫賬號密碼登陸。
5.點擊導入,導入phpadmin/examples/create_tables.sql(注意不是create_tables_drizzle.sql兩個不同,否則底部顯示phpMyAdmin高級功能尚未完全設置,部分功能未激活。本人導錯表后弄了好久才發現;導入正確后沒有錯誤),執行創建。創建出phpadmin數據庫,打開可見17張表。這些表用來管理phpadmin。
6.開啟這17張表功能。
找到samples/config.sample.inc.php文件
把如下18行代碼注釋取消,保存
$cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
$cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark';
$cfg['Servers'][$i]['relation'] = 'pma__relation';
$cfg['Servers'][$i]['table_info'] = 'pma__table_info';
$cfg['Servers'][$i]['table_coords'] = 'pma__table_coords';
$cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages';
$cfg['Servers'][$i]['column_info'] = 'pma__column_info';
$cfg['Servers'][$i]['history'] = 'pma__history';
$cfg['Servers'][$i]['table_uiprefs'] = 'pma__table_uiprefs';
$cfg['Servers'][$i]['tracking'] = 'pma__tracking';
$cfg['Servers'][$i]['designer_coords'] = 'pma__designer_coords';
$cfg['Servers'][$i]['userconfig'] = 'pma__userconfig';
$cfg['Servers'][$i]['recent'] = 'pma__recent';
$cfg['Servers'][$i]['favorite'] = 'pma__favorite';
$cfg['Servers'][$i]['users'] = 'pma__users';
$cfg['Servers'][$i]['usergroups'] = 'pma__usergroups';
$cfg['Servers'][$i]['navigationhiding'] = 'pma__navigationhiding';
$cfg['Servers'][$i]['savedsearches'] = 'pma__savedsearches';
拷貝一份到www目錄下,重命名為config.inc.php
然后刷新即可。
?
轉載于:https://www.cnblogs.com/fstack/p/4450874.html
總結
以上是生活随笔為你收集整理的mac搭建PHP开发环境的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: switch暗黑3怎么更新中文
- 下一篇: 支持 USB-C 充电三种容量可选,唯卓