本博主不小心删了brew 导致 用brew下载的lnmp系统没了坑.
brew 安装与卸载
安装方法
/usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”
卸载方法
/usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)”
注: 卸载brew会将brew所装的软件一起卸载
Homebrew安装PHP(new!)
以php7.2为例, 以前的安装方式是
brew install php72
而现在需要按照brew的统一包名称规范
brew install php@7.2
Mac PHP启动php-fpm问题解决
sudo vim /usr/local/etc/php/7.2/php-fpm.d/www.conf
编辑 www.conf,修改 listen 为 127.0.0.1:9999
开启php-fpm: sudo php-fpm -D
#启动成功
添加环境变量
export PATH="/usr/local/Cellar/php@7.2/7.2.13/bin: P A T H " e x p o r t P A T H = " / u s r / l o c a l / C e l l a r / p h p @ 7.2 / 7.2.13 / s b i n : PATH" export PATH="/usr/local/Cellar/php@7.2/7.2.13/sbin: PATH"exportPATH="/usr/local/Cellar/php@7.2/7.2.13/sbin:PATH"
安装工多版本php管理工具
brew install brew-php-switcher
安装工多版本php
brew install php@7.2
选择php7.2
brew-php-switcher 7.2
安装php扩展redis
由于php扩展被删除所以不能用brew安装
安装redis
brew install redis
使用
启动
redis-server
redis-cli
安装 php-redis 扩展
进入php官网下载redis扩展下载扩展
解压安装包
tar -xzvf redis-5.*.tgz
通过phpize生成编译configure配置文件
cd redis-4./
phpize
./configure --with-php-config=/usr/local/opt/php@7./bin/php-config
编译
make
make install
配置 php.ini文件
/usr/local/etc/php/7.2/php.ini
extension=“redis.so”
测试 访问 localhost/redis.php
//实例化redis对象
$redis = new redis();
//连接redis,第一个参数是redis服务的IP127.0.0.1是自己的,6379是端口号
$redis->connect(‘127.0.0.1’, 6379);
echo "Server is running: " . $redis->ping();
安装nginx
brew search nginx //查询要安装的软件是否存在
这里我们多执行一步“废”命令,不过有利于我们后面的配置:
brew info nginx
我们可以看到,nginx在本地还未安装(Not installed),nginx的来源(From),Docroot默认为/usr/local/var/www,在/usr/local/etc/nginx/nginx.conf配置文件中默认端口被配置为80从而使nginx运行时不需要加sudo,nginx将在/usr/local/etc/nginx/servers/目录中加载所有文件,以及我们可以通过最简单的命令 ‘nginx’ 来启动nginx。
正式开始安装:
brew install nginx
open /usr/local/Cellar/nginx //其实这个才是nginx被安装到的目录
访问验证:
localhost:80
成功 ok
403:
cd /usr/local/var/www/ //进入到www目录下
touch index.html //创建一个新的index.html文件
vim index.html //编辑该文件
Mac上启动nginx报错:nginx: [emerg] bind() to 0.0.0.0:80 failed (48: Address already in use)
原因:
80端口已被占用(可能因为未成功关闭一些服务,如nginx服务等)
解决:
sudo nginx -s stop(或者:sudo nginx -s quit),然后重新启动(sudo nginx).
当然,如果是因为其他服务占用了80端口,如Apache服务等,则把对应服务器关掉©.
Mac上启动nginx报错: nginx: [error] open() "/usr/local/nginx/logs/nginx.pid 并且执行 nginx: [error] open() "/usr/local/nginx/logs/nginx.pid 仍然报错
重新启动nginx后,出现报错,原因就是下没有nginx文件夹或没有nginx.pid文件,为什么会没有呢?
原因就是每次重新启动,系统都会自动删除文件,所以解决方式就是更改pid文件存储的位置,
sudo nginx -c /usr/local/etc/nginx/nginx.conf
#sudo /usr/local/Cellar/php70/7.0.25_17/sbin/php70-fpm restart
sudo nginx -s reload
打开nginx.conf配置文件
#user nobody;
worker_processes 1;
error_log logs/error.log;
error_log logs/error.log notice;
error_log logs/error.log info;
pid logs/nginx.pid;
将 pid 的#号打开
cd /usr/local/Cellar/nginx
mkdir logs
sudo chmod -R 777 logs
ssl on 已废弃 需要改成 listen … ssl
访问
localhost:80
成功 ok
mac下忘记mysql密码, 重新设置mysql密码
step1:
苹果->系统偏好设置->最下边点mysql 在弹出页面中 关闭mysql服务(点击stop mysql server)
step2:
进入终端输入:cd /usr/local/mysql/bin/
回车后 登录管理员权限 sudo su
回车后输入以下命令来禁止mysql验证功能 ./mysqld_safe --skip-grant-tables &
回车后mysql会自动重启(偏好设置中mysql的状态会变成running)
step3.
输入命令 ./mysql
回车后,输入命令 FLUSH PRIVILEGES;
回车后,输入命令 SET PASSWORD FOR ‘root’@‘localhost’ = PASSWORD(‘你的新密码’);
node切换版本之前的项目不能使用:
Node Sass could not find a binding for your current environment: Windows 32-bit with Node.js 6.x
Found bindings for the following environments:
- Windows 64-bit with Node.js 6.x
解决方案:
$ rm -rf node_modules
$ npm rebuild node-sass
$ npm install