Mac下通过 brew 安装不同版本的php

正 文:

    MAC OS X 10.9.5系统里已经自带了 apache  和 php ,只是默认没有启用,我们将他们启用即可。
    APACHE的默认版本是 Apache/2.2.26 (Unix),php版本是PHP 5.4.30。

    由于调试程序需要,我需要同时安装低版本的php5.3,但是又不希望删除系统预装的php 5.4,或升级/降级系统的php5.4,那么怎么办呢?这个时候,就可以通过brew的方式安装新的php版本。

    第一步,先安装 brew

    Brew 是 Mac 下面的包管理工具,通过 Github 托管适合 Mac 的编译配置以及 Patch,可以方便的安装开发工具。 Mac 自带ruby 所以安装起来很方便,同时它也会自动把git也给你装上。官方网站: http://brew.sh

    在mac下终端里直接输入命令行:

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

    安装完成之后,建议执行一下自检:brew doctor 如果看到Your system is ready to brew. 那么你的brew已经可以开始使用了。

    常用命令: (所有软件以PHP5.5为例子)

brew update                        #更新brew可安装包,建议每次执行一下
brew search php55                  #搜索php5.5
brew tap josegonzalez/php          #安装扩展<gihhub_user/repo>
brew tap                           #查看安装的扩展列表
brew install php55                 #安装php5.5
brew remove  php55                 #卸载php5.5
brew upgrade php55                 #升级php5.5
brew options php55                 #查看php5.5安装选项
brew info    php55                 #查看php5.5相关信息
brew home    php55                 #访问php5.5官方网站
brew services list                 #查看系统通过 brew 安装的服务
brew services cleanup              #清除已卸载无用的启动配置文件
brew services restart php55        #重启php-fpm

    第二步,安装PHP
    
     先添加brew的PHP扩展库:

brew update
brew tap homebrew/dupes
brew tap homebrew/php
brew tap josegonzalez/homebrew-php

    可以使用 brew options php53 命令来查看安装php5.3的选项,这里我用下面的选项安装:

brew install php53 --with-apache --with-gmp --with-imap --with-tidy --with-debug

     请注意:如果你希望以mac下的apache作为web server,编译时要加 --with-apache;如果你的web server 是 nginx这类,就需要加上 --with-fpm。

Options
--disable-opcache
Build without Opcache extension
--disable-zend-multibyte
Disable auto-detection of Unicode encoded scripts
--homebrew-apxs
Build against apxs in Homebrew prefix
--with-apache
Enable building of shared Apache 2.0 Handler module, overriding any options which disable apache
--with-cgi
Enable building of the CGI executable (implies --without-apache)
--with-debug
Compile with debugging symbols
--with-fpm
Enable building of the fpm SAPI executable (implies --without-apache)
--with-gmp
Build with gmp support
--with-homebrew-curl
Include Curl support via Homebrew
--with-homebrew-libxslt
Include LibXSLT support via Homebrew
--with-homebrew-openssl
Include OpenSSL support via Homebrew
--with-imap
Include IMAP extension
--with-libmysql
Include (old-style) libmysql support instead of mysqlnd
--with-mssql
Include MSSQL-DB support
--with-pdo-oci
Include Oracle databases (requries ORACLE_HOME be set)
--with-phpdbg
Enable building of the phpdbg SAPI executable (PHP 5.4 and above)
--with-postgresql
Build with postgresql support
--with-thread-safety
Build with thread safety
--with-tidy
Include Tidy support
--without-bz2
Build without bz2 support
--without-mysql
Remove MySQL/MariaDB support
--without-pcntl
Build without Process Control support
--without-pear
Build without PEAR
--without-snmp
Build without SNmp support
--HEAD
Install HEAD version

    PHP编译过程中如果遇到 configure: error: Cannot find OpenSSL's <evp.h> 错误,执行 xcode-select --install 重新安装一下 Xcode Command Line Tools 即可解决该错误(来源:https://github.com/Homebrew/homebrew-php/issues/1181)。

     安装完php后,会有一段提示,请仔细阅读:

Caveats
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php5_module    /usr/local/opt/php53/libexec/apache2/libphp5.so 

The php.ini file can be found in:
/usr/local/etc/php/5.3/php.ini

 

✩✩✩✩ PEAR ✩✩✩✩

 

If PEAR complains about permissions, 'fix' the default PEAR permissions and config:
chmod -R ug+w /usr/local/Cellar/php53/5.3.29/lib/php
pear config-set php_ini /usr/local/etc/php/5.3/php.ini

 

✩✩✩✩ Extensions ✩✩✩✩

 

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"

 

PHP
53 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 homebrew/php/php53)/bin:$PATH"

 

