资讯专栏INFORMATION COLUMN

macOS High Sierra 10.13.3全新搭建PHP开发环境

SQC / 1270人阅读

摘要:安装是苹果出品的包含一系列工具及库的开发软件。通过安装最新版本的。如果你的是之前的版本的话,在你编译的时候会提示你更新版本我们一般不会用来开发项目。命令行工具作为的一部分,包含了编译器。

用了快三年的Mac Pro出现问题,苹果公司帮忙换了一台全新的,所以没办法,只能重新装环境,装平时开发所需的各种软件,本着乐于助人的雷锋精神也把这次搭建写出来,希望可以帮助更多人。

废话不多说进入正题

macOS Sierra 已经帮我们预装了 Ruby、PHP、Perl、Python 等常用的脚本语言,以及 Apache 服务器等等。


1.安装 Xcode

Xcode 是苹果出品的包含一系列工具及库的开发软件。
通过 App Store 安装最新版本的 Xcode。(如果你的Xcode是8.2之前的版本的话,在你编译PHP7.0+的时候会提示你“更新Xcode”版本)
我们一般不会用 Xcode 来开发 PHP 项目。但这一步也是必需的,因为 Xcode 会帮你附带安装一些如 Git 等必要的软件。当然你也可以通过源码包安装 Git
N多软件包都基于Xcode,既然必须要安装,所以我就把这个安装放在第一步。

安装成功,哎公司网络比较差,只能晚上回家安装,大概等了2小时吧,size 5G左右,所以网络不好就提前安装一下吧。

2.安装 Xcode Command Line Tools

这一步会帮你安装许多常见的基于 Unix 的工具。Xcode 命令行工具作为 Xcode 的一部分,包含了 GCC 编译器。在命令行中执行以下命令即可安装:

xcode-select --install

直接点击install,然后等待安装完成就好,哎等待总是漫长的。
Verify that you’ve successfully installed Xcode Command Line Tools:

xcode-select -p
返回以下表示安装成功
/Applications/Xcode.app/Contents/Developer
3.安装 Homebrew

HomeBrew 是macOS 软件包管理器,用来安装、升级以及卸载常用的软件

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


及时按回车键然后输入开机密码,等待安装完成
有时homebrew核心仓库没有我们所要的安装包,但在其他仓库中有,那我们可以自己添加

homebrew扩展仓库
* 列出已有仓库:` brew tap`
* 添加仓库:` brew tap 仓库名 `
* 删除仓库:` brew untap 仓库名`

安装完成后,我们可以考虑更改下 Homebrew 源,因为国外源一直不是很给力,这里我们将 Homebrew 源改为中国科学技术大学开源软件镜像:

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

iTerm2 是 MAC 下最好的终端工具(没有之一)以及配合oh-my-zsh 及其插件,将是强大的神器
下载iTerm2,打开会提示移动到application,或者在 Finder 中,将 iTerm 拖拽进入 Application 文件夹中。这样,你可以在 Launchpad 中启动 iTerm2。

4.1 安装 oh-my-zsh

接下来安装配合iTerm2使用的oh-my-zsh
首先查看系统支持的shell列表,Mac 系统自带了 zsh ,Linux上得安装

cat /etc/shells
zsh --version   //查看版本

虽然Mac自带了zsh,如果你想要最新版的zsh,那么你用 brew install zsh 安装一个最新的吧(问题不大)

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

哇哦,iTerm2的界面瞬间舒服多了,有没有、有没有、有没有?(哈哈哈哈哈哈)

不过默认的theme主题”robbyrussell”用起来感觉还是差了那么一点点,大多数coder都比较喜欢 agnoster.zsh-theme 这个主题

各种主题

vim ~/.zshrc       //打开这个配置文件
ZSH_THEME="robbyrussell"    找到这行主题配置
更换成以下的主题名就好
ZSH_THEME="agnoster" # (this is one of the fancy ones)
# see https://github.com/robbyrussell/oh-my-zsh/wiki/Themes#agnoster

打开一个新终端看看目前是什么样的一个主题,不过貌似有一点不对,有一些字符不能正常显示,so我们来安装一个字体 Powerline fonts

# clone
git clone https://github.com/powerline/fonts.git --depth=1
# install
cd fonts
./install.sh
# clean-up a bit
cd ..
rm -rf fonts

然后到iterm2的preferences > profiles > colors 配色设置选择一个(我比较喜欢这种类型的颜色)
http://ethanschoonover.com/so... 配色主题
继续修改字体,改成刚安装成功的字体

