2021款Mac M1配置Apache、MariaDB

准备工作

macOS 莫过于Shell终端的便利性优势,妥妥的一条命令撬动世界。

macOS12的Shell终端默认是 ~zsh,不再是之前的 ~bash

过程中吃过亏,尤其很多的Github项目被GFW墙了。所以第一步得解决网络问题,后续的各种配置安装才会更顺畅。

配置终端代理

默认Mac SSH是不走代理的,所以先临时配置如下,也有始终让SSH走代理的方法,但我个人不推荐。详细说明参考 Mac M1 Zsh 终端代理设置

export http_proxy=http://127.0.0.1:7890
export https_proxy=$http_proxy
export socks5_proxy="socks5://127.0.0.1:7890"

网络代理,目前自己用的是付费机场服务,客户端使用 ClashX。 这只是解决浏览器及APP联网问题,Shell 工具参考如上方法进行临时配置。

解决了网络问题,首先就是安装Homebrew服务,参考笔记 Mac M1芯片安装Homebrew 。其实,也是一条命令的事:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

整套环境的安装配置过程,参考文章如下:

  1. macOS 12.0 Monterey Apache Setup: Multiple PHP Versions
  2. macOS 12.0 Monterey Apache Setup: MySQL, Xdebug & More
  3. Install PHP on macOS Monterey 12.4 and Set up Apache
  4. Certificate Authority for Code Signing in Mac/Apple

安装Apache

macOS 12.0 Monterey 系统中已经开始预安装了Apache服务,不过苹果在发布的时候还是会移除一些Apache脚本服务,所以不管如何,建议还是自己通过 Homebrew 重装一遍。因为这也可以解决后续PHP挂载Apache的时候需要做系统代码签名认证的麻烦。

1、卸载预安装版本

先将服务停了,然后对服务列表进行unload。

sudo apachectl stop
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null

2、安装 httpd

通过 brew 命令安装 httpd 服务

brew install httpd

成功后会看到类似信息 🍺 /opt/homebrew/Cellar/httpd/2.4.51: 1,660 files, 32.0MB

此时可启动服务 brew services start httpd ,通过浏览器 http://localhost:8080 可以看到 "It works!",说明Apache Httpd服务就准备好了。

安装 MariaDB

1、执行安装

以下命令,开始进入MariaDB 安装过程,系统下载包后分步执行依赖安装。

brew update
brew install mariadb

2、安全配置

执行过程中,根据提示回到 y 或 n,大多数用 n 就可以了,因为是本地开发环境,并无太多安全因素需要考虑。

特别注意在回答 Disallow root login remotely? [Y/n] n 要选 n,而后会提示两次输入设置 root 用户密码,有些Web 应用在安装向导中要求一定要提供 mySQL 用户密码的问题,因为大多数网站数据连接是不支持匿名访问的。

sudo /opt/homebrew/bin/mysql_secure_installation

补充

Brew Apache 常用命令

brew services stop httpd
brew services start httpd
brew services restart httpd

-- End.

依然少年@SHESHUI.ME 2022.8.20 PM

评论已关闭。Comments are turned off for this article.