To have launchd start php53 at login:
 ln -sfv /usr/local/opt/php53/*.plist ~/Library/LaunchAgents
Then to load php53 now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.php53.plist
==> Summary
/usr/local/Cellar/php53/5.3.29: 480 files, 31M, built in 12.9 minutes


    
    等待PHP编译完成,开始安装PHP常用扩展,扩展安装过程中 brew会自动安装依赖包,使用 brew search php53- 命令,可以查看还有哪些扩展可以安装,然后执行 brew install php53-XXX 就可以了。 

    由于Mac自带了php和php-fpm,因此需要添加系统环境变量PATH来替代自带PHP版本:

echo 'export PATH="$(brew --prefix homebrew/php/php53)/bin:$PATH"' >> ~/.bash_profile  #for php
echo 'export PATH="$(brew --prefix homebrew/php/php53)/sbin:$PATH"' >> ~/.bash_profile  #for php-fpm
echo 'export PATH="/usr/local/bin:/usr/local/sbin:$PATH"' >> ~/.bash_profile #for other brew install soft
source ~/.bash_profile  #更新配置

    如何卸载安装的 php5.3呢?

# 卸载
brew uninstall php53
# 清除缓存以及老旧版本文件
brew cleanup -s

     测试一下效果:

$ php -v
PHP 5.3.29 (cli) (built: Jan 24 2015 12:40:58) (DEBUG)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2014 Zend Technologies 

# mac系统自带的php
$ /usr/bin/php -v
PHP 5.4.30 (cli) (built: Jul 29 2014 23:43:29)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
with Zend Guard Loader v3.3, Copyright (c) 1998-2013, by Zend Technologies

     由于我们没有安装php的fpm模式,所以 php-fpm -v 命令显示的是mac自带的:

$ php-fpm -v
PHP 5.4.30 (fpm-fcgi) (built: Jul 29 2014 23:44:15)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
with Zend Guard Loader v3.3, Copyright (c) 1998-2013, by Zend Technologies


 
    这个时候,我们使用 phpinfo 函数显示出来的php版本还是max自带的PHP5.4,需要我们修改 apache的配置文件 httpd.conf,加载的php5模块路径指向刚刚安装的 php5.3目录里的 libphp5.so:

LoadModule php5_module    /usr/local/opt/php53/libexec/apache2/libphp5.so

 
     重启apache,phpinfo() 脚本里显示的 php 版本就变成了 PHP Version 5.3.29。

【参考:】
全新安装Mac OSX 开发者环境 同时使用homebrew搭建 PHP,Nginx ,MySQL,Redis,Memcache ... ... (LNmp开发环境)
通过homebrew升级PHP至5.6

来源:飘易

 

golang cannot use nil as type string in return argument

 Forgive my noobness, but why can't I return nil for string return?

 
I get "cannot use nil as type string in return argument" with the following:
 
func nextLine(src *bufio.Reader) (string, os.Error) {
line, isPrefix, err := src.ReadLine()
// discard the rest of long lines
for isPrefix {
_, isPrefix, err = src.ReadLine()
}
if line == nil {
return nil, nil
}
if err != nil {
return nil, err
}
line_s := string(line)
return line_s, nil
}
 
答案:use "" for string nils.
 
 

2015阿里云最新代金券

快速访问阿里云: www.aliyun.com 

 

最新活动:深圳地区服务器优惠15%

IOS7以上navigationBar遮挡页面的解决方法.

在IOS7以上,navigationbar车档界面的解决方法.在viewDidload中.添加以下代码.

    if( ([[[UIDevice currentDevice] systemVersion] doubleValue]>=7.0)) 
        { self.edgesForExtendedLayout = UIRectEdgeNone;
         self.extendedLayoutIncludesOpaqueBars = NO;
         self.modalPresentationCapturesStatusBarAppearance = NO;
}

问题还有一些,添加代码后,发觉视图整体下移,但视图的宽高不变.谁有更好的方法,可以分享.

not present in DVTPlugInCompatibilityUUIDs

rance:src rance$ webrtc/build/gyp_webrtc

Updating projects from gyp files...

2015-05-06 22:15:19.041 xcodebuild[3603:35178] [MT] PluginLoading: Required plug-in compatibility UUID C4A681B0-4A26-480E-93EC-1218098B9AA0 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/VVDocumenter-Xcode.xcplugin' not present in DVTPlugInCompatibilityUUIDs

2015-05-06 22:15:19.042 xcodebuild[3603:35178] [MT] PluginLoading: Required plug-in compatibility UUID C4A681B0-4A26-480E-93EC-1218098B9AA0 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/ClangFormat.xcplugin' not present in DVTPlugInCompatibilityUUIDs

2015-05-06 22:15:19.119 xcodebuild[3604:35193] [MT] PluginLoading: Required plug-in compatibility UUID C4A681B0-4A26-480E-93EC-1218098B9AA0 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/VVDocumenter-Xcode.xcplugin' not present in DVTPlugInCompatibilityUUIDs

2015-05-06 22:15:19.121 xcodebuild[3604:35193] [MT] PluginLoading: Required plug-in compatibility UUID C4A681B0-4A26-480E-93EC-1218098B9AA0 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/ClangFormat.xcplugin' not present in DVTPlugInCompatibilityUUIDs

2015-05-06 22:15:20.128 xcodebuild[3606:35227] [MT] PluginLoading: Required plug-in compatibility UUID C4A681B0-4A26-480E-93EC-1218098B9AA0 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/VVDocumenter-Xcode.xcplugin' not present in DVTPlugInCompatibilityUUIDs

2015-05-06 22:15:20.130 xcodebuild[3606:35227] [MT] PluginLoading: Required plug-in compatibility UUID C4A681B0-4A26-480E-93EC-1218098B9AA0 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/ClangFormat.xcplugin' not present in DVTPlugInCompatibilityUUIDs

2015-05-06 22:15:20.199 xcodebuild[3608:35239] [MT] PluginLoading: Required plug-in compatibility UUID C4A681B0-4A26-480E-93EC-1218098B9AA0 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/VVDocumenter-Xcode.xcplugin' not present in DVTPlugInCompatibilityUUIDs

2015-05-06 22:15:20.200 xcodebuild[3608:35239] [MT] PluginLoading: Required plug-in compatibility UUID C4A681B0-4A26-480E-93EC-1218098B9AA0 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/ClangFormat.xcplugin' not present in DVTPlugInCompatibilityUUIDs

       追加DVTPlugInCompatibilityUUIDs

 

find ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins -name Info.plist | xargs -IFILE defaults write FILE DVTPlugInCompatibilityUUIDs -array-add A2E4D43F-41F4-4FB9-BB94-7177011C9AED
再次查看

find ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins -name Info.plist | xargs -IFILE defaults read FILE DVTPlugInCompatibilityUUIDs 

NameSilo优惠码及使用技巧

namesilo是icann认证的国外域名注册商,实力啊,信誉啊,那是肯定没问题的, 

如果我们熟悉海外的域名和主机商,大部分都会为了吸引新用户的使用发布优惠码,Namesilo也为了顺应潮流,在原本价格比较低的域名注册/续费和转移情况下,也会分享一些优惠信息。笔者也整理出来提供给大家使用。

NameSilo优惠码:
1、2015sale
2、2015domian
3、2015buy

以上三个优惠码为我们在新注册,续费或者转移域名时候都可以使用的,一个订单只能使用一个,一个账户只能使用1次。且每个优惠码只能优惠1美元,比如我们新购买一个.COM域名需要8.99美元,如果使用优惠码只需要7.99美元。

对于使用NameSilo优惠码有下面几个技巧和注意事项:

第一,一个账户只能用一次

鉴于本身官方的域名价格比较低,优惠促销不是官方的目的,但还是可以让用户稍微便宜一点的,所以每个账户只能使用一次优惠。如果你有多个账户,多个不同的付款方式,还是可以使用的。

PS:有些时候上面三个优惠码可以在一个账户使用,分三个订单使用。

第二,账户问题

如果我们需要用多个优惠,我们只能用不同账户和不同的付款方式,这样我们可以优惠不同的订单。

第三,官方目的

官方的目的不是为了优惠而促销的,如果我们在使用上述优惠后,不好再使用优惠,我个人认为新注册8.99,转入8.39这样的价格还是很便宜的。而且赠送隐私保护,是其他商家目前不可以超越的

Android程序启动问题

广播增加:android.intent.action.BOOT_COMPLETED ,APP会随着系统启动而已启动。

广播增加:android.intent.action.USER_PRESENT ,APP 会在解锁的时候启动。

 

过后的第三年

三年前,应该已过了三年吧!11,10,09;是的三年了。

现在想起来,后悔还是仇恨呢?都不是吧,对某人有点歉意吧,这么久了。虽然说出了实话,都没有真正说过对不起。

也许有人想问我为什么发这篇文章?一来,我真的很久没有写了,想写点什么,却不知道有什么好写的。每天都是工作工作还是工作,这是什么生活,我要的生活吗?二来,看到了以前我盗出的聊天记录。好吧,我承认三年前我想办法盗取了别人的QQ聊天记录。但我只看了两个人的,还有一个人的没有看。我也不知道那时候为什么只看了两个人的聊天记录,却今天看了。关于盗取别人的QQ,我就不说了吧。这个不是我们重点,也请大家不要来问我怎么盗QQ。我只想说,现在我真不会。QQ聊天记录我就不贴出来了,对大家都不好。在这我只是想说下,虽然当年我好像什么都不知道。回想下来,还是有好处的,至少这些人我不会再接触。早点在没付出最大的后果的时候经历下也许有好处。也认清了,表面合得来的男人也不是好人。跟你更近的女人,也不一定是一个好女人。

我承认我不会耍手段,我也想或者想学手段。在当今世界,黑手段太多了。像我这种小兵 想当一个企业领导者,现在看来还是太年轻了。

过于相信别人,以为一些都可以在自己的手中。然则一切都不是这样子。虽说跟某人磕磕绊绊四年多,但一直没伤害过我。有些人只有永恒的利益没有永恒的朋友,有些人只有永恒的的朋友没有永恒的利益。我希望我有永恒的的朋友。

再黑暗的过去也有阳光的那天,再痛苦的记忆也有释怀的那天。

我不会记恨谁,但我不会忘记,经历过的过去。你的,我的,还有他的,都会留在记忆中。

discuz URL伪静态版块目录化和贴子目录化

那么什么是扁平的树型网状结构呢?

例如:首页:http://www.XXX.com
      栏目页:
http://www.XXX.com/discuzx/ 
      内容页:
http://www.XXX.com/discuzx/m826/

像这样的页面就是一个“扁平的树型网状结构”。每增加一个内容页,都会给栏目页增加一定的权重。像地宝网的URL就是很规范的,整站URL目录化,目录层次不超过2个。对于SEO是很有利的。

那么现在discuz官方的地址是怎么样的呢?

首页:http://www.discuz.net/forum.php
栏目页:http://www.discuz.net/forum-21-1.html
内容页http://www.discuz.net/thread-2281986-1-1.html

这样的URL是分散的,并不是,不利于权重的传递。

在这里给大家提供一个方法,通过伪静态方法来实现discuzx的地址目录化(目前只支持Apache服务器)。

首先

打开source\function下的function_core.php

找到

    if($type == 'forum_forumdisplay') {

        list(,,, $fid, $page, $extra) = func_get_args();

        $r = array(

            '{fid}' => empty($_G['setting']['forumkeys'][$fid]) ? $fid : $_G['setting']['forumkeys'][$fid],

            '{page}' => $page ? $page : 1,

        );

    } elseif($type == 'forum_viewthread') {

        list(,,, $tid, $page, $prevpage, $extra) = func_get_args();

        $r = array(

            '{tid}' => $tid,

            '{page}' => $page ? $page : 1,

            '{prevpage}' => $prevpage && !IS_ROBOT ? $prevpage : 1,

        );

改为

if($type == 'forum_forumdisplay') {

        list(,,, $fid, $page, $extra) = func_get_args();

        $r = array(

            '{fid}' => empty($_G['setting']['forumkeys'][$fid]) ? $fid : $_G['setting']['forumkeys'][$fid],

            '{page}' => $page ,

        );

    } elseif($type == 'forum_viewthread') {        

        list(,,, $tid, $page, $prevpage, $extra) = func_get_args();

        $fid = DB::result_first("SELECT fid FROM ".DB::table('forum_thread')." WHERE tid = '$tid'");

        $r = array(

            '{fid}' => empty($_G['setting']['forumkeys'][$fid]) ? $fid : $_G['setting']['forumkeys'][$fid],

            '{tid}' => $tid,

            '{page}' => $page ,

            '{prevpage}' => $prevpage && !IS_ROBOT ? $prevpage : 1,

        );

然后进入网站后吧->''seo设置"->"url静态化"

在"论坛主题列表页"的格式中填写:{fid}/{page}

在"论坛主题内容页"的格式中填写:{fid}/m{tid}/{page}

然后下载.htaccess文件,传到网站根目录

htaccess.rar

然后工具,更新缓存,即实现了版块目录化,贴子目录化

在"论坛"-"版块管理"中的"绑定别名"即是版块目录名:

如: 版块中的"绑定别名"为"discuzx",那么访问地址就是:http://www.XXX.com/discuzx/

ubuntu php安装GD不支持JPEG

这几天在安装GD的时候,无法支持JPEG,Config都设置好了 还是有问题。

libjpeg62-dev  也装了 ,在config ,make 的时候都能过。最后phpinfo 看下,不支持,都支持PNG,为什么不支持JPEG呢

只好问下高手了,说应该是Path的问题

把以下内容加到etc/ld.so.conf,如没有找到,先运行下 ldconfig

 

/usr/local/lib
/usr/lib
/usr/lib64
/lib
/lib64
 

然后make clean 下,最后再重新编译下。OK了,哈哈