zoukankan      html  css  js  c++  java
  • Debian/Ubuntu源码编译安装PHP--支持FastCGI

    从 php 5.3.3 起,就可直接使用 PHP-FPM ,不再需要打补丁了。此前已写过Linux 从源码编译安装 PHP 5》 见 http://www.linuxidc.com/Linux/2011-10/45743.htm,但是以 mod_php 模块方式,而非 FastCGI 模式运行 php ,并不适用于 Lighttpd、Nginx、LiteSpeed ,而且当时对所有模块都采用编译安装也显得过于繁琐。

    一、什么是 FastCGI、PHP-FPM、FastCGI ?

    CGI是一种口;FastCGI 是 CGI 的扩展,让 CGI 更高效;PHP-FPM 是一个 PHP FastCGI 管理器;同理 Spawn-FCGI 是一个通用的 FastCGI 管理器,它是 lighttpd 中的一部份。

    因此,以 FastCGI 模式运行 php 5.3.4,主要有两种方式,一是 PHP-FPM、二是 Spawn-FCGI ,本文要讲的是以 PHP-FPM 方式运行管理 php。

    参考资料:

    1、《php-fpm文档中文翻译》 http://www.linuxidc.com/Linux/2011-10/45747.htm
    2、《什么是CGI、FastCGI、PHP-CGI、PHP-FPM、Spawn-FCGI?》 http://www.linuxidc.com/Linux/2011-07/38108.htm

    二、准备工作

    系统环境:Ubuntu-10.10-Server-I386
    OpenSSL 版本:openssl-1.0.0c (安装方法见 http://www.linuxidc.com/Linux/2011-10/45738.htm
    OpenSSH 版本:openssh-5.6p1 (安装方法见 http://www.linuxidc.com/Linux/2011-10/45739.htm
    MySQL 5 版本:mysql-5.1.53-linux-i686-glibc23 (安装方法见 http://www.linuxidc.com/Linux/2011-10/45742.htm

    三、编译安装 php5-gd

    3.1、安装基础编译环境

    1
    
    apt-get install build-essential -y

    3.2、安装 libpng、 libjpeg、 libfreetype

    1
    
    apt-get install libpng12-dev libjpeg62-dev libfreetype6-dev -y

    3.3、源码编译安装 Libiconv

    1
    2
    3
    4
    5
    
    wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
    tar -zxf libiconv-1.13.1.tar.gz 
    cd libiconv-1.13.1/
    ./configure --prefix=/usr/local
    make && make install

    3.4、源码编译安装 gd-2.0.35

    1
    2
    3
    4
    5
    
    wget http://www.libgd.org/releases/gd-2.0.35.tar.gz
    tar -zxf gd-2.0.35.tar.gz
    cd gd-2.0.35/
    ./configure --prefix=/usr/local --with-libiconv-prefix=/usr/local --with-png --with-freetype --with-jpeg
    make && make install

    四、编译安装 php5 扩展库

    4.1、libxml、libmhash、libmcrypt、mcrypt、libldap、libsasl

    1
    
    apt-get install libxml2-dev libmhash-dev libmcrypt-dev mcrypt libldap2-dev libsasl2-dev libssh2-1-dev

    4.2、编译安装 curl-7.21.3

    1
    2
    3
    4
    5
    
    wget http://curl.haxx.se/download/curl-7.21.3.tar.gz
    tar -zxf curl-7.21.3.tar.gz
    cd curl-7.21.3/
    ./configure --prefix=/usr/local
    make && make install

    五、编译安装 php5.3.4 (FastCGI)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    
    wget http://cn.php.net/distributions/php-5.3.4.tar.gz
    tar -zxf php-5.3.4.tar.gz
    cd php-5.3.4/ ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-openssl=/usr --with-png-dir --with-jpeg-dir --with-freetype-dir --with-iconv-dir=/usr/local --with-gd=/usr/local --enable-gd-native-ttf --with-libxml-dir --with-zlib --with-mhash --with-mcrypt --with-ldap --with-ldap-sasl --with-curl=/usr/local --with-curlwrappers --enable-bcmath --enable-calendar --enable-mbstring --enable-ftp --enable-zip --enable-sockets --enable-exif --enable-zend-multibyte --enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data make && make install
    cp php.ini-production /usr/local/php/lib/php.ini
    <code>
     
    --prefix #指定php5安装目录
    --with-mysql #指定mysql安装目录
    --with-mysqli #添加mysqli扩展支持
    --with-openssl #指定openssl安装目录
    --with-png-dir #GD所需的png库
    --with-jpeg-dir #GD所需的jpeg库
    --with-freetype-dir #指定freetype字体库
    --with-iconv-dir #指定iconv函数库,用于字符集转换
    --with-gd #指定GD库目录
    --enable-gd-native-ttf #添加TrueType字符串函数库
    --with-libxml-dir #指定libxml2库目录
    --with-zlib #压缩库目录
    --with-mhash #指定哈希函数库目录
    --with-mcrypt #指定mcrypt加密函数库
    --with-ldap #指定ldap库
    --with-curl #指定cURL库
    --with-curlwrappers #运用curl工具打开url流
    --enable-bcmath #高精度数学函数支持
    --enable-calendar #开启对日历的支持
    --enable-mbstring #多字节、字符串支持
    --enable-ftp #开启对ftp的支持
    --enable-zip #开启对zip的支持
    --enable-sockets #开启sockets支持
    --enable-exif #图片元数据支持
    --enable-zend-multibyte #zend多字节的支持
    --enable-fpm #开启FastCGI的进程管理支持
    --with-fpm-user #运行fpm的用户
    --with-fpm-user #运行fpm的组
     
    <h3>六、配置 php-fpm</h3>
     
    <code lang='bash'>
    cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
    vim /usr/local/php/etc/php-fpm.conf

    查找下面语句,并将前面"#"号去掉。

    1
    2
    3
    4
    5
    6
    
    pid = run/php-fpm.pid
    error_log = log/php-fpm.log
    log_level = notice
    pm.start_servers
    pm.min_spare_servers
    pm.max_spare_servers

    6.2、开机自动重启 php-fpm

    1
    2
    3
    
    cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
    chmod 755 /etc/init.d/php-fpm
    update-rc.d php-fpm defaults
  • 相关阅读:
    从yum源下载软件包
    本地yum源建立
    Redis慢查询,redis-cli,redis-benchmark,info
    Centos6.6安装mysql记录
    Nginx常用命令(加入系统服务)
    Nginx+keepalived双机热备(主从模式)
    Nginx反向代理+负载均衡简单实现
    Centos7安装Python3.5
    CentOS 6.4下OpenSSH升级到6.7操作
    Redis详解
  • 原文地址:https://www.cnblogs.com/j-king/p/3918907.html
Copyright © 2011-2022 走看看