• 其实这个过程跟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 试试吧

    QQ20140903-3