首先,需要安装brew,关于安装说明,请点此处
1、安装 Apache2.4
brew tap homebrew/apache
brew tap homebrew/php
brew install httpd24
2、安装 mysql
方法有两种,直接去官网下载dmg包,然后下一步,下一步,下一步安装了事。
也可以 brew install mysql 安装mysql-5.7
mysql.server start
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 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file // 这里提示选一个密码强度等级 Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1 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 ... Failed! Error: Your password does not satisfy the current policy requirements New password: Re-enter new password: Estimated strength of the password: 100 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, allowing anyone to log into MySQL without having to have 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 'localhost'. This ensures that someone cannot guess at the root password from the network. // 禁止远程root登录,我选的是不禁止。因为我的mac上的数据库不会放到公网上,也不会存什么敏感数据 Disallow root login remotely? (Press y|Y for Yes, any other key for No) : no ... skipping. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. // 这里删除默认自带的test数据库 Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y - 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!
最后测试一下登陆
mysql -u root -p ALL DONE!
3、安装 php7
brew install php71
安装php7.1最新版,
要安装其他扩展,可以使用brew search php71查看,需要什么brew install 什么.
4,运行配置apache2.4
配置文件在 /usr/local/etc/apache2/2.4/httpd.conf
vim /usr/local/etc/apache2/2.4/httpd.conf
加入下面内容
# ====php module==== LoadModule php7_module /usr/local/Cellar/php71/7.1.5_17/libexec/apache2/libphp7.so #如果已经有了就不用加了,没有就加上,根据自己的版本修改数字。
sudo httpd -k start
修改监听端口 默认的端口为8080,我们改为80:
Listen 80
修改root根目录
DocumentRoot “/Users/lonewolf/Public/dev/php/app”
<Directory “/Users/lonewolf/Public/dev/php/app”>
请自行修改为你的目录
配置mysql
使用默认的mysql配置启动时,会占用434M的内存,这个占用太多了,所以要修改一下。 配置路径为/usr/local/Cellar/mysql/5.6.23/my.cnf
。
# ========
skip-external-locking
key_buffer = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
# ========
这样启动之后就下降到100M以下了。
到这里,我们的安装和配置就完成了,不过有一点很不好,就是启动和停止这些服务都需要在命令行下输入,有没有图形化的管理界面呢? 有的,答案是LaunchRocket
,说这个之前我们先来了解一下另一个工具homebrew-cask
。
homebrew-cask
homebrew-cask是homebrew的一个扩展,用于安装图形界面mac程序,如google chrome
、QQ
等等。
- 安装
brew install caskroom/cask/brew-cask
- 使用
brew cask install google-chrome
具体的功能请翻阅官网。
LaunchRocket
LaunchRocket是管理homebrew所安装应用的一个管理器,它在系统设置中。 安装命令:
brew cask install launchrocket
在mac里面,启动1024以下的端口,需要用root权限才能启动,httpd需要选As Root才能真正运行起来。
到此,安装、配置、运行各方面都完成了。
其它工具
最后介绍两个有用的工具:
1、cakebrew
cakebrew是图形化管理homebrew的一个软件,也就是让你不用敲命令即可安装软件。
2、adminer
adminer是用php写的一个数据库管理工具,可以管理 MySQL, PostgreSQL, SQLite, MS SQL, Oracle, MongoDB等类型数据库,而且还是单文件,安装部署非常方便,支持多种语言。