mac nginx mysql php_在 Mac 上搭建 Nginx PHP Mysql 开发环境

其实这个过程跟Linux下安装都差不多,只是部分命令有差别,大同小异。

网上看到很多教程都是用 brew 之类的包管理器安装,但是 Mac 自带了 php , 难道还要再装一个第三方的?强迫症果断不能忍,于是就想利用自带的 php-fpm 来搭建,没想到一搭建就是两个小时,在这里把过程整理一下备用,同时也方便需要的人。

因为是调试环境,所以没有注重安全方面,有些东西直接 chmod 777 了 要用于ws的话还是改改吧。

下载 nginx 源代码 并开始编译 tar zxvf nginx.tar.gz

cd 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_module

option, or install the PCRE library into the system, or build the PCRE library

statically from the source with nginx by using −−with−pcre= option.

Rewrite 需要 PCRE 库的支持 , 下载pcre库后进行编译安装 tar xvzf pcre.tar.gz

cd pcre-8.35

./configure

make

sudo make install

重新编译nginx cd ..

./configure

make

sudo 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.conf

sudo chmod 777 /private/etc/php-fpm.conf

sudo php-fpm

尝试启动报错: ERROR: failed to open error_log (/usr/var/log/php-fpm.log): No such file or directory (2)

找不到文件夹就新建 sudo mkdir /usr/var

sudo mkdir /usr/var/log

sudo php-fpm

此时PHP正常启动,不过还是需要完善一下 ,放置一下配置文件,修改一下权限,如果开公网访问的话“中奖”就杯具了,这种东西还是不要用 su 执行好一点。 cp /etc/php.ini.default /etc/php.ini

sudo chmod 777 /etc/php.ini

sudo killall php-fpm

php-fpm

此时PHP正常启动 有两个notice 可以不管他 NOTICE: [pool www] 'user' directive is ignored when FPM is not running as root

NOTICE: [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 了 tar zxvf mysql.tar.gz

cd mysql-*

mkdir /User/typcn/mysql

mv * /User/typcn/mysql/

cd /User/typcn/mysql

sudo 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/mysql

datadir = /path/to/mysql/data

port = 3306

server_id = 1

socket = /tmp/mysql.sock

user = _mysql

用脚本管理Mysql sudo ln -s /User/typcn/mysql/support-files/mysql.server /usr/local/bin/mysql

subl support-files/mysql.server

修改配置文件 basedir=/path/to/mysql

datadir=/path/to/data

mysqld_pid_file_path=/path/to/mysql.pid

好吧。我承认pid什么的放tmp是个坏习惯。 sudo mysql start

现在访问 localhost 试试吧

0818b9ca8b590ca3270a3433284dd417.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值