mac 安装 php nginx mysql
Posted Lucky_man
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mac 安装 php nginx mysql相关的知识,希望对你有一定的参考价值。
mac下面安装php nginx mysql根linux下面差不多,建议大家使用brew管理工具包安装。
1,安装homebrew
http://brew.sh/index_zh-cn.html
安装方法会改变的,所以安装官方上面的方法来装。安装 homebrew-cask
- $ brew tap caskroom/cask
homebrew-cask安装的东西,更多。
2,换源或者加代理
brew管理工具包,默认是从github上面下载,github经常被墙。并且龟速。
- $ brew install git
- $ cd /usr/local/Homebrew
- $ git remote set-url origin https://git.coding.net/homebrew/homebrew.git
如果不想换源话,可以加代理,前提是你的代理,不被墙,并且比较快
- zhangyingdeMacBook-Pro:Homebrew zhangying$ cat ~/.curlrc
- socks5="127.0.0.1:1080"
3,安装nginx mysql
- $ brew install nginx mysql
4,安装php
- //添加扩展库
- $ brew tap homebrew/dupes
- $ brew tap homebrew/versions
- $ brew tap homebrew/php
- $ brew search php //查看php的可用版本
- $ brew install php54 //安装所需版本
- //默认是有php的,所以php的环境要指向新的
- $ echo ‘export PATH="$(brew --prefix homebrew/php/php54)/bin:$PATH"‘ >> ~/.bash_profile
- $ echo ‘export PATH="$(brew --prefix homebrew/php/php54)/sbin:$PATH"‘ >> ~/.bash_profile
- $ echo ‘export PATH="/usr/local/bin:/usr/local/sbin:$PATH"‘ >> ~/.bash_profile
- $ source ~/.bash_profile //更新配置
5,配置文件目录
- /usr/local/etc/nginx
- /usr/local/etc/php
- /usr/local/Cellar/mysql/5.7.16
6,开机启动,以nginx为例
- $ ln -s /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents/
- $ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist //加载
- $ launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist //取消加载
7,sudo无密码
- $ sudo su
- # visudo
- %admin ALL = NOPASSWD:ALL //admin组的成员,sudo不用输入密码了
8,如果不想自启动,可以用启动脚本
- #!/bin/bash
- param=$1
- start()
- {
- #启动nginx
- sudo nginx //nginx需要root用户来启动
- #启动mysql
- mysql.server start
- #启动php-fpm
- fpms=`ps aux | grep -i "php-fpm" | grep -v grep | awk ‘{print $2}‘`
- if [ ! -n "$fpms" ]; then
- php-fpm
- echo "PHP-FPM Start"
- else
- echo "PHP-FPM Already Start"
- fi
- }
- stop()
- {
- #停止nginx
- sudo nginx -s stop
- #停止mysql
- mysql.server stop
- #停止php-fpm
- fpms=`ps aux | grep -i "php-fpm" | grep -v grep | awk ‘{print $2}‘`
- echo $fpms | xargs kill -9
- for pid in $fpms; do
- if echo $pid | egrep -q ‘^[0-9]+$‘; then
- echo "PHP-FPM Pid $pid Kill"
- else
- echo "$pid IS Not A PHP-FPM Pid"
- fi
- done
- }
- case $param in
- ‘start‘)
- start;;
- ‘stop‘)
- stop;;
- ‘restart‘)
- stop
- start;;
- *)
- echo "Usage: ./web.sh start|stop|restart";;
- esac
以上是关于mac 安装 php nginx mysql的主要内容,如果未能解决你的问题,请参考以下文章
全新安装Mac OSX 开发者环境 同时使用homebrew搭建 PHP,Nginx ,MySQL,Redis,Memcache ... ... (LNMP开发环境)
macOS monterey 12.6.1安装homebrew + nginx + php + mysql
macOS monterey 12.6.1安装homebrew + nginx + php + mysql