在《Mac OS X Mavericks 10.9安装及配置Homebrew》大致介绍Homebrew的安装。这里就能用上了。 Mac默认自带Apache、PHP,不过这些版本比较老一些。而如果想使用上Nginx、新版的PHP和MySQL,使用Homebrew来安装是个很不错的选择。而这这些软件版本在不断的更新中,所以一些配置也在不断变化中,但依据homebrew在安装过程的提示总能顺利的安装好这个配置。
安装Nginx
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
Mac-mini:~ weiz$ brew install nginx ... Docroot is: /usr/local/var/www The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that nginx can run without sudo. To have launchd start nginx at login: ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents Then to load nginx now: launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist Or, if you don't want/need launchctl, you can just run: nginx Mac-mini:~ weiz$ ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents /Users/weiz/Library/LaunchAgents/homebrew.mxcl.nginx.plist -> /usr/local/opt/nginx/homebrew.mxcl.nginx.plist Mac-mini:~ weiz$ sudo chown root:wheel /usr/local/Cellar/nginx/1.4.4/bin/nginx Password: Mac-mini:~ weiz$ sudo chmod u+s /usr/local/Cellar/nginx/1.4.4/bin/nginx Mac-mini:~ weiz$ vim /usr/local/etc/nginx/nginx.conf Mac-mini:~ weiz$ sudo nginx |
安装MySQL
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
Mac-mini:~ weiz$ brew info mysql mysql: stable 5.6.14 (bottled) http://dev.mysql.com/doc/refman/5.6/en/ Conflicts with: mariadb, mysql-cluster, percona-server Not installed From: https://github.com/mxcl/homebrew/commits/master/Library/Formula/mysql.rb ==> Dependencies Build: cmake ✘ ==> Options --enable-debug Build with debug support --enable-local-infile Build with local infile loading support --enable-memcached Enable innodb-memcached support --universal Build a universal binary --with-archive-storage-engine Compile with the ARCHIVE storage engine enabled --with-blackhole-storage-engine Compile with the BLACKHOLE storage engine enabled --with-embedded Build the embedded server --with-tests Build with unit tests ==> Caveats A "/etc/my.cnf" from another install may interfere with a Homebrew-built server starting up correctly. To connect: mysql -uroot To have launchd start mysql at login: ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents Then to load mysql now: launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist Or, if you don't want/need launchctl, you can just run: mysql.server start Mac-mini:~ weiz$ brew install mysql ==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/mysql-5.6.1 ... ==> Pouring mysql-5.6.14.mavericks.bottle.tar.gz ==> /usr/local/Cellar/mysql/5.6.14/bin/mysql_install_db --verbose --user=weiz ==> Caveats A "/etc/my.cnf" from another install may interfere with a Homebrew-built server starting up correctly. To connect: mysql -uroot To have launchd start mysql at login: ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents Then to load mysql now: launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist Or, if you don't want/need launchctl, you can just run: mysql.server start 配置MySQL随机启动服务: Mac-mini:~ weiz$ ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents /Users/weiz/Library/LaunchAgents/homebrew.mxcl.mysql.plist -> /usr/local/opt/mysql/homebrew.mxcl.mysql.plist 启动MySQL: Mac-mini:~ weiz$ mysql.server start Starting MySQL . SUCCESS! |
安装PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
Mac-mini:~ weiz$ brew tap homebrew/dupes &&brew tap homebrew/php Mac-mini:~ weiz$ brew install php55 --with-debug --with-fpm --with-gmp --with-homebrew-openssl --with-imap --with-intl --with-libmysql --without-bz2 --without-mysql --without-pcntl --without-pear ... ==> Installing php55 ... ==> Caveats The php.ini file can be found in: /usr/local/etc/php/5.5/php.ini ✩✩✩✩ Extensions(注意:根据以下提示配置PHP) ✩✩✩✩ If you are having issues with custom extension compiling, ensure that you are using the brew version, by placing /usr/local/bin before /usr/sbin in your PATH: PATH="/usr/local/bin:$PATH" PHP55 Extensions will always be compiled against this PHP. Please install them using --without-homebrew-php to enable compiling against system PHP. ✩✩✩✩ PHP CLI ✩✩✩✩ If you wish to swap the PHP you use on the command line, you should add the following to ~/.bashrc, ~/.zshrc, ~/.profile or your shell's equivalent configuration file: export PATH="$(brew --prefix josegonzalez/php/php55)/bin:$PATH" ✩✩✩✩ FPM ✩✩✩✩ To launch php-fpm(根据以下提示配置php-fpm随机启动服务) on startup: * If this is your first install: mkdir -p ~/Library/LaunchAgents cp /usr/local/Cellar/php55/5.5.6/homebrew-php.josegonzalez.php55.plist ~/Library/LaunchAgents/ launchctl load -w ~/Library/LaunchAgents/homebrew-php.josegonzalez.php55.plist * If this is an upgrade and you already have the homebrew-php.josegonzalez.php55.plist loaded: launchctl unload -w ~/Library/LaunchAgents/homebrew-php.josegonzalez.php55.plist cp /usr/local/Cellar/php55/5.5.6/homebrew-php.josegonzalez.php55.plist ~/Library/LaunchAgents/ launchctl load -w ~/Library/LaunchAgents/homebrew-php.josegonzalez.php55.plist The control script is located at /usr/local/Cellar/php55/5.5.6/sbin/php55-fpm Mountain Lion comes with php-fpm pre-installed, to ensure you are using the brew version you need to make sure /usr/local/sbin is before /usr/sbin in your PATH: PATH="/usr/local/sbin:$PATH" You may also need to edit the plist to use the correct "UserName". Please note that the plist was called 'org.php-fpm.plist' in old versions of this formula. 将PHP加入随机启动服务: To have launchd start php55 at login: ln -sfv /usr/local/opt/php55/*.plist ~/Library/LaunchAgents Then to load php55 now: launchctl load ~/Library/LaunchAgents/homebrew.mxcl.php55.plist ==> Summary /usr/local/Cellar/php55/5.5.6: 306 files, 39M, built in 4.6 minutes |
根据安装信息配置PHP环境
1 2 3 4 5 6 7 8 9 10 11 |
Mac-mini:~ weiz$ vim ~/.profile export PATH="$(brew --prefix josegonzalez/php/php55)/bin:$PATH" Mac-mini:~ weiz$ source ~/.profile Mac-mini:~ weiz$ vim ~/.bashrc export PATH="$(brew --prefix josegonzalez/php/php55)/bin:$PATH" Mac-mini:~ weiz$ source ~/.bashrc Mac-mini:~ weiz$ mkdir -p ~/Library/LaunchAgents Mac-mini:~ weiz$ cp /usr/local/Cellar/php55/5.5.6/homebrew-php.josegonzalez.php55.plist ~/Library/LaunchAgents/ Mac-mini:~ weiz$ launchctl load -w ~/Library/LaunchAgents/homebrew-php.josegonzalez.php55.plist Mac-mini:~ weiz$ ln -sfv /usr/local/opt/php55/*.plist ~/Library/LaunchAgents /Users/weiz/Library/LaunchAgents/homebrew-php.josegonzalez.php55.plist -> /usr/local/opt/php55/homebrew-php.josegonzalez.php55.plist |
配置Nginx
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
Mac-mini:~ weiz$ vim /usr/local/etc/nginx/nginx.conf #user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; client_max_body_size 20m; ##可以根据自己的实际需要去定义上传附件的大小 #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 logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.php index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/local/var/www$fastcgi_script_name; include /usr/local/etc/nginx/fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443; # server_name localhost; # ssl on; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_timeout 5m; # ssl_protocols SSLv2 SSLv3 TLSv1; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} } Mac-mini:~ weiz$ nginx -s reload #重启nginx |
到这里,安装基本完成了,如果需要管理一些管理MySQL的客户端工具,开源免费的SequelPro是个很不错的选择。