加入收藏 | 设为首页 | 会员中心 | 我要投稿 开发网_开封站长网 (http://www.0378zz.com/)- 科技、AI行业应用、媒体智能、低代码、办公协同!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

苹果系统安装php环境的方法分析

发布时间:2022-07-21 13:05:38 所属栏目:PHP教程 来源:互联网
导读:macOS Catalina 预装了 Ruby(2.6.3)、PHP(7.3.9)、Perl(5.18.4)、Python(2.7.16) 等常用的脚本语言,以及 Apache(2.4.41) Web 服务器。 需要注意的是,在新版本中,zsh 已取代 bash 成为新版操作系统中的默认 shell。 以下是我的 MNMP(macOS-nginx-MySQL-PH
  macOS Catalina 预装了 Ruby(2.6.3)、PHP(7.3.9)、Perl(5.18.4)、Python(2.7.16) 等常用的脚本语言,以及 Apache(2.4.41) Web 服务器。
 
  需要注意的是,在新版本中,zsh 已取代 bash 成为新版操作系统中的默认 shell。
 
  以下是我的 MNMP(macOS-nginx-MySQL-PHP)的安装过程。
 
  本教程用使用了三处代替:
 
  使用 iTerm2 代替了系统自带的命令行终端
  使用 nginx 代替了系统自带的 Apache
  使用 自行安装的 PHP7.4 代替了系统自带的 PHP7.3.9
  安装 iTerm2
  推荐 iTerm2,iTerm2 功能强大,可以替代系统默认的命令行终端。下载解压后,将 iTerm2 直接拖入"应用程序"目录。
 
  安装 Xcode
  Xcode 是苹果出品的包含一系列工具及库的开发套件。通过 AppStore 安装最新版本的 Xcode(9.0)。我们一般不会用 Xcode 来开发后端项目。但这一步也是必须的,因为 Xcode 会附带安装一些如 Git 等必要的软件。
 
  安装 Command Line Tools for Xcode
  这一步会帮你安装许多常见的基于 Unix 的工具。Xcode 命令行工具作为 Xcode 的一部分,包含了 GCC 编译器。在命令行中执行以下命令即可安装:
 
 
  xcode-select --install # 安装 Xcode Command Line Tools
 
  当 Xcode 和 Xcode Command Line Tools 安装完成后,你需要启动 Xcode,并点击同意接受许可协议,然后关闭 Xcode 就可以了。这一步骤也是必须的,否则 Xcode 包含的一系列开发工具都将不可用。
 
 
  cd "$(brew --repo)"
 
  git remote set-url origin https://mirrors.ustc.edu.cn/brew.git # 替换brew.git:
 
   
 
  cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
 
  git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git # 替换homebrew-core.git:
 
   
 
  echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc # 替换Homebrew Bottles源:
 
   
 
  source ~/.zshrc
 
  安装 PHP 7.4
  安装 PHP7.4.* 来代替系统自带的 PHP7.3:
 
 
  brew install php
 
  启动 php 服务:
 
 
  brew services start php
 
  替换系统自带的 php-fpm:
 
 
 
  echo 'export PATH="/usr/local/opt/php/sbin:$PATH"' >> ~/.zshrc
 
  source ~/.zshrc
 
  查看版本信息:
 
 
 
  php -v
 
  php-fpm -v
 
  安装 MySQL
  推荐 MySQL 8.0 作为数据库服务器:
 
 
  brew install mysql
 
  当然,你也可以选择安装 PostgreSQL 或者 MariaDB。
 
  安装完成后,启动 MySQL:
 
 
  brew services start mysql
 
  进入 MySQL 服务器:
 
  brew install redis
 
  安装完成后,启动 Redis:
 
 
  brew services start redis
 
  使用 redis 客户端:
 
 
  redis-cli
 
  安装 nginx
  这里我们选择 nginx 代替系统自带的 Apache,作为我们的 Web 服务器:
 
 
  brew install nginx
 
  启动 nginx 服务:
 
 
  brew services start nginx
 
  查看已安装的 brew services:
 
 
  brew services list
 
  配置 nginx.conf 文件
  通过以下命令可以查看 nginx.conf 文件的位置:
 
 
 
 
  nginx version: nginx/1.17.3
 
  Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]
 
  Options:
 
  -?,-h : this help
 
  -v : show version and exit
 
  -V : show version and configure options then exit
 
  -t : test configuration and exit
 
  -T : test configuration, dump it and exit
 
  -q : suppress non-error messages during configuration testing
 
  -s signal : send signal to a master process: stop, quit, reopen, reload
 
  -p prefix : set prefix path (default: /usr/local/Cellar/nginx/1.17.3_1/)
 
  -c filename : set configuration file (default: /usr/local/etc/nginx/nginx.conf)
 
  -g directives : set global directives out of configuration file

(编辑:开发网_开封站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读