Linux系统有个让人蛋疼的通病,软件包依赖,好在当前主流的两大发行版本都自带了解决方案,Red hat/CentOS有yum,Ubuntu有apt-get
Mac os没有自带类似的东东,但有第三方支持:Homebrew,Homebrew简称brew,是Mac OSX上的软件包管理工具,能在Mac中方便的安装软件或者卸载软件,可以说Homebrew就是mac下的apt-get或yum
在Mac中打开Termal 输入命令
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"brew home
brew update
这会更新 Homebrew 自己,并且使得接下来的两个操作有意义
brew outdated
这回列出所有安装的软件里可以升级的那些
brew upgrade
升级所有可以升级的软件们
brew upgrade <xxx>
如果不是所有的都要升级,那就这样升级指定的
brew cleanup
清理不需要的版本极其安装包缓存
brew search 软件名,如brew search wget
正则查询 brew search /wge*/
brew info mysql
主要看具体的信息,比如目前的版本,依赖,安装后注意事项等
brew list
brew deps mysql
brew install 软件名
如
brew install wgetbrew install nginxbrew install mysqlbrew install php55brew install gitbrew remove 软件名
如brew remove wget
或 brew uninstall wget
这个相信很多人都已经用到过了,安装他人扩展的 brew 服务。由于 brew 和包含的包源都是通过 github 来管理,人为的维护管理,除了自己的源还允许别人的源添加进来。类似与 Ubuntu 的 ppa。好处在于只有我安装规定的方式把包丢到 github 上面就可以用了!
brew tap <gihhub_user/repo>这个命令也就是把一些库添加进来,brew有个默认库, 假如默认库中没有php
我们就可以这样把php添加进来
brew tap josegonzalez/php有时会出现多个库的情况 如安装php55时
Error: Formulae found in multiple taps:
* homebrew/php/php55
* josegonzalez/php/php55如果想去掉扩展的话可以使用命令
brew untap josegonzalez/php假如我们用brew 安装nginx
brew install nginx完成后brew会自动把nginx注册为服务
查询所有的服务
brew services list就会发现多了一个nginx
那么这样操作这些服务呢
brew services start nginxbrew services restart nginxbrew services stop nginxPHP开发环境也可以直接下载集成环境
下面用brew配置 PHP环境
brew install openssl
xcode-select --install先添加brew的PHP扩展库:
brew update
brew tap homebrew/dupes
brew tap homebrew/php
brew tap josegonzalez/homebrew-php
brew untap josegonzalez/php 可以使用 brew options php55 命令来查看安装php5.5的选项,这里我用下面的选项安装
brew install php55 --with-apache --with-gmp --with-imap --with-tidy --with-debug请注意: 如果你希望以
apache作为web server,编译时要加--with-apache;如果你的web server是nginx这类,就需要加上--with-fpm。
PHP编译过程中如果遇到
configure: error: Cannot find OpenSSL's <evp.h>错误,执行xcode-select --install重新安装一下Xcode Command Line Tools即可解决该错误
由于Mac自带了php和php-fpm,因此需要添加系统环境变量PATH来替代自带PHP版本:
echo 'export PATH="$(brew --prefix homebrew/php/php55)/bin:$PATH"' >> ~/.bash_profile #for php
echo 'export PATH="$(brew --prefix homebrew/php/php55)/sbin:$PATH"' >> ~/.bash_profile #for php-fpm
echo 'export PATH="/usr/local/bin:/usr/local/sbin:$PATH"' >> ~/.bash_profile #for other brew install soft
source ~/.bash_profile #更新配置php -v/usr/bin/php -v查看扩展
php -i | grep extension_dir发现版本已经是新安装的了 如果安装多个怎样切换
这种方式只能切大版本 也就是切5.5 ,5.6这种
要是切5.5.30 , 5.5.35 就不能这种方式了 就要用方式2
brew unlink php56
brew link php561) 安装php-version
brew install php-version然后执行
source $(brew --prefix php-version)/php-version.sh && php-version 52) 使用php-version
直接执行
php-version就可以看到现有的版本
然后使用以下命令切换即可
php-version 5.5.35再看php的版本,已经切换好了。
chmod -R 777 /tmp打开目录/usr/local/etc/php/5.5/
文本文档打开 php.ini 搜索session.save_path
设置为
session.save_path = "/tmp"打开配置文件
sudo vim /etc/apache2/httpd.conf把
LoadModule php5_module libexec/apache2/libphp5.so修改为
LoadModule php5_module /usr/local/Cellar/php55/5.5.35/libexec/apache2/libphp5.so可以在/Libary/WebServer/Documents/目录中建立个phpinfo.php来测试了
<?php phpinfo(); ?>重启apache
sudo apachectl restartsudo vi /etc/apache2/httpd.conf,打开Apche的配置文件httpd.conf中找到#Include /private/etc/apache2/extra/httpd-vhosts.conf,去掉前面的#,保存并退出 已开启虚拟主机功能。sudo vi /etc/apache2/extra/httpd-vhosts.conf,添加如下配置<VirtualHost *:80>
ServerName fqy.psvmc.cn
DocumentRoot "/Library/WebServer/Documents/fengqing"
ErrorLog "/private/var/log/apache2/fqy-error_log"
CustomLog "/private/var/log/apache2/fqy-access_log" common
<Directory />
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
</Directory>
</VirtualHost>/Library/WebServer/Documents文件夹下的项目就不能访问了,所以要添加下面的配置,把默认位置配置为虚拟主机就可以了<VirtualHost *:80>
ServerName localhost
DocumentRoot "/Library/WebServer/Documents"
ErrorLog "/private/var/log/apache2/localhost-error_log"
CustomLog "/private/var/log/apache2/localhost-access_log" common
<Directory />
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
</Directory>
</VirtualHost>sudo apachectl restart,重启Apachesudo vi /etc/hosts,打开hosts配置文件,加入127.0.0.1 fqy.psvmc.cn,这样就可以配置完成虚拟主机了,可以访问http://fqy.psvmc.cn了当然不想配置域名的话也可以设置其它的端口
设置域名有局限性 用别的电脑或手机 是无法访问的 所以推荐使用其他端口
Listen 9999
NameVirtualHost *:9999
<VirtualHost *:9999>
ServerName localhost
DocumentRoot "/Library/WebServer/Documents/fengqing"
ErrorLog "/private/var/log/apache2/fqy-error_log"
CustomLog "/private/var/log/apache2/fqy-access_log" common
<Directory />
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
</Directory>
</VirtualHost>sudo apachectl restart,重启Apachehttp://localhost:9999/访问了查看Apache的版本:sudo apachectl -v
Apache2.2
<Directory />
Order deny,allow
Deny from all
</Directory>Apache2.4
<Directory />
Require all denied
</Directory>Apache2.2
<Directory />
Order allow,deny
Allow from all
</Directory>Apache2.4
<Directory />
Require all granted
</Directory>Apache2.2
<Directory />
Order Deny,Allow
Deny from all
Allow from www.psvmc.cn
</Directory>Apache2.4
<Directory />
Require host www.psvmc.cn
</Directory>更多变化请查看
假如我的项目放在/Users/psvmc/Documents/php/fengqing目录中 其中psvmc是我电脑的用户名
然后添加如下配置
Listen 9999
NameVirtualHost *:9999
<VirtualHost *:9999>
ServerName localhost
DocumentRoot "/Users/psvmc/Documents/php/fengqing"
ErrorLog "/private/var/log/apache2/fqy-error_log"
CustomLog "/private/var/log/apache2/fqy-access_log" common
<Directory />
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order deny,allow
Allow from all
</Directory>
</VirtualHost>但发现无法访问http://localhost:9999/ 试了很多方法都不行
报以下错误
You don't have permission to access / on this server.有人说是修改项目文件夹的所有者
sudo chown -R _www:_www /Users/psvmc/Documents/php/fengqing但是我试后发现并不起作用
但修改所有者也是必要的 这样修改的话 就不用更改文件夹的权限了
chmod -R 775 /Users/psvmc/Documents/php/fengqing最后发现把文件共享打开就行了
文件共享打开方法
系统偏好设置 –> 共享 –> 文件共享钩上
然后添加网站所在的文件夹就可以了 这样网站就能访问了
直接安装官方的包
这里给个百度网盘的下载地址
但是并不推荐这样 因为安装容易卸载难啊
还是推荐用brew安装
安装
brew install mysql
unset TMPDIR
mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql获取当前登录用户名
whoami例如我的是psvmc
设置文件的拥有者
sudo chown -R psvmc /usr/local/var/mysql/启动mysql
mysql.server start上面的启动方式 电脑重启就失效了 所以可以以服务的形式启动
brew services start mysql最好给mysql设个密码,方法如下
mysqladmin -u root password 'root'phpmyadmin几乎是管理mysql最容易的web应用了吧,每次我都顺道装上。
phpMyAdmin 4.4.15.5,最新版本在我的PHP5.5.35下运行有问题/Library/WebServer/Documents/下 设置目录名字为phpmyadminphpmyadmin目录下创建一个可写的config目录http://localhost/phpmyadmin/setup,安装一个服务,最后保存(这里只需要输入帐号密码就够了)config下生成的config.inc.php移到phpmyadmin根目录下config这样就装好了,虽然可能有点小复杂,但是来一次就习惯了。
这里很可能会遇到2002错误,就是找不到mysql.sock的问题,用下面方法解决
sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock然后就可以通过http://localhost/phpmyadmin访问
当然也可以用brew安装(不过安装的是英文版的)
brew install phpmyadmin然后在apache的配置文件/etc/apache2/httpd.conf中添加配置
Alias /phpmyadmin /usr/local/share/phpmyadmin
<Directory /usr/local/share/phpmyadmin/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
<IfModule mod_authz_core.c>
Require all granted
</IfModule>
<IfModule !mod_authz_core.c>
Order allow,deny
Allow from all
</IfModule>
</Directory>然后就可以通过http://localhost/phpmyadmin访问
MongoDB可以说是最简单的一个,直接执行
brew install mongodb为PHP添加MongoDB模块
brew install php55-mongo启动方法
brew services start mongodb卸载
brew uninstall php55-mongo
brew uninstall mongodb重启Apache
sudo apachectl restart默认帐号密码都是admin
RockMongo是MongoDB很好用的一个web应用,安装也很容易
/Library/WebServer/Documents/下 设置目录名字为rockmongohttp://localhost/rockmongo即可