工具和技巧集锦Mac 教程收集工具使用指南

公司新同事的MAC安装配置指南

2019-01-28  本文已影响818人  wizarot

过去写的一篇文章,放自己网站没人看. 拿简书上来试试! 源站地址: http://wizarot.me/post/2018-03-22/

基本配置篇

> ls  (显示当前目录内容)
> cd xxx  (进入某一个目录)

打开后会默认在当前用户的home目录. 执行ls ~/.ssh 查看是否存在这个目录,正常新机器是不存在的,如果有请咨询同事. 如果不存在,那么我们就新建一个,这将会生成.ssh目录和下面的文件.ssh目录是隐藏目录,新建之后用ls不能直接看到,这个很正常. 执行命令: ssh-keygen -t rsa -C "youremail@example.com” 里面的email用公司分配给你的即可.后面还有一些询问,都直接回车默认.

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

 > brew install zsh zsh-completions #安装zsh
 > chsh -s $(which zsh) #切换zsh为默认shell
 > sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

 > brew install git


其他可选项目

> brew tap caskroom/cask
> brew install brew-cask
> brew tap caskroom/versions
> brew cask install sublime-text

PHP开发篇

> brew install php@5.6  # 安装php5.6

> brew unlink php  # 不执行这个会报错
> brew install php@70 # 安装php7.0版本

我们使用第三方的brew库: 原因是新版brew不支持同时使用多个版本php. 但会引入新问题,这个库中的lib引用没有维护,可能造成一些报错.但你可以通过软连接没有的这些库来解决. 网上也能找到非常多的解决方案. 具体缺哪个你就处理哪个即可.

> brew tap kyslik/homebrew-php

然后后面就可以正常安装对应的php扩展了.如不哦不行,那么建议考虑用源码安装吧!也是可以的.

不喜欢用,或者安装嫌麻烦也可以不用. 直接用brew unlink php71; brew link php56 这样也能简单切换.

项目github: https://github.com/wilmoore/php-version

> brew install php-version (这个办法已弃用!)
> mkdir -p $HOME/local/php-version
> cd !$
> curl -# -L https://github.com/wilmoore/php-version/tarball/master | tar -xz --strip 1

装好之后,编辑 ~/.zshrc文件,增加下面这行.这样在每次启动一个shell就会加载php-version管理了.

source $HOME/local/php-version/php-version.sh && php-version 7.0

具体使用方法: php-version 查看当前安装php版本. php-version 7.0 切换到对应版本.

> subl "$(brew --prefix)/etc/php/7.0/php.ini" # 用之前安装的sublime编辑器编辑文件

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone (设置时区)
date.timezone =Asia/Macao

...

; Maximum amount of memory a script may consume (128MB)
; http://php.net/memory-limit (设置运行的内存限制)
memory_limit = 1024M

...
; (设置post最大小)
post_max_size = 256M
; (设置上传单个文件大小)
upload_max_filesize = 256M

;if APC installed, update following in conf.d/ext-apc.ini(如果有,没有就算了)
apc.shm_size=256M

设置php-fpm: 为了方便好记设置 php7.0使用9070端口; php5.4用9054端口; php5.6用9056端口; php7.2 用9072端口

> subl "$(brew --prefix)/etc/php/7.0/php-fpm.conf" 

listen = 127.0.0.1:9070  ;配置文件中分号是单行注释,设置为监听本机的9070端口是为了方便.

brew services start homebrew/php/php70

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

> brew install redis    # 安装reids软件
> brew info redis    # 查看安装信息
> brew services start redis # 后台启动redis服务

> brew install mysql # 安装mysql
> brew info mysql  # 查看安装信息(正常安装后也会直接显示一次)
> brew services start mysql # 启动mysql服务,默认用户root,密码为空

> brew install nginx # 直接安装nginx
> brew info nginx # 查看安装信息

> subl /usr/local/etc/nginx/nginx.conf  # 编辑修改配置文件

worker_processes  4;  # nginx服务进程数量,本地开发4条进程就差不多了
...

> cd /usr/local/etc/nginx/servers/
> subl test.conf

编辑文件 test.conf

# test;
server {
        listen       80; # 监听80端口,注意会造成直接启动服务失败,因为权限问题,这个下一节说明
        client_max_body_size 1024m;
        server_name test.l.wizmacau.com; # 公司域名xxx.l.wizmacau.com会自动指向localhost,因此不需要改本机的hosts文件了.
        access_log  /Users/user/logs/test.access.log; # 访问记录路径
        error_log  /Users/user/logs/test.error.log; # 错误记录路径

        root   /Users/user/php_productions/test/web; # 网站根目录,根据实际修改

        # 如果URL中包含app.php,则转发为伪静态格式
        rewrite ^/app_dev\.php/?(.*)$ /$1 permanent;

        location / {
          index app_dev.php; # 默认解析本地开发模式 for symfony
          try_files $uri @rewriteapp;
        }
        location @rewriteapp {
          rewrite ^(.*)$ /app_dev.php/$1 last;
        }

        location ~ ^/(index|app|app_dev|config)\.php(/|$) {
            fastcgi_pass 127.0.0.1:9070; # php-fpm端口,使用7.0则改为9070端口
            fastcgi_split_path_info ^(.+\.php)(/.*)$;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param HTTPS off;
            proxy_read_timeout 300;
            proxy_connect_timeout 300;
            proxy_redirect off;
        }

}

注意不要使用.dev做为本地开发域名,因为chrome浏览器新版本强制要求.dev的域名必须使用https.如果没在nginx配置443端口,那么会导致怎么都访问不到你的本地项目.

> which nginx  # 查询当前nginx路径
> sudo chown root:wheel /usr/local/bin/nginx # 根据查询路径,给nginx修改所有者为root,注意会提示输入当前用户登录密码
> sudo chmod u+s /usr/local/bin/nginx
> sudo brew services start nginx  # 使用root用户启动nginx服务
> ps aux|grep nginx # 查看后台进程,如果有 nginx: worker process 那么说明nginx服务启动成功,如果失败请叫同事帮忙

Python开发篇(TODO)

> brew install python3 # 安装python3

Nodejs环境(TODO)

GO语言开发环境(TODO)

上一篇 下一篇

猜你喜欢

热点阅读