mac下安装lnmp环境

参考
http://avnpc.com/pages/install-lnmp-on-osx

0.安装brew

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

1.安装PHP

brew tap homebrew/homebrew-php
brew install php56 --without-snmp --without-apache --with-debug --with-fpm --with-intl --with-homebrew-curl --with-homebrew-libxslt --with-homebrew-openssl --with-imap --with-mysql --with-tidy

如有错误configure: error: Cannot find libz
xcode-select –install

在~/.bashrc里加入:
export PATH=”/usr/local/bin:/usr/local/sbin:$PATH”

安装完成后,通过braw search php 查找相关的php扩展,再安装。不需要每次都重新安装编译php

安装laravel支持,及其他扩展

brew install mcrypt php56-mcrypt
brew install php56-mongo php56-redis

如果扩展报错可以重装,如

brew reinstall -v php56-redis --build-from-source

启动和停止php-fpm
php-fpm -D
killall php-fpm

2.安装nginx

brew install nginx

安装完毕后可以通过
nginx
nginx -s quit

调整下文件配置
mkdir -p /usr/local/var/logs/nginx
mkdir -p /usr/local/etc/nginx/sites-available
mkdir -p /usr/local/etc/nginx/sites-enabled
mkdir -p /usr/local/etc/nginx/conf.d
mkdir -p /usr/local/etc/nginx/ssl

配置文件
vim /usr/local/etc/nginx/nginx.conf

worker_processes  1;
error_log   /usr/local/var/logs/nginx/error.log debug;
pid        /usr/local/var/run/nginx.pid;

events {
    worker_connections  256;
    }


http {
        include       mime.types;
    default_type  application/octet-stream;

    log_format main '$remote_addr - $remote_user [$time_local] '
    '"$request" $status $body_bytes_sent '
    '"$http_referer" "$http_user_agent" '
    '"$http_x_forwarded_for" $host $request_time $upstream_response_time $scheme '
    '$cookie_evalogin';

    access_log  /usr/local/var/logs/access.log  main;

    sendfile        on;
    keepalive_timeout  65;
    port_in_redirect off;

    include /usr/local/etc/nginx/sites-enabled/*;
}

vim /usr/local/etc/nginx/conf.d/php-fpm

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

vim /usr/local/etc/nginx/sites-enabled/default

server {
    listen       8080;
    server_name  localhost;
    root     /Users/guoyuanjian/lnmp/test;

    location / {
    index  index.html index.htm index.php;
    include     /usr/local/etc/nginx/conf.d/php-fpm;
    }
}

3.安装MySQL

brew install mysql

启动
mysql.server start

设置密码
mysqladmin -uroot password ‘root’

4.Redis

brew install redis
Redis默认配置文件不允许以Deamon方式运行,因此需要先修改配置文件

vim /usr/local/etc/redis.conf
将daemonize修改为yes,然后载入配置文件即可实现后台进程启动

redis-server /usr/local/etc/redis.conf

5.安装mongodb

brew install mongodb
启动
mkdir -p /data/db
mongod
默认路径是/data/db,也可以指定路径
mongod –dbpath

通过配置文件启动
cat /data/db/mongo.conf

dbpath = /data/db
logpath = /data/db/mongo.log
fork = true
port = 27017
oplogSize = 4096

mongod -f /data/db/mongo.conf

6.设置别名

对所有服务的启动停止设置别名方便操作(这一步可不设置)
vim ~/.bash_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.php56.plist"
alias php-fpm.stop="launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.php56.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 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'
alias redis.start="launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mongo.plist"
alias redis.stop="launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mongo.plist"
alias redis.restart='redis.stop && redis.start'

7.其他

如要重新安装扩展
brew reinstall php56-imagick –build-from-source

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值