fpm搭建高性能Nginx平台(2)

4、接着安装php、php-frm

 tar zxvf php-5.2.17.tar.gz
gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1
cd php-5.2.17
./configure --prefix=/usr/local/php --with-MySQL=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv=/usr/local/libiconv/ --with-libxml-dir=/usr/local/libxml2 --with-gd=/usr/local/gd/ --with-jpeg-dir=/usr/local/jpeg6/ --with-zlib-dir=/usr/local/zlib --with-png-dir=/usr/local/lib --with-freetype-dir=/usr/local/freetype --with-mysql=/usr/local/mysql --with-mcrypt=/usr/local/lib/libmcrypt --enable-mbstring --with-openssl --enable-ftp --with-curl --enable-fastcgi --enable-xml --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization  --with-curlwrappers --enable-mbregex  --enable-fpm --enable-force-cgi-redirect --enable-gd-native-ttf --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl
make
make install
cp php.ini-dist /usr/local/php/lib/php.ini
 

PHP的配置一会再说,先把nginx安装完成

5、nginx及php扩展插件

 tar zxvf pcre-8.01.tar.gz
cd pcre-8.01/
./configure
make
make install
cd ..

 

groupadd www

useradd -g www -d /home/www -s /sbin/nologin www

tar zxvf nginx-0.9.5.tar.gz
cd nginx-0.9.5/
./configure --with-http_stub_status_module --with-http_ssl_module --user=www --group=www --with-http_realip_module
make
make install
cd ..

tar zxvf memcache-2.2.5.tgz
cd memcache-2.2.5/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ..

tar jxvf eaccelerator-0.9.5.3.tar.bz2
cd eaccelerator-0.9.5.3/
/usr/local/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ..

mkdir /tmp/eaccelerator
chmod 777 /tmp/eaccelerator
chown www:www /tmp/eaccelerator
 

 

6、安装完那一大堆软件之后,要开始配置了,下面这些才是关键

第一步:配置php.ini

 vi /usr/local/php/lib/php.ini  

找到  extension_dir =""  

修改成

extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"
extension = "memcache.so"

 

再找到

 output_buffering=off  

修改成

 output_buffering = On  

再次查找

 ; cgi.fix_pathinfo=0  

把注释去掉

cgi.fix_pathinfo=0  

最后跳到php.ini文件的末尾,加入以下内容:

[eaccelerator]
zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="16"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="0"
eaccelerator.compress_level="9"
eaccelerator.keys = "disk_only"
eaccelerator.sessions = "disk_only"
eaccelerator.content = "disk_only"
 

至此,php.ini文件修改完毕!

第二步:配置nginx的FCGI

 vi /usr/local/nginx/conf/fcgi.conf  

写入以下内容:

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx;

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

 

第三步:配置php-fpm文件

mv /usr/local/php/etc/php-fpm.conf /usr/local/php/etc/php-fpm.conf.bak
 vi /root/lnmp/php-fpm.conf

 

重新写入以下内容

<?xml version="1.0" ?>
<configuration>

  All relative paths in this config are relative to php's install prefix

  <section>

    Pid file
    <value>/usr/local/php/logs/php-fpm.pid</value>

    Error log file
    <value>/usr/local/php/logs/php-fpm.log</value>

    Log level
    <value>notice</value>

    When this amount of php processes exited with SIGSEGV or SIGBUS ...
    <value>10</value>

    ... in a less than this interval of time, a graceful restart will be initiated.
    Useful to work around accidental curruptions in accelerator's shared memory.
    <value>1m</value>

    Time limit on waiting child's reaction on signals from master
    <value>5s</value>

    Set to 'no' to debug fpm
    <value>yes</value>

  </section>

  <workers>

    <section>

      Name of pool. Used in logs and stats.
      <value>default</value>

      Address to accept fastcgi requests on.
      Valid syntax is 'ip.ad.re.ss:port' or just 'port' or '/path/to/unix/socket'
      <value>127.0.0.1:9000</value>

      <value>

        Set listen(2) backlog
        <value>-1</value>

        Set permissions for unix socket, if one used.
        In Linux read/write permissions must be set in order to allow connections from web server.
        Many BSD-derrived systems allow connections regardless of permissions.
        <value></value>
        <value></value>
        <value>0666</value>
      </value>

      Additional php.ini defines, specific to this pool of workers.
      <value>
        <value>/usr/sbin/sendmail -t -i</value>
        <value>0</value>
      </value>

      Unix user of processes
      <value>www</value>

      Unix group of processes
      <value>www</value>

      Process manager settings
      <value>

        Sets style of controling worker process count.
        Valid values are 'static' and 'apache-like'
        <value>static</value>

        Sets the limit on the number of simultaneous requests that will be served.
        Equivalent to Apache MaxClients directive.
        Equivalent to PHP_FCGI_CHILDREN environment in original php.fcgi
        Used with any pm_style.
        <value>128</value>

        Settings group for 'apache-like' pm style
        <value>

          Sets the number of server processes created on startup.
          Used only when 'apache-like' pm_style is selected
          <value>20</value>

          Sets the desired minimum number of idle server processes.
          Used only when 'apache-like' pm_style is selected
          <value>5</value>

          Sets the desired maximum number of idle server processes.
          Used only when 'apache-like' pm_style is selected
          <value>35</value>

        </value>

      </value>

      The timeout (in seconds) for serving a single request after which the worker process will be terminated
      Should be used when 'max_execution_time' ini option does not stop script execution for some reason
      '0s' means 'off'
      <value>0s</value>

      The timeout (in seconds) for serving of single request after which a php backtrace will be dumped to slow.log file
      '0s' means 'off'
      <value>0s</value>

      The log file for slow requests
      <value>logs/slow.log</value>

      Set open file desc rlimit
      <value>65535</value>

      Set max core size rlimit
      <value>0</value>

      Chroot to this directory at the start, absolute path
      <value></value>

      Chdir to this directory at the start, absolute path
      <value></value>

      Redirect workers' stdout and stderr into main error log.
      If not set, they will be redirected to /dev/null, according to FastCGI specs
      <value>yes</value>

      How much requests each process should execute before respawn.
      Useful to work around memory leaks in 3rd party libraries.
      For endless request processing please specify 0
      Equivalent to PHP_FCGI_MAX_REQUESTS
      <value>1024</value>

      Comma separated list of ipv4 addresses of FastCGI clients that allowed to connect.
      Equivalent to FCGI_WEB_SERVER_ADDRS environment in original php.fcgi (5.2.2+)
      Makes sense only with AF_INET listening socket.
      <value>127.0.0.1</value>

      Pass environment variables like LD_LIBRARY_PATH
      All $VARIABLEs are taken from current environment
      <value>
        <value>$HOSTNAME</value>
        <value>/usr/local/bin:/usr/bin:/bin</value>
        <value>/tmp</value>
        <value>/tmp</value>
        <value>/tmp</value>
        <value>$OSTYPE</value>
        <value>$MACHTYPE</value>
        <value>2</value>
      </value>

    </section>

  </workers>

</configuration>

 

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wywjgw.html