参考
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