设为首页 收藏本站
查看: 809|回复: 0

[经验分享] MAC Lion 下安装php扩展 for XAMPP 之Redis

[复制链接]

尚未签到

发表于 2015-8-25 08:21:07 | 显示全部楼层 |阅读模式
  mac lion下自带的apache,扩展很少,另外我自己尝试用php源码编译未通过,因为决定用一个集成的mamp,那就是xampp(一定要安装那个xampp开发包,不然编译php扩展的时候会出错)。在windows和linux 下安装一些程序或者php的扩展资料很多,而关于mac最新版10.7.4的资料极少。顺便提下mac的好用的安装工具,一个是MacPort,一个是Homebrew.macport可能被墙,安装时可能会卡住。
  下面进入正题,例如今天先安装redis和php-redis。关于redis for mac的资料在https://github.com/antirez/redis ,顺便说下让redis开机自动运行的设置:http://naleid.com/blog/2011/03/05/running-redis-as-a-user-daemon-on-osx-with-launchd/ 说的很清楚。我还是引用过来作为参考,注意我加粗加红的地方。
  

  If you’re developing on the mac using redis and want it to start automatically on boot, you’ll want to leverage the OSX launchd system to run it as a User Daemon. A User Daemon is a non-gui program that runs in the background as part of the system. It isn’t associated with your user account. If you only want redis to launch when a particular user logs in, you’ll want to make a User Agent instead.
  From the command line, create a plist file as root in the /Library/LaunchDaemons directory with your favorite text editor:





sudo vim /Library/LaunchDaemons/io.redis.redis-server.plist
  Paste in the following contents and modify it to point it to wherever you’ve got redis-server installed and optionally pass the location of a config file to it (delete the redis.conf line if you’re not using one):





<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>io.redis.redis-server</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/redis-server</string>
<string>/usr/local/etc/redis.conf</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
  Make sure that you actually have a redis.conf file at the location above. If you’ve installed it withhomebrew that should be the correct location.
  You’ll then need to load the file (one time) into launchd with launchctl:





sudo launchctl load /Library/LaunchDaemons/io.redis.redis-server.plist
  Redis will now automatically be started after every boot. You can manually start it without rebooting with:





sudo launchctl start io.redis.redis-server
  You can also shut down the server with





sudo launchctl stop io.redis.redis-server
  Or you could add these aliases to your bash/zsh rc file:





alias redisstart='sudo launchctl start io.redis.redis-server'
alias redisstop='sudo launchctl stop io.redis.redis-server'
  If you’re having some sort of error (or just want to watch the logs), you can just fire up Console.app to watch the redis logs to see what’s going on.

  说了这么多,还没有开始安装php-redis.下面开始:
  首先用git从https://github.com/nicolasff/phpredis下载源码。然后依次执行以下命令:



sudo /Applications/XAMPP/xamppfiles/bin/phpize


sudo MACOSX_DEPLOYMENT_TARGET=10.7 CFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp" CCFLAGS="-arch i386 -arch x86_64 -g -Os -pipe" CXXFLAGS="-arch i386 -arch x86_64 -g -Os -pipe" LDFLAGS="-arch i386 -arch x86_64 -bind_at_load" ./configure --enable-redis --with-php-config=/Applications/XAMPP/xamppfiles/bin/php-config


sudo make && sudo make install
  然后修改php.ini(增加:extension=redis.so),重启xampp服务就可以了。
  
  示例代码
  
  <?php
  echo 'phpredis sample:<br />';
  
  error_reporting(E_ALL);
  ini_set('display_errors','ON');
  
  $redis = new Redis();
  $redis->connect('127.0.0.1',6379);
  $redis->set('first_key_phpredis', 'Hello world');
  
  );

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-103766-1-1.html 上篇帖子: PHP CGI 中 fix_pathinfo 引起的安全隐患 下篇帖子: php 采集修改技术方案simple_html_dom
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表