1. XenForo 1.5.14 中文版——支持中文搜索!现已发布!查看详情
  2. Xenforo 爱好者讨论群:215909318 XenForo专区

Centos 编译PHP 5.4.16

本帖由 admin2013-04-12 发布。版面名称:应用交流

  1. admin

    admin 管理员 管理成员

    注册:
    2011-11-01
    帖子:
    3,671
    赞:
    2,425
    下载准备
    代码:
    wget -c http://cn.php.net/get/php-5.4.16.tar.gz/from/cn2.php.net/mirror
    wget -c http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
    wget -c http://pecl.php.net/get/memcache-3.0.8.tgz
    wget -c http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz
    
    编译autoconf-2.69
    代码:
    tar xvfz autoconf-2.69.tar.gz
    cd autoconf-2.69/
    ./configure --prefix=/usr/local/autoconf/
    make
    make install
    cd ../
    export PHP_AUTOCONF=/usr/local/autoconf/bin/autoconf
    export PHP_AUTOHEADER=/usr/local/autoconf/bin/autoheader
    
    编译PHP
    代码:
    tar xvfz php-5.4.16.tar.gz
    cd php-5.4.16/
    ./buildconf --force
    ./configure --prefix=/usr/local/php \
    --with-libxml-dir=/usr/include/libxml2 \
    --with-config-file-path=/usr/local/php/etc/ \
    --with-mysql=/usr/local/mysql \
    --with-mysqli=/usr/local/mysql/bin/mysql_config \
    --with-gd \
    --enable-gd-native-ttf \
    --with-zlib \
    --with-mcrypt \
    --with-pdo-mysql=/usr/local/mysql \
    --enable-shmop \
    --enable-soap \
    --enable-sockets \
    --enable-wddx \
    --enable-zip \
    --with-xmlrpc \
    --enable-fpm \
    --enable-mbstring \
    --with-zlib-dir \
    --with-bz2 \
    --with-curl \
    --enable-exif \
    --enable-ftp \
    --with-jpeg-dir=/usr/lib \
    --with-png-dir=/usr/lib \
    --with-freetype-dir=/usr/lib \
    --with-iconv \
    --enable-xml \
    --enable-bcmath \
    --enable-sysvsem \
    --enable-inline-optimization \
    --with-curlwrappers \
    --enable-mbregex \
    --with-openssl \
    --enable-pcntl \
    --with-gettext \
    --enable-session
    make ZEND_EXTRA_LIBS='-liconv'
    make install
    
    创建PHP配置文件
    代码:
    mkdir -p /usr/local/php/etc
    cp php.ini-production /usr/local/php/etc/php.ini
    cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
    cd ../
    
    创建PHP符号链接
    代码:
    ln -s /usr/local/php/bin/php /usr/bin/php
    ln -s /usr/local/php/bin/phpize /usr/bin/phpize
    ln -s /usr/local/php/sbin/php-fpm /usr/bin/php-fpm
    ln -s /usr/local/mysql/include/* /usr/local/include/
    
    编译memcache-3.0.8扩展
    代码:
    tar xvfz memcache-3.0.8.tgz
    cd memcache-3.0.8/
    /usr/local/php/bin/phpize
    ./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir
    make
    make install
    cd ../
    sed -i 's#extension_dir = "./"#extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/"\nextension = "memcache.so"\n#' /usr/local/php/etc/php.ini
    
    编译PDO_MYSQL扩展
    代码:
    tar xvfz PDO_MYSQL-1.0.2.tgz
    cd PDO_MYSQL-1.0.2/
    /usr/local/php/bin/phpize
    ./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
    make
    make install
    cd ../
    
    设置PHP解释器开机启动以及作为系统服务
    代码:
    cp /root/lemp/php-5.4.16/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
    chmod +x /etc/init.d/php-fpm
    chkconfig --level 345 php-fpm on
     
  2. admin

    admin 管理员 管理成员

    注册:
    2011-11-01
    帖子:
    3,671
    赞:
    2,425
    Nginx配置
    代码:
    server
        {
            listen      80;
            server_name localhost;
            index index.html index.htm index.php;
            root  /home/wwwroot;
            location ~ .*\.(php|php5)?$
                {
                    fastcgi_pass 127.0.0.1:9000;
                    fastcgi_index index.php;
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    include fastcgi_params;
                }
     
            location /status {
                stub_status on;
                access_log  off;
            }
     
            location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
                {
                    expires      30d;
                }
     
            location ~ .*\.(js|css)?$
                {
                    expires      12h;
                }
        }
     
  3. admin

    admin 管理员 管理成员

    注册:
    2011-11-01
    帖子:
    3,671
    赞:
    2,425
    php-fpm.conf
    代码:
    pm.max_children:静态方式下开启的php-fpm进程数量。
    pm.start_servers:动态方式下的起始php-fpm进程数量。
    pm.min_spare_servers:动态方式下的最小php-fpm进程数量。
    pm.max_spare_servers:动态方式下的最大php-fpm进程数量。
     
  4. admin

    admin 管理员 管理成员

    注册:
    2011-11-01
    帖子:
    3,671
    赞:
    2,425
    停用危险的PHP函数php.ini
    代码:
    disable_functions = escapeshellarg,escapeshellcmd,exec,ini_alter,parse_ini_file,passthru,pcntl_exec,popen,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,show_source,shell_exec,symlink,system
    代码:
    open_basedir = /home/wwwroot:/usr/bin
    upload_tmp_dir = /tmp
     
正在加载...