Heim  >  Artikel  >  Datenbank  >  Mac OS X Mavericks or Yosemite 安装Nginx、PHP、Mysql、

Mac OS X Mavericks or Yosemite 安装Nginx、PHP、Mysql、

WBOY
WBOYOriginal
2016-06-07 16:41:591085Durchsuche

翻译:http://blog.frd.mn/install-nginx-php-fpm-mysql-and-phpmyadmin-on-os-x-mavericks-using-homebrew/ 最近Ubuntu用着很不爽,首先是输入法很难用,所说搜狗发布了Ubuntu14.04的输入法,但是远远没有Win下的输入法好用。其次是没有qq,在公司喝同事交

翻译: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是否是最新版。
我的是这样的
Bildschirmfoto-2014-10-20-um-11-27-56

确认你用的是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文件夹及配置文件

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:乐观锁和悲观锁Nächster Artikel:mysql 向 mariadb 平滑 过渡