mac上brew安装Apache+MySQL+PHP7(学习经验总结)

 

最近更换电脑了,换成苹果mac,尝试自己配置php的可开发环境,发现问题简直是一大堆,太多关于环境部署的知识点了的,真是学无止境......,现将我的一顿胡乱操作记录如下:

因为苹果电脑自带ruby,可以使用ruby安装brew

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

安装的过程当中可能汇遇到下面的问题:

mac 安装homebrew出错 Failed to connect to raw.githubusercontent.com port 443: Connection refused error:

解决办法如下,重装command line tools,再执行安装指令,homebrew安装成功。

removing the old tools ($ rm -rf /Library/Developer/CommandLineTools)
install xcode command line tools again ($ xcode-select --install).
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

以上参考https://blog.csdn.net/heroacool/article/details/102844367

安装brew成功后,如果觉得下载源很慢的情况下,可以采取以下的方法:

Mac下brew更换国内镜像源最新方法

 brew 是一个很好地Mac下管理应用包的工具,可是第一次安装后直接使用时,下载和更新很慢,这是因为brew的镜像源在国外,我们的网络访问会很慢,不过我们可以修改镜像源为国内,网上有很多博客提供的方法,我试了很多,大部分都过时了,以下是我经过测试截止2019年最新的官方方法更换为国内镜像源(清华大学)

cd /usr/local/Homebrew

git -C “$(brew --repo)” remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git

git -C “$(brew --repo homebrew/core)” remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git

git -C “$(brew --repo homebrew/cask)” remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git

 

brew update

在使用过最后brew update后,需要等待一部分时间,大概一分钟,如果看见终端上方一直在变化就离成功不远了,最后会在终端中显示更新信息,就算是大功告成了。复原的方法

cd /usr/local/Homebrew

git -C “$(brew --repo)” remote set-url origin https://github.com/Homebrew/brew.git

git -C “$(brew --repo homebrew/core)” remote set-url origin https://github.com/Homebrew/homebrew-core.git

git -C “$(brew --repo homebrew/cask)” remote set-url origin https://github.com/Homebrew/homebrew-cask.git

brew update

最新的设置与复原方法参考;https://mirrors.tuna.tsinghua.edu.cn/help/homebrew/

上述经验参考博文地址:https://blog.csdn.net/weixin_40475396/article/details/104042037

卸载brew的方法:

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

 brew -v 可以查看brew的版本

安装完brew后,有以下这些常用的操作:

简单使用:

安装软件:brew install 软件名,例:brew install wget
搜索软件:brew search 软件名,例:brew search wget
卸载软件:brew uninstall 软件名,例:brew uninstall wget
更新所有软件:brew update

更新具体软件:brew upgrade 软件名 ,例:brew upgrade git
显示已安装软件:brew list
查看软件信息:brew info/home 软件名 ,例:brew info git / brew home git
PS:brew home指令是用浏览器打开官方网页查看软件信息
查看哪些已安装的程序需要更新: brew outdated
显示包依赖:brew reps
显示帮助:brew help

以上操作参考博客地址:https://blog.csdn.net/qq_41234116/article/details/79366454

有人说在mac上设置:export ALL_PROXY=socks5://127.0.0.1:portnumber 这样可以加快终端下载速度,我这边尝试效果不明显,

tips:portnumber取决于自己电脑的端口(1086),以上参考博文地址:

https://www.jianshu.com/p/a9d9f00daf30

brew install [email protected]
brew install [email protected]

 vim ~/.bash_profile可以配置php环境变量

export PATH="/usr/local/opt/[email protected]/bin:$PATH"
export PATH="/usr/local/opt/[email protected]/sbin:$PATH"

安装配置Apache 

brew install httpd

配置(去掉注释或添加注释) 

Include /usr/local/etc/httpd/extra/httpd-vhosts.conf

LoadModule php7_module /usr/local/Cellar/[email protected]/7.2.18/lib/httpd/modules/libphp7.so

AddHandler application/x-httpd-php .php

ServerName localhost:80

Listen 80

#伪静态配置
LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so

在extra/httpd-vhosts.conf配置虚拟主机 

<VirtualHost *:80>
    ServerName xxx
    DocumentRoot xxx
    <Directory "xxx">
        DirectoryIndex index.html index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog "/usr/local/var/log/httpd/error_log"
    CustomLog "/usr/local/var/log/httpd/access_log" common

    RewriteEngine On

    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ https://%1$1 [L,R=permanent]

    RewriteCond %{HTTP:X-Forwarded-Proto} =http
    RewriteRule .* https://%{HTTP:Host}%{REQUEST_URI} [L,R=permanent]

    RewriteCond "%{DOCUMENT_ROOT}%{REQUEST_FILENAME}" !-f
    RewriteCond "%{DOCUMENT_ROOT}%{REQUEST_FILENAME}" !-d
    RewriteRule "^" "/index.php" [L]
</VirtualHost>

重启Apache

sudo apachectl restart

配置apache  开机启动命令操作如下:

brew services start httpd

以上安装经验总结参考博文地址:

 https://www.jianshu.com/p/bc087c8235b7,根据该参考整理的。

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章