首次公布路径:phpredis的安装

非常久非常久没有写博文了,好多博文都没有整理完成,今天才抽时间整理完这一篇博文,希望能对大家有一定的帮助

首先对redis做个简单的介绍:

Redis 是全然开源免费的,遵守BSD协议,先进的key – value持久化产品。

它通常被称为数据结构server,由于值(value)能够是 字符串(String), 哈希(Map), 列表(list), 集合(sets)和 有序集合(sorted
sets)
等类型。

这是官网的中文翻译。英文的就不是必需写上来了,假设想看英文的,能够去redis.io上去看看,中文的能够去redis.cn看看

关于php-redis的安装和使用已经有非常多人写过去了。我在这里仅仅是完毕一个验证的过程

安装redis

wget http://download.redis.io/redis-stable.tar.gz

tar xvzf redis-stable.tar.gz

cd redis-stable

make

sudo make install  (假设是root用户能够不用sudo)

安装完成后,拷贝下配置文件redis.conf。这里是为了更方便的使用

sudo mkdir /etc/redis/

sudo cp redis.conf /etc/redis/

这时启动下redis看看,启动方法:

redis-server /etc/redis/redis.conf

启动后的界面效果:

geeknimo@bogon:~/Documents/phpredis$ redis-server /etc/redis/redis.conf

[16859] 07 Aug 10:05:30.292 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.

[16859] 07 Aug 10:05:30.293 # Redis can’t set maximum open files to 10032 because of OS error: Operation not permitted.

[16859] 07 Aug 10:05:30.293 # Current maximum open files is 1024. maxclients has been reduced to 4064 to compensate for low ulimit. If you need higher maxclients increase ‘ulimit -n’.

[16859] 07 Aug 10:05:30.293 # Warning: 32 bit instance detected but no memory limit set. Setting 3 GB maxmemory limit with ‘noeviction’ policy now.

_._

_.-“__ ”-._

_.-“ `. `_. ”-._ Redis 2.8.13 (00000000/0) 32 bit

.-“ .-“`. “`\/ _.,_ ”-._

( ‘ , .-` | `, ) Running in stand alone mode

|`-._`-…-` __…-.“-._|’` _.-’| Port: 6379

| `-._ `._ / _.-’ | PID: 16859

`-._ `-._ `-./ _.-’ _.-’

|`-._`-._ `-.__.-’ _.-’_.-’|

| `-._`-._ _.-’_.-’ | http://redis.io

`-._ `-._`-.__.-’_.-’ _.-’

|`-._`-._ `-.__.-’ _.-’_.-’|

| `-._`-._ _.-’_.-’ |

`-._ `-._`-.__.-’_.-’ _.-’

`-._ `-.__.-’ _.-’

`-._ _.-’

