Home php教程 php手册 编译安装libevent,memcache,以及php的memcached扩展

编译安装libevent,memcache,以及php的memcached扩展

Jun 06, 2016 am 09:51 AM
memcache memcached php code Install Open source Expand programming programming language compile software development

一 安装libevent

1.去官网http://libevent.org/ 下载最新源码,我用的是libevent-2.0.20-stable.tar.gz 

2.解压到/usr/src目录 ,执行命令:sudo tar -zxvf libevent-2.0.20-stable.tar.gz -C /usr/src

3.进入解压以后的目录,用sudo方式执行命令:sudo ./configure --prefix=/usr/local/libevent ; make ; make install

二 安装memcache

1.去官网 http://memcached.org/ 下最新源码,我用的是memcached-1.4.15.tar.gz

2.解压到/usr/src目录 ,执行命令:sudo tar -zxvf memcached-1.4.15.tar.gz -C /usr/src

3.进入解压以后的目录,用sudo方式执行命令:sudo ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent; make ; make install

三 安装php的memcache扩展

   有两个版本一个是memcache(http://pecl.php.net/package/memcache ),另一个是基于libmemcached的memcached版本(http://pecl.php.net/package/memcached );

   网上查的资料是说前一个是原生的,后一个比前一个功能更强大。比较推荐使用基于libmemcahced 库的memcached扩展。支持memcache提供的CAS操作,稳定性和效率也更好。

这里我使用基于libmemcached 库的memcached扩展,安装步骤如下:

首先,安装libmemcached库

1.去网址 https://launchpad.net/libmemcached (或者http://libmemcached.org/libMemcached.html )下载源码,

   我用的是libmemcached-1.0.14.tar.gz

2.解压缩到/usr/src目录,用sudo方式执行命令:sudo tar -zxvf libmemcached-1.0.14.tar.gz -C /usr/src

3.进入目录/usr/src/libmemcached-1.0.14/,sudo方式执行命令:./configure ;make;make install (不加--prefix=/usr/local/libmemcached 指定安装目录时,libmemcached 默认安装在/usr/local/,头文件安装在/usr/local/include/libmemcachde/,动态库默认安装在/usr/local/lib/下。

4.make时遇到问题:sorry, unimplemented: Graphite loop optimizations can only be used if the libcloog-ppl0 package is installed。解决办法是修改Makefile,查找并去掉 floop-parallelize-all(应该有两处需要去掉),看了网上资料说是去掉后表示不使用Graphite loop 优化。

5.再次make,遇到问题:fatal error: sasl/sasl.h: No such file or directory. 在网上搜到的解决办法是:

   Depending on your operating system, you'll need to install the cyrus-sasl development package.

   That would be cyrus-sasl-devel on RedHat based distros and libsasl2-dev on Debian based distros IIRC.

   我在ubuntu下直接用sudo apt-get install libsasl2-dev 安装了。

6.编译还是遇到问题,显示无法链接到sasl的一些文件。问题显示如下:

   undefined reference to `sasl_client_step'
   undefined reference to `sasl_dispose'
   undefined reference to `sasl_client_start'
   undefined reference to `sasl_client_new'

   解决办法是重新执行configure命令,增加相应的参数。sudo执行命令:sudo ./configure --enable-sasl --without-memcached LDFLAGS=-Wl,--as-neede ;make; make install

7.终于安装libmemcached库成功了。。。

其次,安装memcached版本的php扩展

1. 去网址http://pecl.php.net/package/memcached 下载memcached版本,我用的是memcached-2.1.0.tgz

2. 解压到/usr/src目录 ,执行命令:sudo tar -zxvf memcached-2.1.0.tgz -C /usr/src

3. 进入解压以后的目录,是没有configure文件的,用sudo方式执行命令来生成:sudo /usr/local/php/bin/phpize

4.遇到问题:Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script. 网上搜到的解决办法为:

cd /usr/src
wget http://ftp.gnu.org/gnu/m4/m4-1.4.9.tar.gz
tar -zvxf m4-1.4.9.tar.gz
cd m4-1.4.9/
./configure && make && make install
cd ../
wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.62.tar.gz
tar -zvxf autoconf-2.62.tar.gz<br>cd autoconf-2.62/
./configure && make && make install
Copy after login

5.这是再次执行sudo /usr/local/php/bin/phpize,就可以成功生成configure文件了。(phpize是用来扩展php扩展模块的,通过phpize可以建立php的外挂模块,官方说明网址为:http://php.net/manual/en/install.pecl.phpize.php

6.用sudo方式执行命令./configure --with-php-config=/usr/local/php/bin/php-config; make ; make install

7.编译完成了,还需要做的是在/usr/local/lib/php.ini文件中加入extension值:extension=memcache.so 

8.重启/usr/local/php/sbin/php-fpm程序使配置生效,但是报错:

   ERROR: failed to open configuration file '/usr/local/php/etc/php-fpm.conf': No such file or directory (2)

   ERROR: failed to load configuration file '/usr/local/php/etc/php-fpm.conf'

   ERROR: FPM initialization failed

   解决办法为: (1)cd /usr/local/php/etc/; (2)mv php-fpm.conf.default php-fpm.conf

9.重启仍然出现问题:ERROR: [pool www] cannot get uid for user 'www'。解决办法为:编辑文件vim /usr/local/php/etc/php-fpm.conf,

   把user = nobody group = nobody  中的nobody修改成有效的用户和用户组名称。

10.php扩展可使用的一些方法可参考网址:http://blog.csdn.net/fwkjdaghappy1/article/details/7592337

参考网址:

http://www.dewen.org/q/844

http://hi.baidu.com/thinkinginlamp/item/5a3b2531e25dc6f62784f4fb

http://code.google.com/p/memcached/wiki/PHPClientComparison

https://bugs.launchpad.net/keystone/+bug/843080

http://www.cppblog.com/kefeng/archive/2010/10/11/129422.html

https://bugs.launchpad.net/libmemcached/+bug/656010

http://blog.csdn.net/vaal_water/article/details/6439483

http://www.spiration.co.uk/post/1385/Cannot-find-autoconf.-Please-check-your-autoconf-installation

https://gist.github.com/3359828

http://www.2cto.com/kf/201111/110140.html

http://blog.johntechinfo.com/technology/264

http://www.oschina.net/question/231397_36921

http://www.cnblogs.com/huangjingzhou/articles/2093706.html

http://blog.csdn.net/fwkjdaghappy1/article/details/7592337

 

 

 

 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

Demystifying JavaScript: What It Does and Why It Matters Demystifying JavaScript: What It Does and Why It Matters Apr 09, 2025 am 12:07 AM

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

What is Cross-Site Request Forgery (CSRF) and how do you implement CSRF protection in PHP? What is Cross-Site Request Forgery (CSRF) and how do you implement CSRF protection in PHP? Apr 07, 2025 am 12:02 AM

In PHP, you can effectively prevent CSRF attacks by using unpredictable tokens. Specific methods include: 1. Generate and embed CSRF tokens in the form; 2. Verify the validity of the token when processing the request.

See all articles