MAC搭建LNMP环境
2016-02-16 17:28
393 查看
1、安装brew
:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"[/code]
这样就直接安装完成了,安装出现问题请查看brew官方说明,不知道brew请弃用Mac;
移除已安装的程序:sudo brew remove XXXX
彻底卸载需要以下命令:sudo brew cleanup sudo rm -rf ~/Library/LaunchAgents/xxx.plist
如果是卸载MySQL,则需要使用命令:sudo rm -rf /usr/local/var/mysql2、安装
查看MySQL:MySQL可用版本信息:brew info mysql
我这边看到的版本是5.7.10:mysql: stable 5.7.10 (bottled)
接下来安装MySQL5.7.10:brew install mysql
安装完成之后按照提示将plist文件放入~/Library/LaunchAgents/中并load,设定MySQL开机启动:ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
启动MySQL:mysql.server start
启动之后由于MySQL默认没有设置密码,所以要设置root的密码:mysql -uroot -p
提示输入密码的时候直接按回车就登录了,登录MySQL后提示如下:Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.10 Homebrew
接下来设置root的密码:ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
设置密码的时候最好设置一个强密码,关于强密码的规则,官方有如下说明:Note MySQL's validate_password plugin is installed by default. This will require that passwords contain at least one upper case letter, one lower case letter, one digit, and one special character, and that the total password length is at least 8 characters.
为了方便使用,我们经常会创建任意连接的root用户:GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'MyNewPass4!' WITH GRANT OPTION;
刷新权限使命令生效:flush privileges;
退出MySQL:exit;3、安装
首先加入PHP:brew的几个官方源:brew tap homebrew/dupes brew tap homebrew/versions brew tap homebrew/php
然后查看版本库中php的版本信息,我要安装php5.6,所以直接查看php56具体的版本信息:brew info php56
结果显示的是5.6.17:homebrew/php/php56: stable 5.6.17 (bottled), HEAD PHP Version 5.6
下面开始安装php5.6:
PHP如果采用默认配置安装,会编译mod_php模块并只运行在Apache环境下,为了使用Nginx,这里需要编译php-fpm并且禁用apache,主要通过参数--without-fpm --without-apache来实现。完整的安装指令为brew install php56 --with-fpm --with-enchant --with-gmp --with-homebrew-curl --with-homebrew-libressl --with-homebrew-libxml2 --with-homebrew-libxslt --with-imap --with-libmysql --with-mssql --with-pear --with-phpdbg --with-postgresql --without-apache --with-bz2 --with-ldap --with-legacy-mysql --with-mysql --with-pcntl
安装完成之后将php路径加入PATH,由于我的mac使用的是zsh,所以我这里修改zshrc:sudo vi ~/.zshrc
在里面添加如下内容:#php5.6 export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
保存之后引入刚才的path:source ~/.zshrc
加入launchctl启动控制:mkdir -p ~/Library/LaunchAgents cp /usr/local/opt/php56/homebrew.mxcl.php56.plist ~/Library/LaunchAgents/ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php56.plist
php.ini、fpm.conf配置的路径如下:/usr/local/etc/php/5.6/php.ini /usr/local/etc/php/5.6/php-fpm.conf
将配置文件放在/etc/下:sudo ln -s /usr/local/etc/php/5.6/php.ini /etc/php.ini sudo ln -s /usr/local/etc/php/5.6/php-fpm.conf /etc/php-fpm.conf
接下来安装php5.6的扩展,首先查找版本库中php5.6可用的扩展:brew search php56
找到扩展之后开始安装所需扩展:brew install php56-gearman php56-imagick php56-msgpack php56-opcache php56-phalcon php56-redis php56-xdebug php56-swoole php56-yac php56-yaf php56-yar php56-oauth
安装完成之后一些需要启动的服务如下:
gearman启动:ln -sfv /usr/local/opt/gearman/*.plist ~/Library/LaunchAgents gearmand -d
安装完扩展之后,有些扩展需要有服务端支持,redis等,那就需要先安装服务端,具体如何安装使用,自行查找;4、安装
nginx:brew install nginx
安装完成的nginx,默认的root路径如下:Docroot is: /usr/local/var/www
nginx的配置文件目录如下:/usr/local/etc/nginx/nginx.conf
nginx虚拟站点目录如下:nginx will load all files in /usr/local/etc/nginx/servers/.
开机启动nginx:ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents
nginx监听80端口是需要root权限的:sudo chown root:wheel /usr/local/Cellar/nginx/1.8.1/bin/nginx sudo chmod u+s /usr/local/Cellar/nginx/1.8.1/bin/nginx①、先将nginx的配置文件放至
/etc下:sudo ln -s /usr/local/etc/nginx/nginx.conf /etc sudo ln -s /usr/local/etc/nginx/servers /etc/nginxservers②、修改nginx监听端口:
sudo vi /etc/nginx.conf
修改配置文件如下:#user nobody; worker_processes 1; #error_log /usrlogs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; pid /usr/local/var/run/nginx.pid; events { worker_connections 1024; } 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"'; #access_log logs/access.log main; port_in_redirect off; sendfile on; tcp_nopush on; keepalive_timeout 65; gzip on; include servers/*.conf; }
然后在/etc/nginxservers/下创建default.conf,编辑default.conf,加入以下内容:server { listen 80; server_name localhost; #charset koi8-r; root html; index index.php index.html index.htm; # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_intercept_errors on; include /usr/local/etc/nginx/fastcgi.conf; } access_log /usr/local/var/log/local.access.log main; error_log /usr/local/var/log/local.error.log info; #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} }
修改完配置,重启nginx和php-fpm。
相关文章推荐
- 2015年总结和2016年的计划
- 如何生成二维码
- 关于茅台
- pcie posted/non-posted request
- theano学习指南5(翻译)- 降噪自动编码器
- MAC地址飘移查看及解决方法 一般是网络中存在环路
- 安装ubuntu双系统时手动设置分区大小
- 设计模式(9)--Proxy代理模式
- windows php-redis 扩展安装
- Multilayer Feedforward Networks are Universal Approximators
- Android的存储系统—Vold与MountService分析(一)
- SAX解析器
- 深入理解PHP内核(六)函数的定义、传参及返回值
- __stdcall、__cdecl和__fastcall区别
- 设计模式之简单工厂模式
- 字符串匹配的KMP算法(简单清晰的认识KMP)
- 2016目标
- CentOS 7 安装配置 NFS
- 感情整理
- Android驱动使用JNI调用