Mac下安装lnmp

安装mysql5.6

brew seach mysql
brew install [email protected]
#安装成功之后 启动mysql
brew services start [email protected]
#因为我用的是 zsh所以需要
 echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshrc
 source ~/.zshrc
#进入mysql  密码为空,直接回车就行 
mysql -uroot -p 
#修改密码
SET PASSWORD = PASSWORD('123456');

安装nginx

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

安装php

brew search php
brew install [email protected]
#(我的是zsh shell)
 echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshrc   
source ~/.zshrc
#启动[email protected] php-fpm 
brew services start [email protected]
#直接用php-fpm启动的方法
cd /usr/local/etc/php/7.1
sudo cp php-fpm.conf /private/etc
sudo mkdir -p /usr/var/log
sudo touch  /usr/var/log/php-fpm.log

修改nginx配置 是其能运行php

vim /usr/local/etc/nginx/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;
events {
     
    worker_connections  1024;
}
http {
     
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;
    server {
     
        listen       80;
        server_name  localhost;
        location / {
     
            root   html;
            index  index.html index.htm index.php; #加入index.php
        }
        location ~ \.php$ {
       #修改变量
         root html;
         fastcgi_pass 127.0.0.1:9000;
         fastcgi_index index.php;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
         include fastcgi_params;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
     
            root   html;
        }
    }
    include servers/*;
}


#重启nginx
sudo nginx 
#创建php文件
touch  /usr/local/var/www/index.php
echo " ?>  >>index.php
#浏览器打开127.0.0.1/index.php

配置虚拟域名

#创建目录 (注意权限分配,我这已经是分配过的了)
sudo mkdir /WWW/test  
touch index.php
echo " ?>  >>index.php
#修改host  加入127.0.0.1  test.cc
sudo vim /etc/hosts 
#创建配置文件
cd /usr/local/etc/nginx/servers
touch test.conf
#键入下面内容
       server {
     
            #监听绑定80端口
            listen       80;
            #下面这个是域名,多个域名用空格隔开
            server_name  test.cc;
            #本网站的根路径
            root   /WWW/test;
            #下面是默认首页
            location / {
     
                index  index.html index.php;
            }
            #下面是针对本站所有.php文件进行处理的配置
            location ~ \.php{
     
                #加载fastcgi  一种处理方式
                 include fastcgi_params;
                #fastcgi的参数 指定文件路径及参数,否则会有404或是file not find 提示
                fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
                #fastcgi的服务信息 ip:端口
                fastcgi_pass 127.0.0.1:9000;
                #fastcgi默认首页
                fastcgi_index index.php;
            }
        }
#重启nginx
sudo nginx -s reload

安装redis

#安装redis
brew install redis
#启动redis
redis-server

安装扩展

#得到php的运行路径
which php 
#进去运行路径
cd /usr/local/opt/[email protected]/bin/
#通过pecl安装redis扩展
./pecl install redis

你可能感兴趣的:(环境软件)