MAC Lion 下安装php扩展 for XAMPP 之Redis
2012-07-07 17:54
726 查看
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
From the command line, create a plist file as root in the
Paste in the following contents and modify it to point it to wherever you’ve got
Make sure that you actually have a
You’ll then need to load the file (one time) into launchd with
Redis will now automatically be started after every boot. You can manually start it without rebooting with:
You can also shut down the server with
Or you could add these aliases to your bash/zsh rc file:
If you’re having some sort of error (or just want to watch the logs), you can just fire up
说了这么多,还没有开始安装php-redis.下面开始:
首先用git从https://github.com/nicolasff/phpredis下载源码。然后依次执行以下命令:
然后修改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');
);
下面进入正题,例如今天先安装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
launchdsystem 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/LaunchDaemonsdirectory 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-serverinstalled 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.conffile 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.appto 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');
);
相关文章推荐
- Windows下为PHP安装redis扩展
- 在mac上通过brew安装redis以及phpRedis扩展
- YUM安装PHP5.5及phpredis扩展
- Windows下Redis的安装及PHP扩展使用
- Redis php 扩展安装
- php redis扩展安装
- Centos系统安装 phpredis 扩展
- Windows7下为PHP安装redis扩展
- Redis安装整理(window平台) +php扩展redis
- php扩展redis模块安装
- Centos7下安装php-redis扩展及简单使用
- windows 上安装redis和windows上redis与php扩展
- Redis+PHP扩展的安装和Redis集群的配置 与 PHP负载均衡开发方案
- php安装redis扩展以及测试
- Redis---- 下载,安装,php扩展库
- windows下安装php5.5的redis扩展
- Fedora下安装php Redis扩展笔记
- Linux系统php安装Redis扩展的方法
- Linux下php安装Redis扩展
- Windows环境下的PHP如何安装Redis的扩展库?