安装brew:https://brew.sh/index_zh-cn.html
各种安装:http://blog.csdn.net/shichen501/article/details/52911873
- # 安装brew包管理工具
- /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- # 使用 Homebrew 安装 Apple 没有预装但 你需要的东西。
- brew install wget
安装完成之后,最后使用命令检测下 :
- brew doctor
相关命令:
- #更新源
- brew update
- #查找php5.6
- brew search php56
- #安装php5.6
- brew install php56
- #查看编译参数
- brew options php56
- #添加源
- brew tap xxxx
- #卸载
- brew uninstall php56
命令:
- #关闭老版本的PHP56或55或更早版本 进程
- brew unlink php56
- #开始安装PHP7
- brew install php70
- #开启PHP70进程
- brew link php70
- #输入命令,查看是否成功
- php -v
文件根目录
系统级的根目录
http://localhosts/
对应的文件目录是:
/Library/WebServer/Documents/
启用php:
/etc/apache2/httpd.conf
取消这一行前边的注释符号 #
LoadModule php5_module libexec/apache2/libphp5.so
重启 Apache
sudo apachectl restart
查看 Apache 信息
<?php phpinfo(); ?>
安装新版php:
- #卸载
- brew uninstall php56
- ##开始安装,添加源
- brew tap homebrew/php
- #或者:
- brew tap josegonzalez/homebrew-php
如果需要删除安装包
- brew untap xxxxx
安装php7.1.0
- brew install php71
安装完成之后,安装路径是/usr/local/Cellar/php71
修改环境变量,在/private/etc/bashrc最后添加:
- export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
修改/etc/apache2/httpd.conf:
- LoadModule php5_module libexec/apache2/libphp5.so
- #修改为
- LoadModule php7_module /usr/local/Cellar/php71/7.1.0-rc.1_4/libexec/apache2/libphp7.so
并在httpd.conf中最后添加以下代码:
- AddHandler php7-script php
- AddType application/x-httpd-php .php .php7
- AddType application/x-httpd-php-source .phps
php.ini文件在/usr/local/etc/php/7.1/php.ini
重启Apache
即可
- sudo apachectl restart
在根目录(/Library/WebServer/Documents/)中新建上传目录(up),需要可读可写可执行:
- sudo chmod 777 up
如果需要上传大文件,需要配置php.ini:
如果你已经有/private/etc/php.ini就不需要再拷贝一份php.ini.default出来了,如果没有,复制php.ini.default重命名为php.ini
配置php.ini文件 (以上传500M以下大小的文件为例) 查找以下选项并修改->
- #打开文件上传选项
- file_uploads = On ;
- #上传文件上限
- upload_max_filesize = 500M ;
如果要上传比较大的文件,仅仅以上两条还不够,必须把服务器缓存上限调大,把脚本最大执行时间变长
- # post上限
- post_max_size = 500M ;
- # Maximum execution time of each script, in seconds脚本最大执行时间
- max_execution_time = 1800 ;
- # Maximum amount of time each script may spend parsing request data
- max_input_time = 1800 ;
- # Maximum amount of memory a script may consume (128MB)内存上限
- memory_limit = 128M ;
安装apache
启动Apache
- #启动:
- sudo apachectl start
- #停止:
- sudo apachectl stop
- #重启:
- sudo apachectl restart
- #查看 Apache 版本
- httpd -v
浏览器打开 http://127.0.0.1 可以看到 It works! 的页面
注:mac自带apache,配置文件目录为/etc/apache2/httpd.conf,服务器目录/Library/Webserver/Documents
- sudo apachectl start/stop/restart
- # 查看服务是否打开
- curl -I 127.0.0.1:80
测试服务
- vim /Library/WebServer/Documents/index.php
输入:
- <?php
- phpinfo();
- ?>
浏览器访问127.0.0.1/index.php显示phpinfo信息则配置正确
- vim /etc/apache2/httpd.conf
常见问题
httpd: Could not reliably determine the server’s fully qualified domain name, using liuendedeMacBook-Pro.local. Set the ‘ServerName’ directive globally to suppress this message
解决方法:
将httpd.conf中ServerName的注释去掉,改为127.0.0.1:80
apache 打开重写在,配置本地域名的时候也要加上,AllowOverride All:
- sudo vim /etc/apache2/extra/httpd-vhosts.conf
- <VirtualHost *:80>
- ServerAdmin webmaster@dummy-host2.example.com
- DocumentRoot "/Users/yoyo/PhpstormProjects/flower/app/web"
- ServerName flower.ccc
- <Directory "/Users/yoyo/PhpstormProjects/flower/app">
- DirectoryIndex index.html index.htm index.php main.php
- # AllowOverride None
- AllowOverride All
- Order allow,deny
- Allow from all
- Require all granted
- </Directory>
- ErrorLog "/private/var/log/apache2/flower.com-error_log"
- CustomLog "/private/var/log/apache2/flower.com-access_log" common
- </VirtualHost>
安装phpMyadmin
下载地址:https://www.phpmyadmin.net/downloads/
解压重命名为phpMyadim复制到/Library/WebServer/Documents/
config.sample.inc.php,并命名为config.inc.php
浏览器访问127.0.0.1/phpMyadmin如果显示数据库登录界面则成功
常见问题
You don’t have permission to access /phpMyadmin/ on this server.
解决方法:在httpd.conf中增加DirectoryIndex index.php
安装mysql
- brew install mysql
配置初始设置
- mysql_secure_installation
运行后会报错:
- > mysql_secure_installation
- Securing the MySQL server deployment.
- Enter password for user root:
- Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
提示说找不到mysql.sock。原因是mysql进程还没启动。
- #启动mysql服务
- 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:
输入no,不验证密码,
y,删除匿名用户
n,是否允许
http://blog.csdn.net/lkxlaz/article/details/54580735
卸载mysql
由官网下载的dmg安装的mysql
- sudo rm /usr/local/mysql
- sudo rm -rf /usr/local/mysql*
- sudo rm -rf /Library/StartupItems/MySQLCOM
- sudo rm -rf /Library/PreferencePanes/My*
- rm -rf ~/Library/PreferencePanes/My*
- sudo rm -rf /Library/Receipts/mysql*
- sudo rm -rf /Library/Receipts/MySQL*
- sudo rm -rf /private/var/db/receipts/*mysql*
- #edit /etc/hostconfig and remove the line MYSQLCOM=-YES-
brew安装的mysql
- brew uninstall mysql
- brew cleanup
- launchctl unload -w
- #如果存在文件的话
- ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
- #如果存在的话
- rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
- #删除数据库文件
- sudo rm -rf /usr/local/var/mysql
在终端运行,彩色的shell:
- sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
编辑host文件
终端输入:
- sudo vi /etc/hosts
esc + :wq! 保存并退出
esc + wq! 不保存,退出
配置本地域名:
- sudo vi /etc/apache2/extra/httpd-vhosts.conf
运行“sudo vi /etc/hosts”,打开hosts配置文件,加入"127.0.0.1 dev.cloudlab.com",这样就可以配置完成sites虚拟主机了,可以访问“http://dev.cloudlab.com”了.
安装redis
- brew install redis
开机启动redis命令
- $ ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents
使用launchctl启动redis server
- $ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
使用配置文件启动redis server
- $ redis-server /usr/local/etc/redis.conf
停止redis server的自启动
- $ launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
redis 配置文件的位置
- /usr/local/etc/redis.conf
卸载redis和它的文件
- brewuninstallredis rm ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
测试redis server是否启动
- $ redis-cli ping