Memcached on 1and1
Installing Memcached and Libevent
I am going to demonstrate using my shared server on 1and1. This will work on any Linux server which you have shell access to (can be via SSH).
I will use '/kunden/homepages/13/d155370874/htdocs/' as my root directory, because that's the root of what I have access to on my shared server To find your working directory, use
--------------------------
$ pwd
----------------------------
Removing an old libevent
Removing libevent is easy:
-----------------------------------
# apt-get remove --purge libevent1
------------------------------------
Note: That's the number one on the end... it looks a lot like the letter L.
Now check to make sure everything is gone:
---------------------------------------------------
# locate libevent
/var/cache/apt/archives/libevent1_1.1a-1_i386.deb
---------------------------------------------------
First get via (wget) the latest version of libevent available. Then unzip it and install it. I use prefix to install it in my shared directory, because I don't have write access in the usual location for such stuff.
注意:在安装前, ./configure 要将安装路径设置到一个新的文件夹libevent中,而非现在的libevent-1.4.5-stable,否者make install 报错。
原因:不明
--------------------------------------------------------------------
$ wget http://www.monkey.org/~provos/libevent-1.4.5-stable.tar.gz
$ tar -zvxf libevent-*gz
$ cd libevent-*
$ ./configure --prefix=$HOME/libevent
$ make
$ make install
$ cd
---------------------------------------------------------------------
Then get Memcached and install giving it the directory where you installed libevent. (Note: on 1and1 I could only get version 1.1.12 to work; not the latest version; I don't know why)
I didn't have any problem using memcached-1.2.5 (latest at time of this writing) --Merles 18:59, 29 June 2008 (EDT)
----------------------------------------------------------------------
$ wget http://www.danga.com/memcached/dist/memcached-1.2.5
$ tar -zvxf memcached-*
$ cd memcached-*
$ ./configure --prefix=$HOME/memcached --with-libevent=$HOME/libevent
$ make
$ make install
-----------------------------------------------------------------------
Start Memcached
If your server gets restarted, you might have to redo these steps.
------------------------------------------------------------------
$ cd memcached #(the directory where you installed memcached)
$ cd bin
$ ldd memcached
------------------------------------------------------------------
That will output:
libevent-1.3b.so.1 => not found
libc.so.6 => /lib/tls/libc.so.6 (0x00a55000)
/lib/ld-linux.so.2 (0x00a3c000)
Now type (substuting where you installed libevent if needed):
--------------------------------------------------------------
$ export LD_LIBRARY_PATH=$HOME/libevent/lib:$LD_LIBRARY_PATH
$ ldd memcached
--------------------------------------------------------------
That will output: (Notice the path to libevent is now there)
libevent-1.3b.so.1 => /kunden/homepages/13/d155370874/htdocs/libevent-1.3b/lib/libevent-1.3b.so.1 (0x0061f000)
libc.so.6 => /lib/libc.so.6 (0x00a55000)
/lib/ld-linux.so.2 (0x00a3c000)
Start it up: This will start it up as a daemon (it will run in the background) on IP 127.0.0.1 on port 11000 using no more then 64 MB of RAM.
----------------------------------------------------
$ memcached -d -l 127.0.0.1 -p 11000 -m 64
----------------------------------------------------
Confirm that it it is working with
-----------
$ top
----------
Output should be:
24190 u3988386 18 2 24056 22M 248 S N 0.0 0.0 0:00 memcached
Adding PECL Memcache.so to 1&1
注:必须安装libevent pecl扩展和libevent 服务器端
Download PECL to your 1&1 account:
---------------------------------------------------
$ wget http://pecl.php.net/get/memcache-3.0.8.tgz
---------------------------------------------------
Extract the package:
---------------------------------------------------
$ tar xvzf memcache-3.0.8.tgz
---------------------------------------------------
Go into the directory:
---------------------------------------------------
$ cd memcache-pecl-3.0.8
---------------------------------------------------
Run phpize5.5:
---------------------------------------------------
$ phpize5.5
---------------------------------------------------
Change php-config to php-config5.5 in configure script:
---------------------------------------------------
$ sed -i 's/=php-config/=php-config5.5/g' configure
---------------------------------------------------
Run Configure:
---------------------------------------------------
$ ./configure
---------------------------------------------------
如果有configure: error: Cannot find php_session.h
添加--disable-memcache-session
---------------------------------------------------
$ ./configure --disable-memcache-session
---------------------------------------------------
对于libevent
---------------------------------------------------
$ ./configure --with-libevent=$HOME/libevent-2.0.22-stable/ --with-php-config=/usr/bin/php-config5.5
or if by compiling of source libevent with ./configure --prefix=$HOME/libevent do the following:
./configure --with-libevent=$HOME/libevent/ --with-php-config=/usr/bin/php-config5.5
---------------------------------------------------
Change include directives in Makefile:
--------------------------------------------------------------------
$ sed -i 's#-I/usr/local/include/php#-I/usr/include/php5#g' Makefile
注:打开 Makefile文件
phpincludedir = Usage: /usr/local/bin/php-config [--prefix|--includes|--ldflags|--libs|--extension-dir|--version]
[...]
PHP_EXECUTABLE = Usage: /usr/local/bin/php-config [--prefix|--includes|--ldflags|--libs|--extension-dir|--version]
[...]
INCLUDES = -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend
改为:
phpincludedir = Usage: /usr/local/bin/php-config5 [--prefix|--includes|--ldflags|--libs|--extension-dir|--version]
[...]
PHP_EXECUTABLE = Usage: /usr/local/bin/php-config5 [--prefix|--includes|--ldflags|--libs|--extension-dir|--version]
[...]
INCLUDES = -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend
改所有的/usr/include/php 为 /usr/include/php5.5
--------------------------------------------------------------------
Run make and make test:
---------------------------------------------------
$ make
$ make test
---------------------------------------------------
Make new extensions folder for new extension to go in:
--------------------------------------------
$ mkdir ~/extensions
--------------------------------------------
Copy uploadprogress extension to new folder
------------------------------------------
$ cp .libs/memcache.so ~/extensions-php5.5/
------------------------------------------
Create new php.ini under your main folder (or under a single subfolder for just that application) to add new extension_dir then add this code to the file
------------------------------------------------------------------
extension_dir=/kunden/homepages/x/dxxxxxxxx/htdocs/extensions/
extension=memcache.so
-------------------------------------------------------------------