mac下主要用 brew
安装lnmp
M2的2.3.x
版本不支持php7.0
了,我们需要安装到7.1
或者7.2
。
环境如下:
php 7.1
mysql 5.7
nginx 1.12
升级brew
brew update
brew upgrade
配置源
brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/homebrew-php
安装php7.1
先搜索下brew里面有哪些php版本
brew search php
再安装
brew install php71
配置文件在php.ini
在/usr/local/etc/php/7.1/php.ini
php-fpm.conf
在 /usr/local/etc/php/7.1/php-fpm.conf
修改下php-fpm.conf
把
;pid = run/php-fpm.pid
;error_log = log/php-fpm.log
前面的分号去掉,也就是说开启这2个选项
加入开机启动
mkdir -p ~/Library/LaunchAgents
ln -sfv /usr/local/opt/php71/homebrew.mxcl.php71.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php71.plist
将php加入$PATHvim ~/.bash_profile
添加
export PATH="/usr/local/sbin:$PATH"
export PATH="$(brew --prefix php71)/bin:$PATH"
export PATH="$(brew --prefix php71)/sbin:$PATH"
export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
保存退出,运行配置source ~/.bash_profile
查看是否安装成功lsof -Pni4 | grep LISTEN | grep php
显示如下代码代表安装成功
php-fpm 89546 zouhongzhaoo 8u IPv4 0x5dd373a3ef143b3 0t0 TCP 127.0.0.1:9000 (LISTEN)
php-fpm 89547 zouhongzhaoo 0u IPv4 0x5dd373a3ef143b3 0t0 TCP 127.0.0.1:9000 (LISTEN)
php-fpm 89548 zouhongzhaoo 0u IPv4 0x5dd373a3ef143b3 0t0 TCP 127.0.0.1:9000 (LISTEN)
安装php扩展
brew install php71-mcrypt
php71-amqp
php71-apcu
php71-apcu-bc
php71-ast
php71-blitz
php71-couchbase
php71-ev
php71-event
php71-gearman
php71-geoip
php71-geos
php71-gmagick
php71-gmp
php71-grpc
php71-hprose
php71-http
php71-imagick
php71-intl
php71-lua
php71-lz4
php71-lzf
php71-mailparse
php71-maxminddb
php71-mecab
php71-meminfo
php71-molten
php71-mosquitto
php71-msgpack
php71-mustache
php71-oauth
php71-opcache
php71-snmp
php71-ssh2
php71-stats
php71-swoole
php71-yac
php71-yaml
php71-memcached
php71-redis
php71-xdebug
安装nginx
brew install nginx
通过homebrew,nginx文件默认被安装在/usr/local/etc/nginx/nginx.conf
,然后再浏览器中键入http://localhost:8080, 即可访问到nginx的欢迎界面。
配置文件在vim /usr/local/etc/nginx/nginx.conf
log文件在/usr/local/Cellar/nginx/1.12.2_1/logs/error.log
多站点默认设置在 /usr/local/etc/nginx/servers/
下面
如果nginx.conf
没定义的话,就在http里加一条include servers/*
;
比如vim /usr/local/etc/nginx/servers/default
server {
listen 80;
root /var/www/admin/public; #项目文件地址
index index.php index.html index.htm;
server_name b.com; #本地域名,可以在host里定义
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
重启nginx,让配置生效nginx -s reload
加入开机启动
ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
安装mysql
brew install mysql
开机启动
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
然后进行MySQL的安全安装,使用以下命令,可以更改root密码、删除匿名用户、关闭远程连接等:mysql_secure_installation
> Enter current password for root (enter for none): //默认没有密码,直接回车即可
> Change the root password? [Y/n] //是否更改root密码,选择是,然后输入并确认密码
> Remove anonymous users? [Y/n] //是否删除匿名用户,选择是
> Disallow root login remotely? [Y/n] //是否禁止远程登录,选择是
> Remove test database and access to it? [Y/n] //是否删除test数据库,选择是
> Reload privilege tables now? [Y/n] //是否重载表格数据,选择是
测试数据库是否安装成功:mysql -u root -p
mysql的socket在/tmp/mysql.sock
重启mysql:
brew services restart mysql
或者
mysql.server start
php-fpm的一些管理
1,测试php-fpm配置
php-fpm -t
2,启动php-fpm
php-fpm -D
3,关闭php-fpm
kill -INT `cat /usr/local/var/run/php-fpm.pid`
4,重启php-fpm
kill -USR2 `cat /usr/local/var/run/php-fpm.pid`
5,也可以用上文提到的brew命令来管理php-fpm
brew services start|stop|restart php-fpm
6,还可以用这个命令来管理php-fpm
php-fpm start|stop|restart
nginx相关命令
1,测试配置是否有语法错误
nginx -t
2,打开 nginx
sudo nginx
3,重新加载配置|重启|停止|退出 nginx
nginx -s reload|reopen|stop|quit
4,也可以使用Mac的launchctl来启动|停止
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
其他
其他的比如Magento安装和配置Nginx虚拟主机,直接参考上面的:
配置Nginx虚拟主机
安装和配置Magento2
这里就不再赘述了。基本操作都是一样式的。只是配置文件目录有可能不一样而已。
一些常见错误
#1,nginx: [error] invalid PID number "" in "/usr/local/var/run/nginx/nginx.pid"
解决办法:
$ sudo nginx -c /usr/local/etc/nginx/nginx.conf
$ sudo nginx -s reload
#2,Nginx stat() failed (13: Permission Denied) 并且404
检测下权限,比如/var/www/test项目。
检测/var和www的权限 一般设为755就行