翻译:http://blog.frd.mn/install-nginx-php-fpm-mysql-and-phpmyadmin-on-os-x-mavericks-using-homebrew/

最近Ubuntu用着很不爽,首先是输入法很难用,所说搜狗发布了Ubuntu14.04的输入法,但是远远没有Win下的输入法好用。其次是没有qq,在公司喝同事交流很困难,虽说网页qq也可以聊天,但是传个文件就不行了。缺少很多应用,用Web版的用很难用。总之Ubuntu就是不爽。于是把家里尘封的Mac Mini搬到公司爽爽的写程序。

首先我把Mac升级到Mac10.10.1 OS X Yosemite(在App Store里可以免费升级)。然后Xcode也要升级到最新版Version6.1,最后安装(或更新) Xcode Command Line Tools.

安装Xcode Command Line Tools

打开终端,输入以下命令,回车,会弹出一个框,点击安装(或Install)继续。

xcode-select --install

安装完成后,打开Xcode,进入Preferences->Locations,查看Xcode Command Line Tools是否是最新版。

我的是这样的

确认你用的是Xcode 6.1!然后安装homebrew

Homebrew

Mac下的Homebrew相当于Linux下的apt-get、yum,可以获得最新版的各种安装包。

首先,你要Xquartz

curl http://xquartz-dl.macosforge.org/SL/XQuartz-2.7.7.dmg -o /tmp/XQuartz.dmg
open /tmp/XQuartz.dmg

然后用以下命令安装homebrew

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

安装完成后,运行以下命令检查是否安装成功

brew doctor

然后更新、升级下brew源

brew update && brew upgrade

PHP-FPM

因为brew默认不包含php-fpm,所以要先添加一个

brew tap homebrew/dupes
brew tap homebrew/php

然后运行以下命令安装php、php-fpm,可能会花较长时间。

brew install --without-apache --with-fpm --with-mysql php55

设置PHP CLI

如果你想在命令行下运行php,你需要更改下bash shell下的环境变量

# If you use Bash

echo 'export PATH="$(brew --prefix homebrew/php/php55)/sbin:$PATH"' >> ~/.bash_profile && . ~/.bash_profile

# If you use ZSH

echo 'export PATH="$(brew --prefix homebrew/php/php55)/sbin:$PATH"' >> ~/.zshrc && . ~/.zshrc

让php自动开启

mkdir -p ~/Library/LaunchAgents
cp /usr/local/opt/php55/homebrew.mxcl.php55.plist ~/Library/LaunchAgents/

运行php-fpm

launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php55.plist

确认php-fpm监听9000端口

lsof -Pni4 | grep LISTEN | grep php

输出如下

php-fpm 69659 frdmn 6u IPv4 0x8d8ebe505a1ae01 0t0 TCP 127.0.0.1:9000 (LISTEN)

php-fpm 69660 frdmn 0u IPv4 0x8d8ebe505a1ae01 0t0 TCP 127.0.0.1:9000 (LISTEN)

php-fpm 69661 frdmn 0u IPv4 0x8d8ebe505a1ae01 0t0 TCP 127.0.0.1:9000 (LISTEN)

php-fpm 69662 frdmn 0u IPv4 0x8d8ebe505a1ae01 0t0 TCP 127.0.0.1:9000 (LISTEN)

Mysql

运行以下命令安装Mysql

brew install mysql

设置自动重启

ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents

开启数据库服务

launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

安全设置

运行以下命令删除匿名用户,并且禁止root远程登录。

mysql_secure_installation

> Enter current password for root (enter for none):

如果没有设置root密码,直接回车。

> Change the root password? [Y/n]

回车,输入你的root密码。

> Remove anonymous users? [Y/n]

直接回车。

> Disallow root login remotely? [Y/n]

直接回车。

> Remove test database and access to it? [Y/n]

直接回车。

> Reload privilege tables now? [Y/n]

直接回车,刷新权限。

测试连接数据库

mysql -u root -p

输入root密码:

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

退出

/q
Bye

phpMyAdmin

首先需要安装autoconf

brew install autoconf

设置$PHP_AUTOCONF

# If you use Bash
echo 'PHP_AUTOCONF="'$(which autoconf)'"' >> ~/.bash_profile && . ~/.bash_profile # If you use ZSH
echo 'PHP_AUTOCONF="'$(which autoconf)'"' >> ~/.zshrc && . ~/.zshrc

安装phpMyAdmin

brew install phpmyadmin

Nginx

安装Nginx

brew install nginx

设置自启