然后重开一个终端,发现会带上自己mac的用户名什么的,个人感觉挺多余的,so我自己来改变一下
首先进到存放主题的文件夹》复制agnoster.zsh-theme > myagnoster.zsh-theme

cd ~/.oh-my-zsh/themes  //进入主题文件夹
cp agnoster.zsh-theme myagnoster.zsh-theme //复制一份
vim myagnoster.zsh-theme  打开
 
## Main prompt
build_prompt() {
  RETVAL=$?
  prompt_status
  prompt_virtualenv
 #prompt_context
  prompt_dir
  prompt_git
  prompt_hg
  prompt_end
}
只需把prompt_context用#注释掉即可
 
然后打开.zshrc  
ZSH_THEME="agnoster"  》 ZSH_THEME="myagnoster" 改成这样就可以了
 
这样做的原因是避免升级有冲突
4.2 插件

oh my zsh 自带插件
Oh My Zsh 本身自带了很多插件,比如说: git, autojump osx, 不过基本都没有启用,插件目录: ~/.oh-my-zsh/plugins

4.2.1 安装 zsh-syntax-highlighting

这个自动高亮效果的插件也是配合oh-my-zsh使用

Oh-my-zsh插件形式的安装,还有更多安装方式大家可以去探索一下

Clone this repository in oh-my-zsh"s plugins directory:

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

Activate the plugin in ~/.zshrc:

plugins=( [plugins...] zsh-syntax-highlighting)

Source ~/.zshrc to take changes into account:

source ~/.zshrc

5. 安装 PHP

Mac最新的系统已经自带php,个人比较喜欢安装最新的,所以这边升级一下

brew search php   // 先搜索一下

brew install php   // 安装,等待安装完成

新开一个tab输入php -v就可以看到最新版本了

