配置 macOS 本地环境

让命令行看起来更简单

vim ~/.zshrc

内容如下

export PS1="%1~ "
#export PATH="$HOME/.composer/vendor/bin:$PATH"

让配置生效

source ~/.zshrc

接着需要安装 macOS 系统的命令行工具,执行如下命令

sudo rm -rf $(xcode-select -print-path)
xcode-select --install

这样的安装命令会删除旧版本的命令行工具包,然后安装最新版本的命令行工具包。

一、配置 Homebrew 环境

1. 安装 Homebrew

export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.ustc.edu.cn/homebrew-core.git"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles"
/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/Homebrew/install@HEAD/install.sh)"

然后会生成如下目录

/usr/local/bin
/usr/local/etc
/usr/local/include
/usr/local/lib
/usr/local/sbin
/usr/local/share
/usr/local/var
/usr/local/opt
/usr/local/share/zsh
/usr/local/share/zsh/site-functions
/usr/local/var/homebrew
/usr/local/var/homebrew/linked
/usr/local/Cellar
/usr/local/Caskroom
/usr/local/Frameworks

怎样卸载 Homebrew 呢?执行如下命令

/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/uninstall.sh)"

然后执行如下命令

cd /usr/local
sudo rm -rf *

2. 配置中科大镜像

替换brew.git:

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

替换homebrew-core.git:

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

替换Homebrew Bottles源

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc

3. 安装常用的软件

brew update
brew install mpv httpd php mysql composer npm

4. 配置国内镜像

composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
npm config set registry https://registry.npm.taobao.org

链接:腾讯镜像源、阿里镜像源

二、配置 MPV 播放器

vim ~/.config/mpv/mpv.conf

内容如下

no-osc
no-border
ontop=yes
autofit-larger=49%x64%
save-position-on-quit=yes

四、配置 Apache 环境

1. 设置 Apache 配置文件 httpd.conf

sudo vim /usr/local/etc/httpd/httpd.conf

取消以下行的注释

#LoadModule rewrite_module libexec/apache2/mod_rewrite.so
#LoadModule userdir_module libexec/apache2/mod_userdir.so
#Include /private/etc/apache2/extra/httpd-userdir.conf
#Include /private/etc/apache2/extra/httpd-vhosts.conf

并添加如下代码

LoadModule php_module /usr/local/opt/php/lib/httpd/modules/libphp.so


    SetHandler application/x-httpd-php

修改如下代码

User _www
Group _www

如下

User jackie
Group staff

2. 开启个人的配置文件 httpd-userdir.conf

sudo vim /usr/local/etc/httpd/extra/httpd-userdir.conf

内容如下

UserDir Sites


    Options FollowSymLinks Multiviews
    MultiviewsMatch Any
    AllowOverride All
    Require all granted

3. 设置多站点配置文件 httpd-vhosts.conf

sudo vim /usr/local/etc/httpd/extra/httpd-vhosts.conf

内容如下


    ServerAdmin webmaster@localhost
    DocumentRoot "/Library/WebServer/Documents"
    ServerName localhost



    ServerAdmin [email protected]
    DocumentRoot "/Users/jackie/Sites/test"
    ServerName test.local
    ServerAlias *.test.local
    ErrorLog "/private/var/log/apache2/test.local-error_log"
    CustomLog "/private/var/log/apache2/test.local-access_log" common

5. 部署网站代码

创建网站代码目录

mkdir -p ~/Sites/test

创建网站代码

cd ~/Sites/test
vim index.php

内容如下

6. 解析域名

sudo vim /etc/hosts

最后面加一行代码如下

127.0.0.1 test.local

执行命令 sudo apachectl restart 重启 Httpd 就可以通过浏览器访问 test.local 了。

另外本地开发经常需要用到 Sequel Pro, 下载安装即可。

五、配置数据库

brew services start mysql
mysql -uroot

1. 创建 Mysql 用户

CREATE USER jackie@localhost IDENTIFIED WITH mysql_native_password BY '123456';

2. 创建 test 数据库

CREATE DATABASE test;

3. 授权 Mysql用户

GRANT all ON test.* TO jackie@localhost;

4. 撤销 Mysql 用户的授权

REVOKE all ON test.* FROM jackie@localhost;

5. 删除 Mysql 用户

DROP USER jackie@localhost;

6. 数据库导出

mysqldump -h 127.0.0.1 -uroot -p test > test.sql

7. 数据库导入

mysql -uroot test < test.sql

8. 拷贝本地文件到远程服务器

scp test.sql jackie@Server_IP:~

9. 拷贝远程服务器文件到本地

scp jackie@Server_IP:/home/jackie/test.sql ~

你可能感兴趣的:(配置 macOS 本地环境)