Mac nginx php mysql redis

brewhome安装

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused

报错解决办法
修改hosts

sudo vim /etc/hosts

添加如下内容:

199.232.28.133 raw.githubusercontent.com

国内镜像

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

 

安装nginx

brew install nginx

就这一句命令,nginx就安装好了,不过我们还是需要配置下。

1.给nginx 设置管理员权限:如果不设置管理员权限,80端口是不能监听的

  #这里的目录根据你实际安装的目录来填写,默认是这个目录,不同的只是nginx的版本号而已

sudo chown root:wheel /usr/local/Cellar/nginx/1.10.1/bin/nginx
sudo chmod u+s /usr/local/Cellar/nginx/1.10.1/bin/nginx

2.加入launchctl启动控制

mkdir -p ~/Library/LaunchAgents
cp /usr/local/opt/nginx/homebrew.mxcl.nginx.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist

到这里,nginx基本上是完工了

运行nginx :

sudo nginx #打开 nginx
nginx -s reload|reopen|stop|quit #重新加载配置|重启|停止|退出 nginx
nginx -t #测试配置是否有语法错误

nginx配置

/usr/local/etc/nginx/nginx.conf

1.找到 server 的 location 配置,给 index 加一个 index.php

location / {
  root  html;
  index index.html index.htm index.php;
}


2.访问 index.php 报 File not found. 找到server 下被注释的 location ~.php$(删除代码前面的 ‘#')

location ~ \.php$ {
  root      html;
  fastcgi_pass  127.0.0.1:9000;
  fastcgi_index index.php;
  fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  include    fastcgi_params;
}

且更改

fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;

为:

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

配置.conf

/usr/local/etc/nginx/servers

server{
 listen      80;
 server_name dev.com;
 root /Users/;
 location / {
     try_files $uri $uri/ /index.php?$query_string;
        index index.php index.html;
 }
 location ~ \.php(.*)$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
 }
}

/etc/hosts

127.0.0.1       dev.com

然后重启nginx:
 

sudo nginx -s reload //重载配置文件
sudo nginx -s stop //停止nginx服务
sudo nginx //开启nginx服务

 

安装MySql

brew install mysql

也是一句命令搞定,等执行完后,mysql也安装完毕,接下来就是对mysql的一些配置

1.先cd到mysql的目录中:

cd /usr/local/opt/mysql/

2.加入launchctl启动控制

mkdir -p ~/Library/LaunchAgents/
cp /usr/local/opt/mysql/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
#取消启动
#launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

3.执行安全设置脚本,设置root账号密码,如果不执行这一步,是无法用mysql -u root -p这个命令登录mysql的,网上很多教程就是没有这个说明,所以这里特别强调下:

./bin/mysql_secure_installation

执行上面的命令后,会进入mysql的配置,具体步骤就不写了,每一个选项都有说明是干什么的,等这个命令执行完毕后,你就可以用 mysql -u root -p 来登录mysql 了。

 

安装PHP

寻找php-fpm的路径

whereis php-fpm

如果找不到,可以尝试使用:

find / -name php-fpm

一般默认的路径就是:

/usr/sbin/php-fpm

修改php-fpm.conf配置文件

默认位置是:

/private/etc/php-fpm.conf

如果不存在的话,就看看是不是存在

/private/etc/php-fpm.conf.default

然后 COPY 一份:

sudo cp /private/etc/php-fpm.conf.default /private/etc/php-fpm.conf

修改php-fpm的配置文件的项目『daemonize』

daemonize = yes

把前面的分号去掉。

加入启动项

在~/Library/LaunchAgents目录,新建 org.php.php-fpm.plist 文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>php-fpm</string>
    <key>Program</key>
    <string>/usr/sbin/php-fpm</string>
    <key>KeepAlive</key><true/>
</dict>
</plist>

注意:xml文件中的php-fpm的路径,是通过上面的命令得到的。

sudo chown root:owner ~/Library/LaunchAgents/org.php.php-fpm.plist
sudo chmod +x ~/Library/LaunchAgents/org.php.php-fpm.plist
launchctl load -w ~/Library/LaunchAgents/org.php.php-fpm.plist

执行完以上命令,需要重新启动,看是否生效。

当重启不生效的死活,可以用这个调试命令,来看看是否加载了启动项:

launchctl list | grep php

关于上述启动文件的目录,/Library/LaunchAgents,还有个关联位置:/Library/LaunchDaemons/。当没有生效的时候,可以查看一下这个plist文件,不如换个位置试试。mac系统中,有几个类似的位置,功效是不同的。在本例中,建议大家使用~/Library/LaunchAgents/。

 

重启php-fpm

查看php-fpm端口是否在被php-fpm使用

sudo lsof -i:9000

一般修改 php.ini 文件后经常需要重启php-fpm

sudo  killall  php-fpm   // 关闭

再输入 sudo lsof -i:9000 就会发现php-fpm没有打印对应端口

sudo  php-fpm    // 重启

 

安装redis

一、安装

brew install redis

二、常用命令

1.启动redis服务

brew services start redis

2.关闭redis服务

brew services stop redis

3.重启redis服务

brew services restart redis

4.打开图形化界面

redis-cli

  redis-cli --raw  # 解决中文乱码

5.开机启动redis命令

ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents

6.使用配置文件启动redis-server

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

7.停止redis服务

redis-cli shutdown

8. redis配置文件位置

/usr/local/etc/redis.conf

9.卸载redis

brew uninstall redis rm ~/Library/LaunchAgents/homebrew.mxcl.redis.plist

再安装phpredis

官网下载redis扩展

http://pecl.php.net/
wget http://pecl.php.net/get/redis-5.3.1.tgz

解压包

tar -xzvf redis-5.3.1.tgz
sudo mv redis-5.3.1 phpredis
cd phpredis
sudo phpize
./configure
make
make install
extension="redis.so"

使用php -m查看是否有redis模块
 

重启php-fpm

sudo  killall  php-fpm
sudo  php-fpm

测试redis是否开启成功

<?php

$redis = new redis();

$redis->connect('127.0.0.1', 6379);
$redis->set('test', "hello world");
$result = $redis->get('test');
print_r($result);

 

➜  swoole sudo make install
Password:
Installing shared extensions:     /usr/lib/php/extensions/no-debug-non-zts-20180731/
cp: /usr/lib/php/extensions/no-debug-non-zts-20180731/#INST@21401#: Read-only file system
make: *** [install-modules] Error 1

如果遇到以上报错
需要先关闭 mac系统有保护机制

//查看保护机制状态
$ csrutil status
System Integrity Protection status: disabled.	//关闭状态
$ sudo mount -o rw /	   (临时读写)
$ sudo make install

齐活了您嘞!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值