brew install php55redis,Mac下安装LNMP环境
Mac下搭建lamp開發(fā)環(huán)境很容易,有xampp和mamp現(xiàn)成的集成環(huán)境。但是集成環(huán)境對(duì)于經(jīng)常需要自定義一些配置的開發(fā)者來說會(huì)非常麻煩,而且Mac本身自帶apache和php,在brew的幫助下非常容易手動(dòng)搭建,可控性很高
Brew
brew對(duì)于mac,就像apt-get對(duì)于ubuntu,安裝軟件的好幫手,能方便更多…
brew的安裝方式如下:ruby?-e?"$(curl?-fsSL?https://raw.github.com/Homebrew/homebrew/go/install)"
brew常用選項(xiàng)brew?install?xxx
brew?uninstall?xxx
brew?list
brew?update?xxx
還有一個(gè)必須要安裝的就是os x 自身的命令行開發(fā)工具,否則后面的安裝也會(huì)出問題。xcode-select?--install??#?彈窗提示后,點(diǎn)擊“安裝”即可
Apache || Nginx
Apache
Apache的話使用mac自帶的基本就夠了,我的系統(tǒng)是10.9,可以使用以下命令控制Apachesudo?apachectl?start
sudo?apachectl?restart
sudo?apachectl?stop
唯一要改的是主目錄,mac默認(rèn)在home下有個(gè)sites(站點(diǎn))目錄,訪問路徑是http://localhost/~user_name
這樣很不適合做開發(fā)用,修改/etc/apache2/httpd.conf內(nèi)容DocumentRoot?"/Users/username/Sites"
Options?Indexes?MultiViews
AllowOverride?All
Order?allow,deny????Allow?from?all
這樣sites目錄就是網(wǎng)站根目錄了,代碼都往這個(gè)下頭丟
Nginx
要使用Nginx也比較方便,首先安裝brew?install?nginx
如果想開機(jī)就啟動(dòng)nginx,可以運(yùn)行下面命令:mkdir?-p?~/Library/LaunchAgentsln?-sfv?/usr/local/opt/nginx/*.plist?~/Library/LaunchAgents
想立馬run nginx的話,也可以手動(dòng)執(zhí)行:launchctl?load?~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
sudo?chown?root:wheel?~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
如果對(duì)launchctl不是太熟悉的話,也可以這么玩:(如果想要監(jiān)聽80端口,必須以管理員身份運(yùn)行)#打開?nginxsudo?nginx#重新加載配置|重啟|停止|退出?nginxnginx?-s?reload|reopen|stop|quit#測(cè)試配置是否有語(yǔ)法錯(cuò)誤nginx?-t
update:-03-30?:?after?upgrading?from?Mavericks?to?Yosemite?I?got?the?following?error:
/usr/local/var/run/nginx.pid?failed?(2?no?such?file?or?directory)
nginx:?[emerg]?mkdir()?"/usr/local/var/run/nginx/client_body_temp"?failed?(2:?No?such?file?or?directory)All?I?needed?to?do?to?solve?this?issue?was?to?create?the?folder:
mkdir?-p?/usr/local/var/run/nginx/client_body_temp
OK,?升級(jí)碰到的問題解決。
檢查是否run起來:http://localhost:8080??或者??http://localhost:80
配置Nginxcd?/usr/local/etc/nginx/mkdir?conf.d
修改Nginx配置文件#配置文件地址?/usr/local/etc/nginx/nginx.confvim?nginx.conf
主要修改位置是最后的includeworker_processes??1;??error_log???????/usr/local/var/log/nginx/error.log?warn;pid????????/usr/local/var/run/nginx.pid;events?{
worker_connections??256;}http?{
include???????mime.types;
default_type??application/octet-stream;
log_format??main??'$remote_addr?-?$remote_user?[$time_local]?"$request"?'
'$status?$body_bytes_sent?"$http_referer"?'
'"$http_user_agent"?"$http_x_forwarded_for"';
access_log??????/usr/local/var/log/nginx/access.log?main;
port_in_redirect?off;
sendfile????????on;
keepalive_timeout??65;
include?/usr/local/etc/nginx/conf.d/*.conf;
}
修改自定義文件vim?./conf.d/default.conf
增加一個(gè)監(jiān)聽端口server?{
listen???????80;
server_name??localhost;
root?/Users/username/Sites/;?#?該項(xiàng)要修改為你準(zhǔn)備存放相關(guān)網(wǎng)頁(yè)的路徑
location?/?{
index?index.php;
autoindex?on;
}
#proxy?the?php?scripts?to?php-fpm
location?~?\.php$?{
include?/usr/local/etc/nginx/fastcgi.conf;
fastcgi_intercept_errors?on;
fastcgi_pass???127.0.0.1:9000;
}???}
這個(gè)時(shí)候還不能訪問php站點(diǎn),因?yàn)檫€沒有開啟php-fpm。
雖然mac 10.9自帶了php-fpm,但是由于我們使用了最新的PHP,PHP中自帶php-fpm,所以使用PHP中的php-fpm可以保證版本的一致。
這里的命令在安裝完下一步的php后再執(zhí)行
sudo nginx
sudo php-fpm -D
PHP
PHP在mac下默認(rèn)安裝了,但是不好控制版本,利用brew可以再mac下安裝最新版本,甚至是多個(gè)版本,我裝了php5.5brew?tap?homebrew/dupes
brew?tap?josegonzalez/homebrew-php
brew?install?--without-apache?--with-fpm?--with-mysql?php55?#Nginx#brew?install?php55?#Apache
安裝成功后提示:#To?have?launchd?start?php55?at?login:
mkdir?-p?~/Library/LaunchAgents
ln?-sfv?/usr/local/opt/php55/*.plist?~/Library/LaunchAgents
#Then?to?load?php55?now:
launchctl?load?~/Library/LaunchAgents/homebrew.mxcl.php55.plist
然后修改php的cli路徑和apache使用的php模塊。在~/.bash_profile或.zshrc里頭加以下內(nèi)容#export?PATH="$(brew?--prefix?josegonzalez/php/php55)/bin:$PATH"?export?PATH="/usr/local/bin:/usr/local/sbin:$PATH"#執(zhí)行下面命令后,新的php版本生效source?~/.bash_profile#或者source?~/.zshrc
如果是apache就用剛剛安裝的php代替了系統(tǒng)默認(rèn)cli的php版本。然后在/etc/apache2/httpd.conf下增加LoadModule?php5_module?/usr/local/Cellar/php55/5.5.15/libexec/apache2/libphp5.so
這樣就對(duì)apache使用的php版本也進(jìn)行了修改。
后面會(huì)用到mongo和memcache等,所以可以直接利用下面命令安裝php模塊,其他模塊也類似brew?install?php55-memcache
brew?install?php55-memcached
brew?install?php55-redis
brew?install?php55-mongo
brew?install?php55-xdebug
brew?install?php55-mcrypt????#Laravel?框架依賴此擴(kuò)展brew?install?php55-xhprof????#php性能分析工具brew?install?php55-gearman
brew?install?php55-msgpack
brew?install?php55-phalcon
那么安裝后如何對(duì)php進(jìn)行管理呢(這里主要是重啟操作),可以制作一個(gè)腳本來管理(/usr/local/etc/php/fpm-restart):#!/bin/shecho?"Stopping?php-fpm..."launchctl?unload?-w?~/Library/LaunchAgents/homebrew.mxcl.php55.plist
echo?"Starting?php-fpm..."launchctl?load?-w?~/Library/LaunchAgents/homebrew.mxcl.php55.plist
echo?"php-fpm?restarted"exit?0
然后:chmod?ug+x?/usr/local/etc/php/fpm-restart
cd?/usr/local/sbin
ln?-s?/usr/local/etc/php/fpm-restart
MySQL
mac不自帶mysql,這里需要重新安裝,方法依然很簡(jiǎn)單brew?install?mysql
安裝后的提示:A?"/etc/my.cnf"?from?another?install?may?interfere?with?a?Homebrew-built
server?starting?up?correctly.To?connect:
mysql?-uroot#?開機(jī)登錄啟動(dòng)mysqlTo?have?launchd?start?mysql?at?login:
mkdir?-p?~/Library/LaunchAgents
ln?-sfv?/usr/local/opt/mysql/*.plist?~/Library/LaunchAgents
#?手動(dòng)開啟mysql
Then?to?load?mysql?now:
launchctl?load?~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
#非launchctl開啟方式
Or,?if?you?don't?want/need?launchctl,?you?can?just?run:
mysql.server?start
最好給mysql設(shè)個(gè)密碼,方法如下mysqladmin?-u?root?password?'xxx'
如果想修改mysql的配置,在/usr/local/etc下建立一個(gè)my.cnf,例如增加log[mysqld]general-log
general_log_file?=?/usr/local/var/log/mysqld.log
Memcachebrew?install?memcached
啟動(dòng)/停止指令memcached?-d
killall?memcached
加入開機(jī)啟動(dòng)cp?/usr/local/Cellar/memcached/1.4.20/homebrew.mxcl.memcached.plist?~/Library/LaunchAgents/
Redisbrew?install?redis
Redis默認(rèn)配置文件不允許以Deamon方式運(yùn)行,因此需要先修改配置文件vim?/usr/local/etc/redis.conf
將daemonize修改為yes,然后載入配置文件即可實(shí)現(xiàn)后臺(tái)進(jìn)程啟動(dòng)redis-server?/usr/local/etc/redis.conf
加入開機(jī)啟動(dòng)cp?/usr/local/Cellar/redis/2.8.19/homebrew.mxcl.redis.plist?~/Library/LaunchAgents/
設(shè)置別名
最后可以對(duì)所有服務(wù)的啟動(dòng)停止設(shè)置別名方便操作vim?~/.bash_profile
加入alias?nginx.start='launchctl?load?-w?~/Library/LaunchAgents/homebrew.mxcl.nginx.plist'alias?nginx.stop='launchctl?unload?-w?~/Library/LaunchAgents/homebrew.mxcl.nginx.plist'alias?nginx.restart='nginx.stop?&&?nginx.start'alias?php-fpm.start="launchctl?load?-w?~/Library/LaunchAgents/homebrew.mxcl.php55.plist"alias?php-fpm.stop="launchctl?unload?-w?~/Library/LaunchAgents/homebrew.mxcl.php55.plist"alias?php-fpm.restart='php-fpm.stop?&&?php-fpm.start'alias?mysql.start="launchctl?load?-w?~/Library/LaunchAgents/homebrew.mxcl.mysql.plist"alias?mysql.stop="launchctl?unload?-w?~/Library/LaunchAgents/homebrew.mxcl.mysql.plist"alias?mysql.restart='mysql.stop?&&?mysql.start'alias?redis.start="launchctl?load?-w?~/Library/LaunchAgents/homebrew.mxcl.redis.plist"alias?redis.stop="launchctl?unload?-w?~/Library/LaunchAgents/homebrew.mxcl.redis.plist"alias?redis.restart='redis.stop?&&?redis.start'alias?memcached.start="launchctl?load?-w?~/Library/LaunchAgents/homebrew.mxcl.memcached.plist"alias?memcached.stop="launchctl?unload?-w?~/Library/LaunchAgents/homebrew.mxcl.memcached.plist"alias?memcached.restart='memcached.stop?&&?memcached.start'
MongoDB
MongoDB可以說是最簡(jiǎn)單的一個(gè),直接執(zhí)行brew?install?mongodb
成功安裝后的提示:#開機(jī)啟動(dòng)To?have?launchd?start?mongodb?at?login:
ln?-sfv?/usr/local/opt/mongodb/*.plist?~/Library/LaunchAgents
#立刻運(yùn)行
Then?to?load?mongodb?now:
launchctl?load?~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
#如果不想加入到開機(jī)啟動(dòng),也可以收到運(yùn)行
Or,?if?you?don't?want/need?launchctl,?you?can?just?run:
mongod?--config?/usr/local/etc/mongod.conf
PHPMyAdmin
phpmyadmin幾乎是管理mysql最容易的web應(yīng)用了吧,每次我都順道裝上。
去官網(wǎng)下載最新的版本
- 解壓到~/Sites/phpmyadmin下
- 在phpmyadmin目錄下創(chuàng)建一個(gè)可寫的config目錄
- 打開http://localhost/phpmyadmin/setup,安裝一個(gè)服務(wù),最后保存(這里只需要輸入帳號(hào)密碼就夠了)
- 將config下生成的config.inc.php移到phpmyadmin根目錄下
- 刪除config
這樣就裝好了,雖然可能有點(diǎn)小復(fù)雜,但是來一次就習(xí)慣了。
這里很可能會(huì)遇到2002錯(cuò)誤,就是找不到mysql.sock的問題,用下面方法解決sudo?mkdir?/var/mysql
sudo?ln?-s?/tmp/mysql.sock?/var/mysql/mysql.sock
RockMongo
RockMongo是MongoDB很好用的一個(gè)web應(yīng)用,安裝也很容易去官網(wǎng)下載最新版本
解壓到~/Sites/rockmongo下
運(yùn)行http://localhost/rockmongo即可
完成
這樣就在mac下配置好一個(gè)php開發(fā)環(huán)境了,enjoy it!
原文鏈接:http://outofmemory.cn/php/mac-install-lnmp-env
總結(jié)
以上是生活随笔為你收集整理的brew install php55redis,Mac下安装LNMP环境的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: centos java 集成环境搭建,C
- 下一篇: php可以独立运行,【判断题】PHP不能