mac下快速安装php 5.4

手头的笔记本升级到了OS X 10.8了,但是偶尔还需要写点php调剂一下。看看自带的php版本?

PHP 5.3.13 with Suhosin-Patch (cli) (built: Jun 20 2012 17:05:20)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies

对于追新族来说,必须得升级到php 5.4才开心。借助homebrew很快完成升级:

安装过程

三行即可。


brew tap homebrew/dupes
brew tap josegonzalez/homebrew-php
brew install php54

这样安装的php路径在/usr/local/bin/php,版本信息:

/usr/local/bin/php -v
PHP 5.4.4 (cli) (built: Jul 27 2012 08:42:32)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies

如何安装Node.js

下面分别介绍在Mac, Ubuntu,Centos以及Windows下安装Node.js.

Mac

在Mac下,如果你喜欢用homebrew,那么只用一行就可以装好:

brew install node

否则,只能考虑手工安装了,步骤如下:

    1. 安装Xcode
    2. 安装git
    3. 运行下面的命令行编译node.js
      git clone git://github.com/joyent/node.git
      cd node
      ./configure
      make
      sudo make install

Ubuntu

    1. 安装依赖包
      sudo apt-get install g++ curl libssl-dev apache2-utils
      sudo apt-get install git-core
    2. 运行下面的命令行:
      git clone git://github.com/joyent/node.git
      cd node
      ./configure
      make
      sudo make install

Windows

用cygwin来安装node,步骤如下:

    1. 安装cygwin
    2. 在cygwin的目录下,运行setup.exe安装下面列表中的包
      • devel → openssl
      • devel → g++-gcc
      • devel → make
      • python → python
      • devel → git
    3. 运行cygwin
    4. 运行下面的命令行:
      git clone git://github.com/joyent/node.git
      cd node
      ./configure
      make
      sudo make install

Centos

yum install gcc-c++ openssl-devel
wget --no-check-certificate https://github.com/joyent/node/tarball/v0.3.3
tar -xzvf ry-node-v0.3.3-0-g57544ba.tar.gz
cd ry-node-v0.3.3-0-g57544bac1
./configure
make
make install

Hello Node.js!

写一段小程序例如hello_node.js来验证安装是否正确:

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello Node.js\n');
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');

用node来运行这段代码

node hello_node.js
Server running at http://127.0.0.1:8124/

现在,用浏览器打开 http://127.0.0.1:8124/ , 应该能够看到一条好消息。

参考文档

How to Install Node.js

Update

  • 补充了在centos上安装Node.js的步骤

mac下的tree命令

在默认安装安装的mac下没有找到tree命令,找了一下原来有个比较流氓的解决办法:

find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'

这个命令行跑起来类似平常tree的效果,比如:

.
|____extra
| |____httpd-autoindex.conf
| |____httpd-dav.conf
| |____httpd-default.conf
| |____httpd-info.conf
| |____httpd-languages.conf
| |____httpd-manual.conf
| |____httpd-mpm.conf
| |____httpd-multilang-errordoc.conf
| |____httpd-ssl.conf
| |____httpd-userdir.conf
| |____httpd-vhosts.conf
|____httpd.conf
|____magic
|____mime.types
|____original
| |____extra
| | |____httpd-autoindex.conf
| | |____httpd-dav.conf
| | |____httpd-default.conf
| | |____httpd-info.conf
| | |____httpd-languages.conf
| | |____httpd-manual.conf
| | |____httpd-mpm.conf
| | |____httpd-multilang-errordoc.conf
| | |____httpd-ssl.conf
| | |____httpd-userdir.conf
| | |____httpd-vhosts.conf
| |____httpd.conf
|____other
| |____bonjour.conf
| |____php5.conf
|____users

写一个alias到~/.bash_profile里,就更方便了:

alias tree="find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'"

Update

现在正在用的是homebrew安装的tree命令行。

brew install tree