你成功了,他妒嫉你;你失败了,他笑话你 [登录·注册]

吕滔博客

首页 开发 运维 工具 摄影

macOS下安装nginx+php+memcached+redis+mysql+yaf扩展环境教程

环境配置 memory发布于April 12, 2017 标签: PHP, MySQL, mac, redis, Memcached, Yaf

macOS 10.12.4
直接上命令,不多说了。
下载并安装各软件包均通过 Homebrew,因此,安装之前,需在 Mac 上下载并安装  Homebrew,在 CLI 中通过下面的命令可以完成:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

怎么用brew不是这篇文章介绍的。我们直接说我本地的配置过程

这里安装默认的 Nginx:

brew install nginx

新版的macOS默认没了Launch目录,创建个

mkdir -p ~/Library/LaunchAgents

添加 Nginx 至开机启动:

ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents

设置nginx的执行文件权限,这样就可以80端口运行了

sudo chown root:wheel /usr/local/Cellar/nginx/1.10.0/bin/nginx
sudo chmod u+s  /usr/local/Cellar/nginx/1.10.0/bin/nginx
sudo chown -R $USER /usr/local/var/log/nginx/

Nginx安装完成,开启和停止服务的命令:

sudo nginx         # Start
sudo nginx -s stop # stop

安装PHP

brew search php

我这儿安装php71 也就最新的7.1版本

brew install --without-apache --with-fpm --with-mysql php71

安装相关扩展(我自己用的,你们需要其它的自行查看对应的扩展名)

brew install php71-xdebug php71-memcached php71-swoole php71-redis php71-pdo-pgsql php71-mcrypt 

添加进开机启动

ln -sfv /usr/local/opt/php71/homebrew.mxcl.php71.plist ~/Library/LaunchAgents/
ln -sfv /usr/local/Cellar/memcached/1.4.36/homebrew.mxcl.memcached.plist  ~/Library/LaunchAgents/

yaf扩展安装
在https://github.com/laruence/yaf下载最新的源码安装包并解压

unzip yaf-master.zip
cd yaf-master

找到我们的php的bin目录

echo $(brew --prefix homebrew/php/php71)

安装autoconf,否则会报错 Cannot find autoconf. Please check your autoconf installation and the

brew install autoconf

执行安装

/usr/local/opt/php71/bin/phpize
./configure --with-php-config=/usr/local/opt/php71/bin/php-config
make && make install

完事后会提示你扩展目录,像我的是

/usr/local/Cellar/php71/7.1.3_15/lib/php/extensions/no-debug-non-zts-20160303/

打开/usr/local/etc/php/7.1/conf.d目录,复制个ini文件,重命名ext-yaf.ini
内容改为

[yaf]
extension="/usr/local/Cellar/php71/7.1.3_15/lib/php/extensions/no-debug-non-zts-20160303/yaf.so"

mysql安装

brew install mysql

安装完了会有一些提示,默认密码为空,启动命令

mysql.server start

添加开机启动

ln -sfv /usr/local/opt/mysql/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/

启动mysql,然后初始化

mysql_secure_installation

会依次出现下面的各种提示

New password:                   //给root账号设置一个新密码. 输入密码后回车

Re-enter new password:      //确认刚才的密码

Remove anonymous users? (Press y|Y for Yes, any other key for No) :    //是否删除匿名账号
Success.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) :   //禁止远程登录

Remove test database and access to it? (Press y|Y for Yes, any other key for No) :  //删除test数据库

Reload privilege tables now? (Press y|Y for Yes, any other key for No) :  //立即刷新数据库权限,也就是刚才的设置立即生效

用你的mysql工具连接一下,我个人推荐sequel pro

安装redis

brew install redis

完成了会提示你

brew services start redis //启动命令
redis-server /usr/local/etc/redis.conf //配置等信息

开机启动

ln -sfv /usr/local/Cellar/redis/3.2.8/homebrew.mxcl.redis.plist ~/Library/LaunchAgents/

配置环境

source ~/.profile
alias nginx.start='launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist'
alias nginx.stop='launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist'
alias nginx.restart='nginx.stop && nginx.start'
alias php-fpm.start="launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php71.plist"
alias php-fpm.stop="launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.php71.plist"
alias php-fpm.restart='php-fpm.stop && php-fpm.start'
alias mysql.start="launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist"
alias mysql.stop="launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist"
alias mysql.restart='mysql.stop && mysql.start'
alias memcached.start="launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist"
alias memcached.stop="launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist"
alias memcached.restart='memcached.stop && memcached.start'
alias redis.start="launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.redis.plist"
alias redis.stop="launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.redis.plist"
alias redis.restart='redis.stop && redis.start'

改下nginx的相关配置

vi /usr/local/etc/nginx/nginx.conf

内容大致如下

worker_processes  8;
events {
    worker_connections  1024000;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    client_max_body_size 2000M;
    include servers/*;
}

然后是建个php-fpm文件

location ~ \.php$ {
    try_files    $uri = 404;
    fastcgi_pass    127.0.0.1:9000;
    fastcgi_index    index.php;
    fastcgi_intercept_errors  on;
    include fastcgi.conf;
}

进servers目录下建个默认站点default.conf

server {
    listen       80;
    server_name  _;
    root         /usr/local/var/www/;
    access_log  off;
    location / {
        index  index.html index.htm index.php;
        autoindex   on;
        include     php-fpm;
    }
}

完事了重启一下机器 ... 收工

相关推荐

添加新评论

网站状态

  • 栏目分类:35个
  • 发布文章:1106篇
  • 用户评论:608条

最新回复

  • memory: php64位? 这个我还真没有注意。。。回头再试试
  • Kngstr: 这个很简单,你用的PHP不是64位的,64位的dll只能在64位...
  • memory: 使用的是typecho.
  • GavinHsueh: 您好,我了解下您的博客是自己开发的么?看着很不错
  • 个人博客: 看看先
  • memory: 谢谢,已修正。
  • jrotty: 方法一中next后面少个'符号
  • daxia: mark
  • 企业孵化器: 厉害了
  • Bearox: 我也遇到了同样的问题,yum install dev86* 没用...
  • themebetter: 优化方法很不错。
  • 架构之路: 总结和nice,网站速度很快。
  • 架构之路: 总结的很好,简单、完整、高效。
  • memory: 我正在犹豫要不要更新了~~~ 因为1.2撇弃了php5.2,最低...
  • 灵九哲: medoo已经更新到v1.2了,博主更新下中文版网站内容
  • 灵九哲: medoo已经更新了v1.2,麻烦博主更新下中文版的网站,然后把...
  • memory: 用的typecho.
  • einsan: 涛哥,你的博客后端是自己开发的吗?还是使用哪一款开源产品?
  • yfly962464: 不行啊
  • memory: 哥们儿~非常不好意思,之前有段时间折腾jpress,后来就没有玩...