程序员教育培训&老师&互联网&创业

一、mac安装Homebrew,更新 nginx php7 my

2019-03-13  本文已影响1人  langkong
//查看版本
brew -v

//安装homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

国内Homebrew镜像,更换镜像源加速:

cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git

brew update

brew -v

安装 启动 nginx

brew cleanup  //移除旧版本

brew install nginx
//启动nginx,如果更新安装nginx,启动时常会提示没有权限,则删除之前的logs文件夹中的文件等
sudo nginx   //启动
//查看状态
ps -ef|grep nginx
nginx -V
sudo nginx -s reload  //重新加载配置
sudo nginx -s stop    //关闭
lsof -i tcp:80        //查看80端口占用情况
ps aux | grep nginx  //查看nginx进程

配置nginx 虚拟主机,通过域名访问本地web项目

server {
listen 80;
server_name  www.dtemp.com;
root /Users/free/www/learnlaravel/;

access_log /usr/local/var/logs/nginx/dtemp.access.log;
location / {
    if (!-e $request_filename){
        rewrite ^/(.*) /index.php last;
    }
    index index.html index.htm index.php;
    autoindex on;
    include /usr/local/etc/nginx/conf.d/php-fpm;
  }

} 

// include /usr/local/etc/nginx/conf.d/php-fpm;
//这个文件内容:

location ~ \.php$ {
try_files $uri = 404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_intercept_errors on;
include /usr/local/etc/nginx/fastcgi.conf;
}

//以上内容表示如果nginx接到的请求是.php结尾的php程序,
//则将请求转发到本机9000端口,而这个端口是php-fpm在监听,
//当未安装php时,请求www.dtemp.com会返回502错误

搜索安装php

brew search php
brew install php@7.2
php -v //查看版本
php -m //查看扩展
//安装完php7会输出以下内容,实际是一个简单guid,
//执行 brew services start php@7.2启动php-fpm


The php.ini and php-fpm.ini file can be found in:
    /usr/local/etc/php/7.2/

php@7.2 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have php@7.2 first in your PATH run:
//*执行下面两行命令,就会将php7命令路径加入环境变量

  echo 'export PATH="/usr/local/opt/php@7.2/bin:$PATH"' >> ~/.bash_profile
  echo 'export PATH="/usr/local/opt/php@7.2/sbin:$PATH"' >> ~/.bash_profile

For compilers to find php@7.2 you may need to set:
  export LDFLAGS="-L/usr/local/opt/php@7.2/lib"
  export CPPFLAGS="-I/usr/local/opt/php@7.2/include"


To have launchd start php@7.2 now and restart at login:
  brew services start php@7.2
Or, if you don't want/need a background service you can just run:
  php-fpm

laravel环境要求如下, 新建test.php在web目录,可以清楚看到php配置和扩展等信息

PHP >= 7.1.3
OpenSSL PHP Extension
PDO PHP Extension
Mbstring PHP Extension
Tokenizer PHP Extension
XML PHP Extension
Ctype PHP Extension
JSON PHP Extension
BCMath PHP Extension

test.php 内容:
<?php phpinfo();?>

安装mysql,通过官网下载社区版
https://dev.mysql.com/downloads/mysql/

 brew 覆盖安装老版本往往有些坑,使用dmg安装一路next简易操作,只有一点需要注意。
 老版连接mysql的客户端使用的旧版加密,mysql8安装时会默认选择加强加密,可以选择老版加密,避免更好客户端。

navicat 查看mysql数据库很方便,推荐一个下载地址:https://xclient.info/search/s/navicat/

创建用户并分配某个库的权限给该用户,项目中不要使用root账户

//*我mac安装后mysql的路径 
cd /usr/local/mysql-8.0.15-macos10.14-x86_64/bin
./mysql //进入mysql命令行模式
use mysql;//进入mysql系统库
//创建名为freeuser的用户,%表示可以远程操作,ip不限。
CREATE USER 'freeuser'@'%' IDENTIFIED BY 'free99';
//分配learnlaravel库的所有权限给freeuser用户
GRANT ALL PRIVILEGES ON learnlaravel.* TO 'freeuser'@'%';
上一篇下一篇

猜你喜欢

热点阅读