加入开机自启
ln -sfv /usr/local/opt/php/*.plist ~/Library/LaunchAgents
6. 安装 Composer

Dependency Manager for PHP , PHP 的一个依赖管理工具

brew search composer

brew install composer

安装成功啦,之后我们就可以通过composer来安装PHP的一些扩展包

7. 安装 Mysql
brew install mysql  //安装

安装成功如下:
We"ve installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation
 
MySQL is configured to only allow connections from localhost by default
 
To connect run:
    mysql -uroot
 
To have launchd start mysql now and restart at login:
  brew services start mysql
Or, if you don"t want/need a background service you can just run:
  mysql.server start

启动:
mysql.server start

加入开机自启
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents

运行密码配置
//运行mysql_secure_installation

mysql_secure_installation
 
Securing the MySQL server deployment.
 
Connecting to MySQL using a blank password.
 
VALIDATE PASSWORD PLUGIN can be used to test passwords  //密码验证插件,为了提高安全性,需要验证密码
and improve security. It checks the strength of password     // 它会检查密码的强度
and allows the users to set only those passwords which are      //只允许用户设置足够安全的密码
secure enough. Would you like to setup VALIDATE PASSWORD plugin?    //你确定要安装验证密码插件吗?
 
Press y|Y for Yes, any other key for No: y      //确定安装
 
There are three levels of password validation policy:   //三个等级的验证策略
 
LOW    Length >= 8   //最小长度大于等于8个字符
MEDIUM Length >= 8, numeric, mixed case, and special characters     //数字,字母,特殊字符 混合,具体的应该是至少1个数字,1个字母,1个特殊字符,长度不超过32个字符
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file     //  最严格,加上了,字典文件
 
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0       //这里我选择0最简单的,
Please set the password for root here.
 
New password:       //输入密码
 
Re-enter new password:      //重复输入密码
 
Estimated strength of the password: 50      //密码强度的评级
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y    //是否使用刚输入的密码?
By default, a MySQL installation has an anonymous user,     //默认情况下,MySQL有一个匿名用户,
allowing anyone to log into MySQL without having to have     //这个匿名用户,不必有一个用户为他们创建,匿名用户允许任何人登录到MySQL,
a user account created for them. This is intended only for   //这只是为了方便测试使用
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production  //在正式环境使用的时候,建议你移除它
environment.
 
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y    //提示移除匿名用户
Success.
 
 
Normally, root should only be allowed to connect from    //一般情况下,root用户只允许使用"localhost"方式登录,
"localhost". This ensures that someone cannot guess at  
the root password from the network.  // 以此确保,不能被某些人通过网络的方式访问
 
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : no    //不允许root远程登陆?
 
 ... skipping.
By default, MySQL comes with a database named "test" that     //默认情况下,MySQL数据库中
anyone can access. This is also intended only for testing,        //这也仅仅是为了测试
and should be removed before moving into a production             // 在正式环境下,应该移除掉
environment.
 
 
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y  //确认删除test数据库?
 - Dropping test database...
Success.
 
 - Removing privileges on test database...
Success.
 
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.         //刷新权限表,以确保所有的修改可以立刻生效
 
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y      //确认刷新
Success.
 
All done!
8. 安装 Laravel Valet

这边我说明一下,本该安装 NGINX,因为我所接触的项目都是 laravel 或者 lumen,所以我这边安装这个 laravel 官方支持的 valet 开发环境,这个其实本身就是运用的 nginx,只是使用这个开发环境,开发 laravel 的很多项目就非常方便,我个人也比较建议使用,目前支持 Mac 和 linux 系统。
前面已经安装php和composer,这边就可以直接安装

composer global require laravel/valet  //先获取项目
valet install       //然后安装
ping foobar.test    //ping一下是否通

在家目录创建Sites文件夹,之后所有项目都放在这个文件夹中,访问的话也是文件夹名+.test就可以了

mkdir ~/Sites
cd ~/Sites
valet park  //将这个目录设置为项目仓库
valet path  //查看valet 仓库路径

这样就可以以这样的  http://blog.test 域名访问了

如果有切换PHP版本需求的用户,我觉得这个 brew-php-switcher 可能会比较适合

9. 安装 Redis
brew search redis
brew install redis

默认配置在/usr/local/etc/redis.conf

redis-server

设置开机启动
ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents 

使用launchctl启动redis server
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist

最基本的PHP开发环境已经搭建完成,可以创造世界了!哈哈

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/31413.html

相关文章

  • macOS High Sierra 10.13.3全新搭建PHP开发环境

    摘要:安装是苹果出品的包含一系列工具及库的开发软件。通过安装最新版本的。如果你的是之前的版本的话,在你编译的时候会提示你更新版本我们一般不会用来开发项目。命令行工具作为的一部分,包含了编译器。 showImg(https://segmentfault.com/img/bVbsoUj?w=640&h=426); 用了快三年的Mac Pro出现问题,苹果公司帮忙换了一台全新的,所以没办法,只能重...

    cnTomato 评论0 收藏0
  • macOS High Sierra 10.13.3全新搭建PHP开发环境

    摘要:安装是苹果出品的包含一系列工具及库的开发软件。通过安装最新版本的。如果你的是之前的版本的话,在你编译的时候会提示你更新版本我们一般不会用来开发项目。命令行工具作为的一部分,包含了编译器。 showImg(https://segmentfault.com/img/bVbsoUj?w=640&h=426); 用了快三年的Mac Pro出现问题,苹果公司帮忙换了一台全新的,所以没办法,只能重...

    shuibo 评论0 收藏0
  • macOS系统PHP7增加Xdebug

    摘要:但是,系统自带的只有基础的配置,如果想做开发,还是必须的,以下就总结一下如何在中为系统自带的增加模块。本文先发布于我的个人博客系统增加,后续如有更新,可以查看原文。 Apple在发布macOS High Sierra后,系统也终于自带了php v7.1,相比于之前,如果想使用php7,还得额外想办法( Homebrew 或者 php-osx )而言着实方便了不少。 但是,系统自带的PH...

    sPeng 评论0 收藏0
  • MacOS High Sierra下完整搭建MNMP开发环境

    摘要:一些关于在最新下搭建开发环境的流程建议,直接进入正题安装开发常用包软件又叫,是上的软件包管理工具,能在中方便的安装软件或者卸载软件,和系统中的非常相似,只需要一个命令,非常方便。 一些关于在最新 Macos 下搭建LNMP开发环境的流程建议,直接进入正题: Preparing安装 Homebrew、Ohmyzsh、开发常用包&软件 1.1 Homebrew Homebrew又叫Br...

    awkj 评论0 收藏0
  • MacOS High Sierra下完整搭建MNMP开发环境

    摘要:一些关于在最新下搭建开发环境的流程建议,直接进入正题安装开发常用包软件又叫,是上的软件包管理工具,能在中方便的安装软件或者卸载软件,和系统中的非常相似,只需要一个命令,非常方便。 一些关于在最新 Macos 下搭建LNMP开发环境的流程建议,直接进入正题: Preparing安装 Homebrew、Ohmyzsh、开发常用包&软件 1.1 Homebrew Homebrew又叫Br...

    jay_tian 评论0 收藏0

发表评论

0条评论

SQC

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<