其實這個過程跟Linux下安裝都差不多,只是部分命令有差別,大同小異。
網上看到很多教程都是用 brew 之類的包管理器安裝,但是 Mac 內建了 php , 難道還要再裝一個第三方的?強迫症果斷不能忍,於是就想利用內建的 php-fpm 來搭建,沒想到一搭建就是兩個小時,在這裡把過程整理一下備用,同時也方便需要的人。
因為是調試環境,所以沒有注重安全方面,有些東西直接 chmod 777 了 要用於ws的話還是改改吧。
下載 nginx 原始碼 並開始編譯
tar zxvf nginx.tar.gzcd nginx−1.7.4./configure
執行報錯:
./configure: error: the HTTP rewrite module requires the PCRE library.You can either disable the module by using −−without−http_rewrite_moduleoption, or install the PCRE library into the system, or build the PCRE librarystatically from the source with nginx by using −−with−pcre=<path> option.
Rewrite 需要 PCRE 庫的支援 , 下載pcre庫後進行編譯安裝
tar xvzf pcre.tar.gzcd pcre-8.35./configuremakesudo make install
重新編譯nginx
cd .../configuremakesudo make install
建立一個符號連結讓開關容易一些
sudo ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/nginx
有了 web 服務,接著嘗試啟動系統內建的php-fpm
php-fpm
執行報錯
ERROR: failed to open configuration file '/private/etc/php-fpm.conf': No such file or directory (2)
找不到設定檔,為了省事就直接把.default複製,然後賦予許可權
sudo cp /private/etc/php-fpm.conf.default /private/etc/php-fpm.confsudo chmod 777 /private/etc/php-fpm.confsudo php-fpm
嘗試啟動報錯:
ERROR: failed to open error_log (/usr/var/log/php-fpm.log): No such file or directory (2)
找不到檔案夾就建立
sudo mkdir /usr/varsudo mkdir /usr/var/logsudo php-fpm
此時PHP正常啟動,不過還是需要完善一下 ,放置一下設定檔,修改一下許可權,如果開公網訪問的話“中獎”就杯具了,這種東西還是不要用 su 執行好一點。
cp /etc/php.ini.default /etc/php.inisudo chmod 777 /etc/php.inisudo killall php-fpmphp-fpm
此時PHP正常啟動 有兩個notice 可以不管他
NOTICE: [pool www] 'user' directive is ignored when FPM is not running as rootNOTICE: [pool www] 'group' directive is ignored when FPM is not running as root
修改 nginx 設定檔 使其可以處理php
location ~ \.php$ { root /path/to/wwwroot; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME /path/to/wwwroot$fastcgi_script_name;}
啟動 nginx
sudo nginx
接下來就是 mysql 了
從官方下載 ( 下載DMG的話安裝更簡單的,可是我手賤下載了tar )http://dev.mysql.com/downloads/mysql/
tar zxvf mysql.tar.gzcd mysql-*mkdir /User/typcn/mysqlmv * /User/typcn/mysql/cd /User/typcn/mysqlsudo chown -R _mysql .#賦予許可權sudo chgrp -R _mysql . sudo scripts/mysql_install_db --user=_mysql --datadir=/User/typcn/mysql/data#執行安裝sudo chown -R root . sudo chown -R _mysql data subl my.cnf
編輯Mysql 設定檔
basedir = /path/to/mysqldatadir = /path/to/mysql/dataport = 3306 server_id = 1 socket = /tmp/mysql.sockuser = _mysql
用指令碼管理Mysql
sudo ln -s /User/typcn/mysql/support-files/mysql.server /usr/local/bin/mysqlsubl support-files/mysql.server
修改設定檔
basedir=/path/to/mysqldatadir=/path/to/datamysqld_pid_file_path=/path/to/mysql.pid
好吧。我承認pid什麼的放tmp是個壞習慣。
sudo mysql start
現在訪問 localhost 試試吧