sudo cp -v /usr/local/opt/nginx/*.plist /Library/LaunchDaemons/
sudo chown root:wheel /Library/LaunchDaemons/homebrew.mxcl.nginx.plist

测试Web服务器

启动nginx

sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.nginx.plist

现在默认监听8080端口,运行以下命令测试

curl -IL http://127.0.0.1:8080

输出:

HTTP/1.1 200 OK

Server: nginx/1.6.2

Date: Mon, 19 Oct 2014 19:07:47 GMT

Content-Type: text/html

Content-Length: 612

Last-Modified: Mon, 19 Oct 2014 19:01:32 GMT

Connection: keep-alive

ETag: “5444dea7-264”

Accept-Ranges: bytes

停止Nginx服务

sudo launchctl unload /Library/LaunchDaemons/homebrew.mxcl.nginx.plist

配置

创建nginx文件夹及配置文件

mkdir -p /usr/local/etc/nginx/logs
mkdir -p /usr/local/etc/nginx/sites-available
mkdir -p /usr/local/etc/nginx/sites-enabled
mkdir -p /usr/local/etc/nginx/conf.d
mkdir -p /usr/local/etc/nginx/ssl
sudo mkdir -p /var/www sudo chown :staff /var/www
sudo chmod 775 /var/www

Load PHP-Fpm

curl -L https://gist.github.com/frdmn/7853158/raw/php-fpm -o /usr/local/etc/nginx/conf.d/php-fpm

Create default virtual hosts

curl -L https://gist.github.com/frdmn/7853158/raw/sites-available_default -o /usr/local/etc/nginx/sites-available/default
curl -L https://gist.github.com/frdmn/7853158/raw/sites-available_default-ssl -o /usr/local/etc/nginx/sites-available/default-ssl
curl -L https://gist.github.com/frdmn/7853158/raw/sites-available_phpmyadmin -o /usr/local/etc/nginx/sites-available/phpmyadmin

设置 SSL

创建文件夹存放ssl证书和ssl key

mkdir -p /usr/local/etc/nginx/ssl

生成4096bit key和证书

openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 -subj "/C=US/ST=State/L=Town/O=Office/CN=localhost" -keyout /usr/local/etc/nginx/ssl/localhost.key -out /usr/local/etc/nginx/ssl/localhost.crt
openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 -subj "/C=US/ST=State/L=Town/O=Office/CN=phpmyadmin" -keyout /usr/local/etc/nginx/ssl/phpmyadmin.key -out /usr/local/etc/nginx/ssl/phpmyadmin.crt

Enable virtual hosts

ln -sfv /usr/local/etc/nginx/sites-available/default /usr/local/etc/nginx/sites-enabled/default
ln -sfv /usr/local/etc/nginx/sites-available/default-ssl /usr/local/etc/nginx/sites-enabled/default-ssl
ln -sfv /usr/local/etc/nginx/sites-available/phpmyadmin /usr/local/etc/nginx/sites-enabled/phpmyadmin

开启Nginx

sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.nginx.plist

Test

http://localhost → "Nginx works" page
http://localhost/info → phpinfo()
http://localhost/nope → " Not Found" page
https://localhost:443 → "Nginx works" page (SSL)
https://localhost:443/info → phpinfo() (SSL)
https://localhost:443/nope → "Not Found" page (SSL)
https://localhost:306 → phpMyAdmin (SSL)

配置命令文件

curl -L https://gist.github.com/frdmn/7853158/raw/bash_aliases -o /tmp/.bash_aliases
cat /tmp/.bash_aliases >> ~/.bash_aliases
# If you use Bash
echo "source ~/.bash_aliases" >> ~/.bash_profile
# If you use ZSH
echo "source ~/.bash_aliases" >> ~/.zshrc

Commands

Nginx

nginx.start
nginx.stop
nginx.restart

快速tail日志文件

nginx.logs.access
nginx.logs.default.access
nginx.logs.phpmyadmin.access
nginx.logs.default-ssl.access
nginx.logs.error
nginx.logs.phpmyadmin.error

查看Nginx配置

sudo nginx -t

PHP-FPM

php-fpm.start
php-fpm.stop
php-fpm.restart

查看PHP—FPM配置文件

php-fpm -t

Mysql

mysql.start
mysql.stop
mysql.restart

Mac OS X Mavericks or Yosemite 安装Nginx、PHP、Mysql、phpMyAdmin的更多相关文章

  1. 在Mac OS X 10.9上安装nginx

    1. 安装PCRE Download latest PCRE. After download go to download directory from terminal. $ cd ~/Downlo ...

  2. VMware Workstation 11 安装MAC OS X 10.10 Yosemite(14B25)图解 2015-01-13 12:26:01|

    VMware Workstation 11 安装MAC OS X 10.10 Yosemite(14B25)图解 2015-01-13 12:26:01|  分类: 网络互联 |  标签:10.10  ...

  3. Mac OS X Mavericks使用手册

    基本信息 作者: 施威铭研究室 出版社:清华大学出版社 ISBN:9787302386018 上架时间:2014-12-30 出版日期:2015 年1月 开本:16 版次:1-1 所属分类: 计算机 ...

  4. mac os x在PC上安装

    系统安装之前的准备工作及安装过程简介 前面我们已经提到,苹果电脑虽然已经采用了x86架构的Intel处理器,但其官方并不提供在非苹果电脑上安装Mac OS的支持.所以,要想在普通PC/笔记本电脑上安装 ...

  5. Mac OS X上搭建Apache、PHP、MySQL的Web服务器

    mac OS 系统太帅了,安装php的环境如此简单,大赞一个! 转载自http://jingyan.baidu.com/article/39810a23e1939fb636fda6a9.html 在M ...

  6. 在Mac OS X中配置Apache + PHP + MySQL

    在Mac OS X中配置Apache + PHP + MySQL Mac OS X 内置Apache 和 PHP,使用起来非常方便.本文以Mac OS X 10.6.3和为例.主要内容包括: 启动Ap ...

  7. 在Mac OS X中配置Apache + PHP + MySQL 很详细

    这是一篇超级详细的配置mac os下面php+mysql+apache的文章.非常详细我的大部分配置就是参考上面的内容的,比如,PHP不能连接数据库,就是改一下默认的php.ini中pdo_mysql ...

  8. Linux--YUM 安装 nginx php mysql

    Linux--YUM 安装 nginx php mysql (2011-11-13 11:27:14) 转载▼ 标签: 杂谈 分类: Linux 1.先新建一个 repo # vi /etc/yum. ...

  9. ubuntu12.04 安装nginx+php+mysql (lnmp)的web服务器环境

    1.Ubuntu12.04 安装nginx+php+mysql (lnmp)的web服务器环境 http://blog.db89.org/ubuntu12-04-install-nginx-php-m ...

随机推荐

  1. SQL学习之学会使用子查询

    1.SELECT语句是SQL的查询.我之前的随笔中所用的SELECT语句都是简单的查询,即从单个数据库表中检索数据的单条SELECT语句. 查询:任何SQL语句都是查询,但此术语一般指SELECT语句 ...

  2. 使用jsp标签和java资源管理实现jsp支持多语言

    1.编写一个Serverlet并设置服务器启动是初始化该Servlet,并在初始化方法中实现对java的资源加载: DispatcherServlet.java package mypack; imp ...

  3. ASP.NET MVC Controller向View传值方式总结

    Controller向View传值方式总结 总结发现ASP.NET MVC中Controller向View传值的方式共有6种,分别是: ViewBag ViewData TempData 向普通Vie ...

  4. 善于 调用Windows API

    前一段时间看见别人做的一个自动填写信息并且点击登录的程序,觉得很有意思. 其实就是在程序中调用Windows的API,那么如何调用,下面就做个简单的介绍. 写的简单粗暴, 不喜轻喷. 0.首先引入名称 ...

  5. Convert Sorted Array to Balanced Binary Search Tree (BST)

    (http://leetcode.com/2010/11/convert-sorted-array-into-balanced.html) Given an array where elements ...

  6. USACO Section 4.2 Drainage Ditches(最大流)

    最大流问题.ISAP算法.注意可能会有重边,不过我用的数据结构支持重边.距离d我直接初始化为0,也可以用BFS逆向找一次. -------------------------------------- ...

  7. springmvc中关于静态资源的放行

    参考:http://blog.csdn.net/fujiakai/article/details/52504525 方法1. 修改web.xml文件,增加对静态资源的url映射,要加在org.spri ...

  8. 树莓派高级GPIO库,wiringpi2 for python使用笔记(一)安装

    网上的教程,一般Python用RPi.GPIO来控制树莓派的GPIO,而C/C++一般用wringpi库来操作GPIO,RPi.GPIO过于简单,很多高级功能不支持,比如i2c/SPI库等,也缺乏高精 ...

  9. Auto login to your computer

    in run dialog, type in following words and enter Rundll32 netplwiz.dll,UsersRunDll On user account d ...

  10. HDU 5765 Bonds(状压DP)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5765 [题目大意] 给出一张图,求每条边在所有边割集中出现的次数. [题解] 利用状压DP,计算不 ...