威尼斯wns.9778官网 > 计算机教程 > MAC Lion 下安装php扩展 for XAMPP 之Redis

原标题:MAC Lion 下安装php扩展 for XAMPP 之Redis

浏览次数:194 时间:2019-07-05

      mac lion下自带的Apache,扩展很少,另外我自己尝试用php源码编译未通过,因为决定用一个集成的mamp,那就是xampp(一定要安装那个xampp开发包,不然编译php扩展的时候会出错)。在windows和Linux 下安装一些程序或者php的扩展资料很多,而关于mac最新版10.7.4的资料极少。顺便提下mac的好用的安装工具,一个是MacPort,一个是Homebrew.macport可能被墙,安装时可能会卡住。

Redis安装配置教程及phpredis扩展安装测试

1. 下载redis-2.8.17.tar.gz:http://download.redis.io/releases/redis-2.8.17.tar.gz;

  1. 编译安装配置如下:

[redis-2.8.17]# make
[redis-2.8.17]# make PREFIX=/usr/local/redis-2.8.17 install
[redis-2.8.17]# ln -s /usr/local/redis-2.8.17/bin/redis-benchmark /usr/bin/redis-benchmark
[redis-2.8.17]# ln -s /usr/local/redis-2.8.17/bin/redis-check-aof /usr/bin/redis-check-aof
[redis-2.8.17]# ln -s /usr/local/redis-2.8.17/bin/redis-check-dump /usr/bin/redis-check-dump
[redis-2.8.17]# ln -s /usr/local/redis-2.8.17/bin/redis-cli /usr/bin/redis-cli
[redis-2.8.17]# ln -s /usr/local/redis-2.8.17/bin/redis-server /usr/bin/redis-server
 
[redis-2.8.17]# cd utils
[utils]# ./install_server.sh
Welcome to the redis service installer
This script will help you easily set up a running redis server
 
Please select the redis port for this instance: [6379]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf] /usr/local/redis-2.8.17/conf/redis_6379.conf
Please select the redis log file name [/var/log/redis_6379.log] /usr/local/redis-2.8.17/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379] /usr/local/redis-2.8.17/data/6379
Please select the redis executable path [/usr/bin/redis-server]
Selected config:
Port          : 6379
Config file    : /usr/local/redis-2.8.17/conf/redis_6379.conf
Log file      : /usr/local/redis-2.8.17/log/redis_6379.log
Data dir      : /usr/local/redis-2.8.17/data/6379
Executable    : /usr/bin/redis-server
Cli Executable : /usr/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.接着开启AOF模式:appendonly yes:

############################## APPEND ONLY MODE ###############################
 
# By default Redis asynchronously dumps the dataset on disk. This mode is
# good enough in many applications, but an issue with the Redis process or
# a power outage may result into a few minutes of writes lost (depending on
# the configured save points).
#
# The Append Only File is an alternative persistence mode that provides
# much better durability. For instance using the default data fsync policy
# (see later in the config file) Redis can lose just one second of writes in a
# dramatic event like a server power outage, or a single write if something
# wrong with the Redis process itself happens, but the operating system is
# still running correctly.
#
# AOF and RDB persistence can be enabled at the same time without problems.
# If the AOF is enabled on startup Redis will load the AOF, that is the file
# with the better durability guarantees.
#
# Please check http://redis.io/topics/persistence for more information.
 
appendonly yes
 
# The name of the append only file (default: "appendonly.aof")
 
appendfilename "appendonly_6379.aof"通过redis服务命令重启下redis:

[redis-2.8.17]# /etc/init.d/redis_6379 --help
Please use start, stop, restart or status as first argument
[redis-2.8.17]# /etc/init.d/redis_6379 restart
Please use start, stop, restart or status as first argument3. 下载igbinary扩展包(redis扩展包–enable-redis-igbinary依赖igbinary扩展包):http://pecl.php.net/get/igbinary-1.2.1.tgz

[redis-2.8.17]# /usr/local/php/bin/phpize
[redis-2.8.17]# ./configure --with-php-config=/usr/local/php/bin/php-config  --enable-igbinary
[redis-2.8.17]# make && make install4. 下载redis扩展包:http://download.redis.io/releases/redis-2.8.17.tar.gz

[redis-2.8.17]# /usr/local/php/bin/phpize
[redis-2.8.17]# ./configure --with-php-config=/usr/local/php/bin/php-config  --enable-redis  --enable-redis-igbinary
[redis-2.8.17]# make && make install5. 修改php.ini配置:

; /usr/local/php/etc/php.ini
extension=igbinary.so
extension=redis.so6. 测试扩展是否正常加载:

[redis-2.8.17]# /usr/local/php/bin/php -m
[PHP Modules]
...
igbinary
...
redis
...
 
[Zend Modules]7. 测试代码如下:

<?php
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$count = $redis->dbSize();
echo "Redis has $count keysn";
 
$ret = $redis->get('test5');
var_dump($ret);8. 安装配置Redis WEB管理工具phpRedisAdmin:https://github.com/ErikDubbelboer/phpRedisAdmin

[phpredisadmin]# git clone https://github.com/ErikDubbelboer/phpRedisAdmin.git
[phpredisadmin]# cd phpRedisAdmin
[phpredisadmin]# git clone https://github.com/nrk/predis.git vendor然后配置相应nginx配置即可看到当前Redis服务状态:

图片 1 

至此redis环境配置就完成了。

Ubuntu 14.04下Redis安装及简单测试

Redis集群明细文档

Ubuntu 12.10下安装Redis(图文详解) Jedis连接Redis

Redis系列-安装部署维护篇

CentOS 6.3安装Redis

Redis安装部署学习笔记

Redis配置文件redis.conf 详解

Redis 的详细介绍:请点这里
Redis 的下载地址:请点这里

本文永久更新链接地址:

http://www.bkjia.com/Linuxjc/898705.htmlwww.bkjia.comtruehttp://www.bkjia.com/Linuxjc/898705.htmlTechArticleRedis安装配置教程及phpredis扩展安装测试 1. 下载redis-2.8.17.tar.gz:http://download.redis.io/releases/redis-2.8.17.tar.gz;

  1. 编译安装配置如下: [redis-2...

     下面进入正题,例如今天先安装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

本文由威尼斯wns.9778官网发布于计算机教程,转载请注明出处:MAC Lion 下安装php扩展 for XAMPP 之Redis

关键词:

上一篇:Bootstrap 垂直(默认)表单

下一篇:没有了