Home >> php >> 服务器配置系列之二 Install php-5.3.x on linux

服务器配置系列之二 Install php-5.3.x on linux

本文为 服务器配置系列之一 Install apache2 on linux 的续篇 
(原文链接 http://ddbiz.com/?p=178)
php 的安装要比 httpd 复杂一些,主要可能是他的相关模块以及对系统环境的相关行很强。

  1. 下载
    wget http://www.php.net/get/php-5.3.10.tar.bz2/from/a/mirror 
  2. 安装前的准备工作
    php 很多模块需要相关的动态库, 因此安装前需要先设定一下。本文仅仅符合 CentOS 5.3/6.x/x86 64 环境,其他环境下的安装还需要参考其文档。

    yum install freetype-devel jpeg-devel libpng-devel
    注: Centos 6中, jpeg-devel 或许更名为了 libjpeg-devel

    安装 libmcrypt libltdl libmhash

    说明: 这个安装是如果要把 mcrypt 安装进php,则需要特别安装 libmcrypt, libmcrypt/libltdl, 否则可能会在make php的时候发生cannot find -lltdl的错误。

  3. 安装libmcrypt

    http://downloads.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.bz2?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fmcrypt%2Ffiles%2FLibmcrypt%2F2.5.8%2F&ts=1329115552&use_mirror=jaist
    tar xjvf libmcrypt-2.5.8.tar.bz2
    cd libmcrypt-2.5.8
    ./configure
    make && make install

  4. 安装 libltdl

    cd libmcrypt-2.5.8
    ./configure –enable-ltdl-install
    make && make install

    默认的libmcrypt会安装在 /usr/local/lib下,无论你是否指定过安装目录,在安装完毕libmycrypt后,最好创建并编辑一下 /etc/ld.so.conf.d/libmycrypt.conf 文件,然后执行 ldconfig ,这样可以避免出现:

    checking for libmcrypt – version >= no

    的错误

  5. 安装 libmhash

    wget http://downloads.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.bz2?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fmhash%2Ffiles%2Fmhash%2F0.9.9.9%2F&ts=1329117267&use_mirror=jaist
    tar xjvf mhash-0.9.9.9.tar.bz2
    cd mhash-0.9.9.9
    ./configure
    maks && make install

    同样,libmhash的库目录也应该出现在 ld.so.conf.d中,配置同libmcrypt

  6. 安装 mcrypt

    wget http://downloads.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz?use_mirror=voxel
    tar xzvf mcrypt-2.6.8.tar.gz
    cd mcrypt-2.6.8
    ./configure
    make && make install
    ldconfig
    cd libltdl
    ./configure ?–enable-ltdl-install
    make && make install

  7. 配置 php-fpm .
    下面是一个可用的php-fpm的配置,如果需要集成更多的模块,可以根据需要,修改./configure 的配置项

    cd php-5.3.10
    ./configure –prefix=/usr/local/webserver/php \
    –with-mysql=mysqlnd \
    –with-pdo-mysql=mysqlnd \
    –with-mysql-sock=/var/lib/mysql/mysql.sock \
    –with-gettext \
    –with-iconv \
    –disable-debug \
    –with-openssl \
    –with-zlib \
    –with-curl \
    –enable-mbstring \
    –with-gd \
    –with-zlib-dir \
    –with-jpeg-dir \
    –with-png-dir \
    –with-freetype-dir \
    –enable-magic-quotes \
    –enable-fpm
    make && make install

    在64位系统上编译php的时候,需要指定 –with-libdir=lib64,从而能够启用64位的动态库,否则可能会出现库版本不正确或者找不到库的情况,如:

    ./configure –prefix=/usr/local/webserver/php \
    –with-libdir=lib64 \
    –with-mysql=mysqlnd \
    –with-pdo-mysql=mysqlnd \
    –with-mysql-sock=/var/lib/mysql/mysql.sock \
    –with-gettext \
    –with-iconv \
    –disable-debug \
    –with-openssl \
    –with-zlib \
    –with-curl \
    –enable-mbstring \
    –with-gd \
    –with-zlib-dir \
    –with-jpeg-dir \
    –with-png-dir \
    –with-freetype-dir \
    –enable-magic-quotes \
    –enable-fpm

    查看 php 的编译加载模块

    [PHP Modules]
    Core
    ctype
    curl
    date
    dom
    ereg
    fileinfo
    filter
    gd
    gettext
    hash
    iconv
    json
    libxml
    mbstring
    mcrypt
    memcache
    mhash
    mysql
    openssl
    pcre
    PDO
    pdo_mysql
    pdo_sqlite
    Phar
    posix
    Reflection
    session
    SimpleXML
    SPL
    SQLite
    sqlite3
    standard
    tokenizer
    uuid
    xml
    xmlreader
    xmlwriter
    zip
    zlib
     
    [Zend Modules]

    根据列表确定所有需要的模块都已经静态加载

  8. 为php静态编译memcache模块
    memcache目前尚未包含在php源码中,不过可以通过php-memcache的源码来联编php:

    #下载php memcache 扩展模块
    wget http://pecl.php.net/get/memcache-2.2.6.tgz
    tar xzvf memcache-2.2.6.tgz
    mv memcache-2.2.6 $PHPSRC/ext/memcache
    cd $PHPSRC/extmemcache
    phpize
    cd $PHPSRC
    rm configure
    ./buildconf –force
    ./configure –enable-memcache ….

    使用buildconf时,可能会遇到autoconf版本不对或者找不到的情况,要么是autoconf没有安装,或者autoconf安装的版本太高了,修正方式:

    yum install autoconf213
    PHP_AUTOCONF=/usr/bin/autoconf-213;export PHP_AUTOCONF
    ./buildconf –force

  9. 设置httpd加载php, 创建一个 httpd-php.conf, 并让其能够在 httpd.conf 中加载

    #######################################################################
    #LoadModule php5_module modules/libphp5.so
    # loadmodule will be add by php make install into httpd.conf
    ######################################################################
    <FilesMatch “/.ph(p[2-6]?|tml)$”>
       SetHandler application/x-httpd-php
    </FilesMatch>
    <FilesMatch “/.phps$”>
       SetHandler application/x-httpd-php-source
    </FilesMatch>
    DirectoryIndex index.php

    查看httpd加载

    service httpd restart

  10. 为php 安装其他的动态模块

    修改php.ini
    extension_dir=”/usr/local/webserver/php/lib/ext”
    extension=memcache.so

    extension=uuid.so

  11. uuid

    $wget http://pecl.php.net/get/uuid-1.0.2.tgz
    $tar xzvf uuid-1.0.2.tgz
    $cd uuid-1.0.2
    $phpize && ./configure –enable-uuid && make
    cp modules/uuid.so /usr/local/webserver/php/lib/ext/ 

  12. memcache

    wget http://pecl.php.net/get/memcache-2.2.5.tgz /*this file seems to be a inline module for php compile*/

    phpize && ./configure -enable-memcache && make

    cp modules/memcache.so /usr/local/webserver/php/lib/ext


(原文链接 http://ddbiz.com/?p=178)

留言/有话要说

Copyright © 2012 Dimensions Data Business. All rights reserved.
server process 2.518 seconds.
WP-Backgrounds Lite by InoPlugs Web Design and Juwelier Schönmann 1010 Wien