`-.__.-’

[16859] 07 Aug 10:05:30.308 # Server started, Redis version 2.8.13

[16859] 07 Aug 10:05:30.308 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add ‘vm.overcommit_memory = 1′ to /etc/sysctl.conf and then reboot or run the command ‘sysctl vm.overcommit_memory=1′
for this to take effect.

[16859] 07 Aug 10:05:30.308 * The server is now ready to accept connections on port 6379

假设想要后台执行,能够执行redis-server /etc/redis/redis.conf & ,或者改动配置文件/etc/redis/redis.conf中的daemonize设置为yes就可以。

设置为daemonize后。启动redis-server。并使用redis-cli对redis-server进行连接

redis-cli

连接成功后:

geeknimo@bogon:~/Documents/phpredis$ redis-cli

127.0.0.1:6379>

输入info查看:

127.0.0.1:6379> info

# Server

redis_version:2.8.13

redis_git_sha1:00000000

redis_git_dirty:0

redis_build_id:7331093c2c819968

redis_mode:standalone

os:Linux 3.2.0-29-generic-pae i686

arch_bits:32

multiplexing_api:epoll

gcc_version:4.6.3

process_id:16890

run_id:660fc790eb501ea29b01b8bb9551f4711ab5f151

tcp_port:6379

uptime_in_seconds:6

uptime_in_days:0

hz:10

lru_clock:14868319

config_file:/etc/redis/redis.conf

# Clients

connected_clients:1

client_longest_output_list:0

client_biggest_input_buf:0

blocked_clients:0

# Memory

used_memory:424880

used_memory_human:414.92K

used_memory_rss:1609728

used_memory_peak:424880

used_memory_peak_human:414.92K

used_memory_lua:22528

mem_fragmentation_ratio:3.79

mem_allocator:jemalloc-3.6.0

# Persistence

loading:0

rdb_changes_since_last_save:0

rdb_bgsave_in_progress:0

rdb_last_save_time:1407377241

rdb_last_bgsave_status:ok

rdb_last_bgsave_time_sec:-1

rdb_current_bgsave_time_sec:-1

aof_enabled:0

aof_rewrite_in_progress:0

aof_rewrite_scheduled:0

aof_last_rewrite_time_sec:-1

aof_current_rewrite_time_sec:-1

aof_last_bgrewrite_status:ok

aof_last_write_status:ok

# Stats

total_connections_received:1

total_commands_processed:0

instantaneous_ops_per_sec:0

rejected_connections:0

sync_full:0

sync_partial_ok:0

sync_partial_err:0

expired_keys:0

evicted_keys:0

keyspace_hits:0

keyspace_misses:0

pubsub_channels:0

pubsub_patterns:0

latest_fork_usec:0

# Replication

role:master

connected_slaves:0

master_repl_offset:0

repl_backlog_active:0

repl_backlog_size:1048576

repl_backlog_first_byte_offset:0

repl_backlog_histlen:0

# CPU

used_cpu_sys:0.00

used_cpu_user:0.00

used_cpu_sys_children:0.00

used_cpu_user_children:0.00

# Keyspace

这就表明redis服务启动成功了。至于优化嘛。后面的文章再说

接下来我们去配置php-redis

首先要安装git,php5,apache2,php5-dev

sudo apt-get install php5 php5-dev apache2

安装须要点时间

在php-redis源码文件夹下。运行

git clone https://github.com/nicolasff/phpredis.git

phpize

./configure

make && sudo make install

提示信息:

Installing shared extensions:     /usr/lib/php5/20121212+lfs/

共享库在上面提示的路径下

配置php-redis

在/var/www/html下创建index.php,里面写上例如以下内容:

<?php

phpinfo();

?

>

并在/etc/php5/mods-available下建立一个redis.ini,内容例如以下:

extension=redis.so

并在/etc/php5/apache2/conf.d和/etc/php5/cli/conf.d下建立一个与redis.ini的软链接,当中cli这个部分非常关键,否则php -m无法得到redis的不论什么模块信息,即无法成功载入使用phpredis

ln -s /etc/php5/mods-available/redis.ini /etc/php5/cli/conf.d/10-redis.ini

ln -s /etc/php5/mods-available/redis.ini /etc/php5/apache2/conf.d/10-redis.ini

重新启动apache2服务

sudo service apache2 restart

这里打开ubuntu相应的ip/index.php就能够看到php-redis的配置

Additional .ini files parsed /etc/php5/apache2/conf.d/05-opcache.ini, /etc/php5/apache2/conf.d/10-pdo.ini, /etc/php5/apache2/conf.d/10-redis.ini, /etc/php5/apache2/conf.d/20-json.ini, /etc/php5/apache2/conf.d/20-readline.ini

redis

Redis Support enabled
Redis Version 2.2.5

session

Session Support enabled
Registered save handlers files user redis
Registered serializer handlers php_serialize php php_binary wddx

有了这些信息后開始进行測试代码

建立testredis.php。内容例如以下:

<?php

$redis = new Redis();

$redis->connect(’127.0.0.1′,6379);

var_dump($redis->info());

?>

这时运行php testredis.php

能够在终端看到相应的内容

也能够在web端看到对应的内容了。

这样就算基本上搭建好了php-redis。

[Redis专辑][1]ubuntu12.04下安装php-redis的方法和步骤的更多相关文章

  1. 阿里云ubuntu12.04下安装使用mongodb

    阿里云ubuntu12.04下安装mongodb   apt-get install mongodb 阿里云ubuntu12.04下卸载mongodb,同时删除配置文件     apt-get pur ...

  2. Ubuntu12.04下安装sourcenavigator-NG4.5阅读源代码

    大家知道Windows下有一个很好的查看源代码的软件sourceinsight,使用sourceinsight查看Linux内核代码.嵌入式软件开发中的C语言项目源代码.驱动程序代码很是方便.在Lin ...

  3. Linux Ubuntu12.04下安装OpenCv2.4.10

    参考 http://blog.sina.com.cn/s/blog_53b0956801010lfu.html 捣鼓了一个晚上了,OpenCv还没装好,本来以为看个类似的比如Ubuntu安装OpenC ...

  4. Ubuntu12.04下安装NS3.25

    实验室项目的需求,要使用到NS3做仿真,使用实验室的电脑,Ubuntu12.04,版本比较低,建议大家使用16.04,这样安装依赖文件时不会出现版本过低的问题 (没管最后也安装成功了).下面就安装步骤 ...

  5. UBUNTU12.04下安装配置体验gnome3

    年. ubuntu12.04默认采用unity界面,但是自己更加喜欢gnome3的操作方式. 安装gnome3: sudo apt-get install  gnome-shell 其实安装成功后,注 ...

  6. ubuntu-12.04下安装postgresql

    2013-10-01 20:42:57|    moniter参考资料:Ubuntu 12.04下PostgreSQL-9.1安装与配置详解(在线安装)一.安装postgresqlbamboo@bam ...

  7. Ubuntu12.04下安装Subversion并进行配置

    Ubuntu下安装Subversion还是很简单的,只要输入sudo apt-get install Subversion就可以安装了. 主要的难点在于对权限的配置上. 安装完subversion后, ...

  8. ubuntu12.04 下安装matlab2012

    1.下载matlab2012a(例如:****.iso) 2.创建挂载目录 sudo mkdir /media/matlab 3.将当前目录切换到镜像文件的目录,然后将镜像文件挂载到刚刚创建的目录下 ...

  9. Ubuntu12.04 下安装Qt

    1.下载Qt Creator 链接  http://qt-project.org/downloads 选择 Qt Creator 2.8.0 for Linux/X11 32-bit (61 MB) ...

随机推荐

  1. Linux基础(vim)

    1.源文件到可执行文件经历了什么? gcc -E main.c -o(输出) main.i 第一阶段:预处理:加载了include文件 gcc -S main.i -o main.s 第二阶段:编译( ...

  2. 【Codeforces Round #457 (Div. 2) B】Jamie and Binary Sequence

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 把n分解成二进制的形式. n=2^a0+2^a1+...+2^a[q-1] 则固定就是长度为q的序列. 要想扩展为长为k的序列. 可 ...

  3. MyBatis学习总结(11)——MyBatis动态Sql语句

    MyBatis中对数据库的操作,有时要带一些条件,因此动态SQL语句非常有必要,下面就主要来讲讲几个常用的动态SQL语句的语法 MyBatis中用于实现动态SQL的元素主要有: if choose(w ...

  4. TYVJ P1153 间谍网络

    P1153 间谍网络 时间: 1000ms / 空间: 131072KiB / Java类名: Main 描述 由于外国间谍的大量渗入,国家安全正处于高度危机之中.如果A间谍手中掌握着关于B间谍的犯罪 ...

  5. 类名引用static变量好处

    不仅强调了变量static的结构,而且在有些情况下他还为编译器进行优化提供了更好的机会.

  6. 1.19 Python基础知识 - 软件目录开发规范及不同模块之间的调用

    一个软件项目的开发,除了需要很厉害的开发能力,同时在软件开发项目时,也需要对项目结构有良好的组织能力,将功能进行拆分,不同的功能放在不同的目录或文件中,方便日后的维护,升级等操作.比如核心代码的目录, ...

  7. 阅读笔记——Web应用程序

    Web应用程序与DD文件 Web应用程序 web应用程序是一种可以通过Web访问的应用程序.Web应用程序最大的好处是永和很容易访问应用程序.用户只需要有浏览器即可,不需要安装其他任何软件.一个Web ...

  8. Scala入门到精通——第二十九节 Scala数据库编程

    本节主要内容 Scala Mavenproject的创建 Scala JDBC方式訪问MySQL Slick简单介绍 Slick数据库编程实战 SQL与Slick相互转换 本课程在多数内容是在官方教程 ...

  9. 转换PHP脚本成为windows的执行程序

    转换PHP脚本成为windows的执行程序 Convert a PHP script into a stand-alone windows executable I want to automate ...

  10. 字串乱序 PHP&JS

    <?php /** * 字串乱序 PHP&JS * * php 中把字串乱序后输出给客户机的 JAVASCRIPT , JAVASCRIPT 中恢复 * 在指定长度提取一个字符,并把这一 ...