brew 又叫Homebrew,是Mac OSX上的软件包管理工具,能在Mac中方便的安装软件或者卸载软件, 只需要一个命令, 非常方便
brew类似ubuntu系统下的apt-get的功能
安装brew
brew 的官方网站: http://brew.sh/ 在官方网站对brew的用法进行了详细的描述
安装方法: 在Mac中打开Termal: 输入命令:
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
不知道为什么, 在国内经常被屏蔽
使用brew安装软件
一个命令就搞定了, 比如安装git
brew install git
比如安装wget
brew install wget
使用brew卸载软件
卸载更方便了
brew uninstall wget
使用brew查询软件
有时候,你不知道你安装的软件的名字, 那么你需要先搜索下, 查到包的名字。
比如我要安装
brew search /wge*/
/wge*/是个正则表达式, 需要包含在/中
其他brew命令
brew list 列出已安装的软件
brew update 更新brew
brew home 用浏览器打开brew的官方网站
brew info 显示软件信息
brew deps 显示包依赖
brew upgrade 升级
升级完毕后,会有一个summary(总结) 及 Caveats(注意事项),如:
php5.6
==> php@5.6
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php5_module /usr/local/opt/php@5.6/lib/httpd/modules/libphp5.so
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
Finally, check DirectoryIndex includes index.php
DirectoryIndex index.php index.html
The php.ini and php-fpm.ini file can be found in:
/usr/local/etc/php/5.6/
php@5.6 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.
If you need to have php@5.6 first in your PATH run:
echo 'export PATH="/usr/local/opt/php@5.6/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/usr/local/opt/php@5.6/sbin:$PATH"' >> ~/.zshrc
For compilers to find php@5.6 you may need to set:
export LDFLAGS="-L/usr/local/opt/php@5.6/lib"
export CPPFLAGS="-I/usr/local/opt/php@5.6/include"
To have launchd start php@5.6 now and restart at login:
brew services start php@5.6
Or, if you don't want/need a background service you can just run:
php-fpm
php7.0
==> php@7.0
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php7_module /usr/local/opt/php@7.0/lib/httpd/modules/libphp7.so
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
Finally, check DirectoryIndex includes index.php
DirectoryIndex index.php index.html
The php.ini and php-fpm.ini file can be found in:
/usr/local/etc/php/7.0/
php@7.0 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.
If you need to have php@7.0 first in your PATH run: //如 果需要在路径(命令行)中使用,请执行下面这条语句
echo 'export PATH="/usr/local/opt/php@7.0/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/usr/local/opt/php@7.0/sbin:$PATH"' >> ~/.zshrc
For compilers to find php@7.0 you may need to set:
export LDFLAGS="-L/usr/local/opt/php@7.0/lib"
export CPPFLAGS="-I/usr/local/opt/php@7.0/include"
To have launchd start php@7.0 now and restart at login:
brew services start php@7.0
Or, if you don't want/need a background service you can just run:
php-fpm
系统中正在使用的版本php7.2
==> php
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php7_module /usr/local/opt/php/lib/httpd/modules/libphp7.so
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
Finally, check DirectoryIndex includes index.php
DirectoryIndex index.php index.html
The php.ini and php-fpm.ini file can be found in:
/usr/local/etc/php/7.2/
To have launchd start php now and restart at login:
brew services start php
Or, if you don't want/need a background service you can just run:
php-fpm
注意:
切换版本步骤:
- 执行PHP切换命令,如下brew-php-switcher.
- 修改apache的配置文件httpd.conf,即可在phpinfo()中,看到对应的PHP版本
- 修改命令行下的PHP版本,执行对应版本的echo语句
echo 'export PATH="/usr/local/opt/php@7.0/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/usr/local/opt/php@7.0/sbin:$PATH"' >> ~/.zshrc
- 重启服务器,如果不起作用,重启下电脑
mac下使用命令切换PHP版本,使用brew-php-switcher工具
brew-php-switcher 5.6
brew-php-switcher 7.0
brew-php-switcher 7.1
brew-php-switcher 7.2
修改apache下的http.conf配置文件信息,以对应环境中的PHP版本
LoadModule php5_module /usr/local/opt/php@5.6/lib/httpd/modules/libphp5.so
#LoadModule php7_module /usr/local/opt/php@7.0/lib/httpd/modules/libphp7.so
#LoadModule php7_module /usr/local/opt/php@7.1/lib/httpd/modules/libphp7.so
#LoadModule php7_module /usr/local/opt/php@7.2/lib/httpd/modules/libphp7.so
参考文档:http://www.jb51.net/os/MAC/101860.html
安装完成后的记录参考:主要有Extensions \ PHP CLI \ PHP-FPM
The php.ini file can be found in:
/usr/local/etc/php/7.2/php.ini
✩✩✩✩ Extensions ✩✩✩✩
If you are having issues with custom extension compiling, ensure that you are using the brew version, by placing /usr/local/bin before /usr/sbin in your PATH:
PATH="/usr/local/bin:$PATH"
PHP72 Extensions will always be compiled against this PHP. Please install them using --without-homebrew-php to enable compiling against system PHP.
✩✩✩✩ PHP CLI ✩✩✩✩
If you wish to swap the PHP you use on the command line, you should add the following to ~/.bashrc, ~/.zshrc, ~/.profile or your shell's equivalent configuration file:
export PATH="$(brew --prefix homebrew/php/php72)/bin:$PATH"
✩✩✩✩ FPM ✩✩✩✩
To launch php-fpm on startup:
mkdir -p ~/Library/LaunchAgents
cp /usr/local/opt/php72/homebrew.mxcl.php72.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php72.plist
The control script is located at /usr/local/opt/php72/sbin/php72-fpm
OS X 10.8 and newer come with php-fpm pre-installed, to ensure you are using the brew version you need to make sure /usr/local/sbin is before /usr/sbin in your PATH:
PATH="/usr/local/sbin:$PATH"
You may also need to edit the plist to use the correct "UserName".
Please note that the plist was called 'homebrew-php.josegonzalez.php72.plist' in old versions of this formula.
With the release of macOS Sierra the Apache module is now not built by default. If you want to build it on your system you have to install php with the --with-httpd option. See brew options php72 for more details.
To have launchd start homebrew/php/php72 now and restart at login:
brew services start homebrew/php/php72
==> Summary
🍺 /usr/local/Cellar/php72/7.2.0_11: 350 files, 46.6MB
➜ ~ export PATH="$(brew --prefix homebrew/php/php72)/bin:$PATH"
➜ ~ php -v
PHP 7.2.0 (cli) (built: Dec 3 2017 21:47:51) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2017 Zend Technologies
作者:A奔跑的小农场主
链接:https://www.jianshu.com/p/704e9b1712e9
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。
nginx
==> nginx
Docroot is: /usr/local/var/www
The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.
nginx will load all files in /usr/local/etc/nginx/servers/.
To have launchd start nginx now and restart at login:
brew services start nginx
Or, if you don't want/need a background service you can just run:
nginx
mysql 说明了mysql的密码以及启动方式
==> 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
mqsql连接的一些坑及填坑方法
使用命令mysql -uroot
启动了mysql,但是不能操作数据,提示如下:
('mysql.infoschema'@'localhost') does not exist
~ brew services start mysql
==> Successfully started `mysql` (label: homebrew.mxcl.mysql)
➜ ~
➜ ~ mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.12 Homebrew
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
ERROR 1449 (HY000): The user specified as a definer ('mysql.infoschema'@'localhost') does not exist
然后,决定使用命令mysql_secure_installation
来启动mysql,并填写密码,提示... Failed! Error: Table 'mysql.role_edges' doesn't exist
:
mysql_secure_installation
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD COMPONENT 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 component?
Press y|Y for Yes, any other key for No: y
The password validation component is not available. Proceeding with the further steps without the component.
Please set the password for root here.
New password:
Re-enter new password:
... Failed! Error: Table 'mysql.role_edges' doesn't exist
解决办法,升级mysql:
mysql_upgrade -u root -p;
如下:
➜ ~ mysql_upgrade -uroot
Checking if update is needed.
Checking server version.
Running queries to upgrade MySQL server.
Upgrading system table data.
Checking system database.
mysql.columns_priv OK
mysql.component OK
mysql.db OK
mysql.default_roles OK
mysql.engine_cost OK
mysql.func OK
mysql.general_log OK
mysql.global_grants OK
mysql.gtid_executed OK
mysql.help_category OK
mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.innodb_index_stats OK
mysql.innodb_table_stats OK
mysql.ndb_binlog_index OK
mysql.password_history OK
mysql.plugin OK
mysql.procs_priv OK
mysql.proxies_priv OK
mysql.role_edges OK
mysql.server_cost OK
mysql.servers OK
mysql.slave_master_info OK
mysql.slave_relay_log_info OK
mysql.slave_worker_info OK
mysql.slow_log OK
mysql.tables_priv OK
mysql.time_zone OK
mysql.time_zone_leap_second OK
mysql.time_zone_name OK
mysql.time_zone_transition OK
mysql.time_zone_transition_type OK
mysql.user OK
Found outdated sys schema version 1.5.1.
Upgrading the sys schema.
Checking databases.
sys.sys_config OK
Upgrade process completed successfully.
Checking if update is needed.
再次使用密码登录,第一步设置密码,第二步移除anonymous user,禁止root远程登录,删除测试数据等:
➜ ~ mysql_secure_installation
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD COMPONENT 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 component?
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: 0
Please set the password for root here.
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) :
... skipping.
Normally, root should only be allowed to connect from
'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) :
... 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.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) :
... skipping.
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) :
... skipping.
All done!
再次使用密码登录,进行查询等操作,可正常使用:
➜ ~ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 22
Server version: 8.0.12 Homebrew
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.12 |
+-----------+
1 row in set (0.00 sec)
mysql升级参考文档:
~ brew install httpd
...
...
...
🍺 /usr/local/Cellar/nghttp2/1.33.0: 33 files, 6.3MB
==> Installing httpd
==> Downloading https://homebrew.bintray.com/bottles/httpd-2.4.34.high_sierra.bo
######################################################################## 100.0%
==> Pouring httpd-2.4.34.high_sierra.bottle.tar.gz
==> Caveats
DocumentRoot is /usr/local/var/www.
The default ports have been set in /usr/local/etc/httpd/httpd.conf to 8080 and in
/usr/local/etc/httpd/extra/httpd-ssl.conf to 8443 so that httpd can run without sudo.
To have launchd start httpd now and restart at login:
brew services start httpd
Or, if you don't want/need a background service you can just run:
apachectl start
==> Summary
🍺 /usr/local/Cellar/httpd/2.4.34: 1,633 files, 26.6MB
==> Caveats
==> httpd
DocumentRoot is /usr/local/var/www.
The default ports have been set in /usr/local/etc/httpd/httpd.conf to 8080 and in
/usr/local/etc/httpd/extra/httpd-ssl.conf to 8443 so that httpd can run without sudo.
To have launchd start httpd now and restart at login:
brew services start httpd
Or, if you don't want/need a background service you can just run:
apachectl start
apache和PHP的结合文档:
外国友人的博客: