现在的位置: 首页Nginx>正文
FreeBSD下安装mysql5.1.56+php5.2.17(FastCGI)+nginx1.0.1高性能Web服务器 [原创]
2011年05月05日 Nginx FreeBSD下安装mysql5.1.56+php5.2.17(FastCGI)+nginx1.0.1高性能Web服务器 [原创]已关闭评论 ⁄ 被围观 15,410 次+

一、下载所需软件

  1. mysql-5.1.56.tar.gz
  2. zlib-1.2.5.tar.gz
  3. libpng-1.4.2.tar.gz
  4. curl-7.20.1.tbz
  5. freetds-0.64_5,1.tbz
  6. freetype-1.3.1_4.tbz
  7. jpeg-8_3.tbz
  8. libmcrypt-2.5.8.tbz
  9. libxml2-2.7.7.tbz
  10. mcrypt-2.6.8_1.tbz
  11. mysql-client-5.1.50_1.tbz
  12. openssl-1.0.0_2.tbz
  13. perl-5.10.1_2.tbz
  14. png-1.4.3.tbz
  15. gd-2.0.35_7,1.tbz
  16. autoconf-2.62.tbz
  17. php-5.2.17.tar.gz
  18. php-5.2.17-fpm-0.5.14.diff.gz
  19. memcache-2.2.5.tgz
  20. eaccelerator-0.9.6.1.tar.bz2
  21. nginx-1.0.1.tar.gz

二、编译安装mysql

  1. mkdir -p /data/soft
  2. pw groupadd mysql
  3. pw useradd mysql -g mysql
  4. tar zxvf mysql-5.1.56.tar.gz
  5. cd mysql-5.1.56/
  6. ./configure --prefix=/data/soft/mysql --without-debug --with-unix-socket-path=/data/soft/mysql/tmp/mysql.sock --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --enable-assembler --with-extra-charsets=gbk,gb2312,utf8 --with-pthread --enable-thread-safe-client --with-plugins=max-no-ndb
  7. make && make install
  8. cd ..
  9. cp /data/soft/mysql/share/mysql/my-medium.cnf /data/soft/mysql/my.cnf
  10. sed -i """s/skip-locking/# skip-locking/" /data/soft/mysql/my.cnf
  11. chmod +w /data/soft/mysql
  12. chown -R mysql:mysql /data/soft/mysql

以mysql用户帐号的身份建立数据表:

  1. /bin/sh /data/soft/mysql/bin/mysql_install_db --defaults-file=/data/soft/mysql/my.cnf --basedir=/data/soft/mysql --datadir=/data/soft/mysql/data --user=mysql --pid-file=/data/soft/mysql/mysql.pid --port=3306 --socket=/data/soft/mysql/tmp/mysql.sock
  2. /bin/sh /data/soft/mysql/bin/mysqld_safe --defaults-file=/data/soft/mysql/my.cnf &
  3. echo "/data/soft/mysql/bin/mysqld_safe --user=mysql &" > /etc/rc.d/start.sh
  4. chmod o+x /etc/rc.d/start.sh

三、编译安装php所需的支持库

  1. tar zxvf zlib-1.2.5.tar.gz
  2. cd zlib-1.2.5
  3. ./configure --prefix=/usr
  4. make && make install
  5. cd ..
  6. tar zxvf libpng-1.4.2.tar.gz
  7. cd libpng-1.4.2
  8. ./configure --disable-shared --prefix=/usr
  9. make && make install
  10. cd ..
  11. pkg_add curl-7.20.1.tbz freetds-0.64_5,1.tbz freetype-1.3.1_4.tbz jpeg-8_3.tbz libmcrypt-2.5.8.tbz libxml2-2.7.7.tbz mcrypt-2.6.8_1.tbz mysql-client-5.1.50_1.tbz openssl-1.0.0_2.tbz perl-5.10.1_2.tbz png-1.4.3.tbz gd-2.0.35_7,1.tbz autoconf-2.62.tbz

四、编译安装php

1、安装php-5.2.17

  1. tar zxvf php-5.2.17.tar.gz
  2. gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1
  3. cd php-5.2.17
  4. sed -i "" "s/\!png_check_sig (sig, 8)/png_sig_cmp (sig, 0, 8)/" ext/gd/libgd/gd_png.c
  5. ./configure --prefix=/data/soft/php --with-config-file-path=/data/soft/php/etc --with-bz2=/usr --with-mhash=/usr --with-mcrypt=/usr --with-curl=/usr --with-libxml-dir=/usr --with-iconv-dir=/usr --with-freetype-dir=/usr --with-jpeg-dir=/usr --with-png-dir=/usr --with-zlib-dir=/usr --with-mysql=/usr --with-mssql --with-gd --with-openssl --with-sybase --with-curlwrappers --with-mysqli --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fastcgi --enable-force-cgi-redirect --enable-mbstring --enable-zip --enable-ftp --enable-sockets --enable-calendar --enable-gd-native-ttf --enable-xml --enable-fpm --enable-sysvmsg --enable-soap --disable-debug --disable-rpath
  6. make ZEND_EXTRA_LIBS='-liconv'
  7. make install
  8. cp php.ini-dist /data/soft/php/etc/php.ini
  9. cd ..

2、编译安装PHP5扩展模块

  1. tar zxvf memcache-2.2.5.tgz
  2. cd memcache-2.2.5/
  3. /data/soft/php/bin/phpize
  4. ./configure --with-php-config=/data/soft/php/bin/php-config
  5. make && make install
  6. cd ..
  7. tar jxvf eaccelerator-0.9.6.1.tar.bz2
  8. cd eaccelerator-0.9.6.1/
  9. /data/soft/php/bin/phpize
  10. ./configure --enable-eaccelerator=shared --with-php-config=/data/soft/php/bin/php-config --without-eaccelerator-use-inode
  11. make && make install
  12. cd ..

3、修改php.ini文件

  1. sed -i "" "s/output_buffering = Off/output_buffering = On/" /data/soft/php/etc/php.ini
  2. sed -i "" "s/extension_dir =/; extension_dir =/" /data/soft/php/etc/php.ini
  3. sed -i "" "s/; cgi.fix_pathinfo=0/cgi.fix_pathinfo=0/" /data/soft/php/etc/php.ini
  4. sed -i "" "s/disable_functions =/disable_functions = popen,pentl_exec,passthru,exec,system,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,show_source,escapeshellcmd,escapeshellarg,curl_exec,curl_multi_exec,parse_ini_file,assert/" /data/soft/php/etc/php.ini
  5. sed -i "" "s/expose_php = On/expose_php = Off/" /data/soft/php/etc/php.ini
  6. sed -i "" "s%mysql.default_socket =%mysql.default_socket = /data/soft/mysql/tmp/mysql.sock%" /data/soft/php/etc/php.ini
  7. sed -i "" "s/display_errors = On/display_errors = Off/" /data/soft/php/etc/php.ini
  8. sed -i "" "s/log_errors = Off/log_errors = On/" /data/soft/php/etc/php.ini

在php.ini最后添加如下:

  1. extension_dir = "/data/soft/php/lib/php/extensions/no-debug-non-zts-20060613/"
  2. extension = "memcache.so"
  3. [eaccelerator]
  4. zend_extension="/data/soft/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
  5. eaccelerator.shm_size="64"
  6. eaccelerator.cache_dir="/data/soft/eaccelerator_cache"
  7. eaccelerator.enable="1"
  8. eaccelerator.optimizer="1"
  9. eaccelerator.check_mtime="1"
  10. eaccelerator.debug="0"
  11. eaccelerator.filter=""
  12. eaccelerator.shm_max="0"
  13. eaccelerator.shm_ttl="3600"
  14. eaccelerator.shm_prune_period="3600"
  15. eaccelerator.shm_only="0"
  16. eaccelerator.compress="1"
  17. eaccelerator.compress_level="9"

4、创建eAccelerator缓存目录

  1. mkdir -p /data/soft/eaccelerator_cache

5、修改内核参数

  1. sysctl -w kern.ipc.shmall=32768
  2. sysctl -w kern.ipc.shmmax=134217728
  3. sysctl -w kern.ipc.semmap=256
  4. echo "kern.ipc.shmall=32768" >> /etc/sysctl.conf
  5. echo "kern.ipc.shmmax=134217728" >> /etc/sysctl.conf
  6. echo "kern.ipc.semmap=256">> /etc/sysctl.conf

6、创建php-fpm.conf文件

  1. rm -f /data/soft/php/etc/php-fpm.conf
  2. ee /data/soft/php/etc/php-fpm.conf

如下:

  1. <?xml version="1.0" ?>   
  2. <configuration>   
  3.   
  4.   All relative paths in this config are relative to php's install prefix   
  5.   
  6.   <section name="global_options">   
  7.   
  8.     Pid file   
  9.     <value name="pid_file">/data/soft/php/logs/php-fpm.pid</value>   
  10.   
  11.     Error log file   
  12.     <value name="error_log">/data/soft/php/logs/php-fpm.log</value>   
  13.   
  14.     Log level   
  15.     <value name="log_level">notice</value>   
  16.   
  17.     When this amount of php processes exited with SIGSEGV or SIGBUS ...   
  18.     <value name="emergency_restart_threshold">10</value>   
  19.   
  20.     ... in a less than this interval of time, a graceful restart will be initiated.   
  21.     Useful to work around accidental curruptions in accelerator's shared memory.   
  22.     <value name="emergency_restart_interval">1m</value>   
  23.   
  24.     Time limit on waiting child's reaction on signals from master   
  25.     <value name="process_control_timeout">5s</value>   
  26.   
  27.     Set to 'no' to debug fpm   
  28.     <value name="daemonize">yes</value>   
  29.   
  30.   </section>   
  31.   
  32.   <workers>   
  33.   
  34.     <section name="pool">   
  35.   
  36.       Name of pool. Used in logs and stats.   
  37.       <value name="name">default</value>   
  38.   
  39.       Address to accept fastcgi requests on.   
  40.       Valid syntax is 'ip.ad.re.ss:port' or just 'port' or '/path/to/unix/socket'   
  41.       <value name="listen_address">127.0.0.1:9000</value>   
  42.   
  43.       <value name="listen_options">   
  44.   
  45.         Set listen(2) backlog   
  46.         <value name="backlog">-1</value>   
  47.   
  48.         Set permissions for unix socketif one used.   
  49.         In Linux read/write permissions must be set in order to allow connections from web server.   
  50.         Many BSD-derrived systems allow connections regardless of permissions.   
  51.         <value name="owner"></value>   
  52.         <value name="group"></value>   
  53.         <value name="mode">0666</value>   
  54.       </value>   
  55.   
  56.       Additional php.ini defines, specific to this pool of workers.   
  57.       <value name="php_defines">   
  58.         <value name="sendmail_path">/usr/sbin/sendmail -t -i</value>   
  59.         <value name="display_errors">1</value>   
  60.       </value>   
  61.   
  62.       Unix user of processes   
  63.       <value name="user">www</value>   
  64.   
  65.       Unix group of processes   
  66.       <value name="group">www</value>   
  67.   
  68.       Process manager settings   
  69.       <value name="pm">   
  70.   
  71.         Sets style of controling worker process count.   
  72.         Valid values are 'static' and 'apache-like'   
  73.         <value name="style">static</value>   
  74.   
  75.         Sets the limit on the number of simultaneous requests that will be served.   
  76.         Equivalent to Apache MaxClients directive.   
  77.         Equivalent to PHP_FCGI_CHILDREN environment in original php.fcgi   
  78.         Used with any pm_style.   
  79.         <value name="max_children">8</value>   
  80.   
  81.         Settings group for 'apache-like' pm style   
  82.         <value name="apache_like">   
  83.   
  84.           Sets the number of server processes created on startup.   
  85.           Used only when 'apache-like' pm_style is selected   
  86.           <value name="StartServers">20</value>   
  87.   
  88.           Sets the desired minimum number of idle server processes.   
  89.           Used only when 'apache-like' pm_style is selected   
  90.           <value name="MinSpareServers">5</value>   
  91.   
  92.           Sets the desired maximum number of idle server processes.   
  93.           Used only when 'apache-like' pm_style is selected   
  94.           <value name="MaxSpareServers">35</value>   
  95.   
  96.         </value>   
  97.   
  98.       </value>   
  99.   
  100.       The timeout (in seconds) for serving a single request after which the worker process will be terminated   
  101.       Should be used when 'max_execution_time' ini option does not stop script execution for some reason   
  102.       '0s' means 'off'   
  103.       <value name="request_terminate_timeout">0s</value>   
  104.   
  105.       The timeout (in seconds) for serving of single request after which a php backtrace will be dumped to slow.log file   
  106.       '0s' means 'off'   
  107.       <value name="request_slowlog_timeout">0s</value>   
  108.   
  109.       The log file for slow requests   
  110.       <value name="slowlog">logs/slow.log</value>   
  111.   
  112.       Set open file desc rlimit   
  113.       <value name="rlimit_files">65535</value>   
  114.   
  115.       Set max core size rlimit   
  116.       <value name="rlimit_core">0</value>   
  117.   
  118.       Chroot to this directory at the start, absolute path   
  119.       <value name="chroot"></value>   
  120.   
  121.       Chdir to this directory at the start, absolute path   
  122.       <value name="chdir"></value>   
  123.   
  124.       Redirect workers' stdout and stderr into main error log.   
  125.       If not set, they will be redirected to /dev/null, according to FastCGI specs   
  126.       <value name="catch_workers_output">yes</value>   
  127.   
  128.       How much requests each process should execute before respawn.   
  129.       Useful to work around memory leaks in 3rd party libraries.   
  130.       For endless request processing please specify 0   
  131.       Equivalent to PHP_FCGI_MAX_REQUESTS   
  132.       <value name="max_requests">1024</value>   
  133.   
  134.       Comma separated list of ipv4 addresses of FastCGI clients that allowed to connect.   
  135.       Equivalent to FCGI_WEB_SERVER_ADDRS environment in original php.fcgi (5.2.2+)   
  136.       Makes sense only with AF_INET listening socket.   
  137.       <value name="allowed_clients">127.0.0.1</value>   
  138.   
  139.       Pass environment variables like LD_LIBRARY_PATH   
  140.       <value name="environment">   
  141.         <value name="PATH">/usr/local/bin:/usr/bin:/bin</value>   
  142.         <value name="TMP">/tmp</value>   
  143.         <value name="TMPDIR">/tmp</value>   
  144.         <value name="TEMP">/tmp</value>   
  145.         <value name="OSTYPE">$OSTYPE</value>   
  146.         <value name="MACHTYPE">$MACHTYPE</value>   
  147.         <value name="MALLOC_CHECK_">2</value>   
  148.       </value>   
  149.   
  150.     </section>   
  151.   
  152.   </workers>   
  153.   
  154. </configuration>  

7、启动php-fpm并加入启动脚本

  1. /data/soft/php/sbin/php-fpm start
  2. echo "/data/soft/php/sbin/php-fpm start" >> /etc/rc.d/start.sh

五、编译安装nginx-1.0.1

1、安装nginx所需的pcre库

  1. tar zxvf pcre-8.10.tar.gz
  2. cd pcre-8.10
  3. ./configure
  4. make && make install
  5. cd ..

2、安装nginx

  1. tar zxvf nginx-1.0.1.tar.gz
  2. cd nginx-1.0.1/
  3. ./configure --prefix=/data/soft/nginx --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_dav_module --with-http_flv_module --with-http_addition_module --with-http_sub_module
  4. make && make install
  5. cd ..

3、创建nginx配置文件

  1. rm -f /data/soft/nginx/conf/nginx.conf
  2. ee /data/soft/nginx/conf/nginx.conf

如下:

  1. user  www www;   
  2. worker_processes 8;   
  3. pid        /data/soft/nginx/logs/nginx.pid;   
  4. worker_rlimit_nofile 65535;   
  5. events   
  6. {   
  7.     use kqueue;   
  8.     worker_connections 65535;   
  9. }   
  10. http   
  11. {   
  12.     include       mime.types;   
  13.     default_type  application/octet-stream;   
  14.     #log_format main '$remote_addr "$request" $status $bytes_sent "$http_referer""$http_user_agent"';   
  15.     #access_log  logs/access.log  main;   
  16.     error_log logs/error.log crit;   
  17.     access_log off;   
  18.     server_names_hash_bucket_size 128;   
  19.     client_header_buffer_size 32k;   
  20.     large_client_header_buffers 4 32k;   
  21.     client_max_body_size 8m;   
  22.     sendfile on;   
  23.     tcp_nopush     on;   
  24.     keepalive_timeout 60;   
  25.     tcp_nodelay on;   
  26.     fastcgi_connect_timeout 300;   
  27.     fastcgi_send_timeout 300;   
  28.     fastcgi_read_timeout 300;   
  29.     fastcgi_buffer_size 64k;   
  30.     fastcgi_buffers 4 64k;   
  31.     fastcgi_busy_buffers_size 128k;   
  32.     fastcgi_temp_file_write_size 128k;   
  33.     gzip on;   
  34.     gzip_min_length  1k;   
  35.     gzip_buffers 4 16k;   
  36.     gzip_http_version 1.0;   
  37.     gzip_comp_level 2;   
  38.     gzip_types       text/plain application/x-javascript text/css application/xml;   
  39.     gzip_vary on;   
  40.     server   
  41.     {   
  42.         listen 80;   
  43.         server_name default;   
  44.         index index.php;   
  45.         root  /data/www/test;   
  46.         location ~ .*\.(php|php5)?$   
  47.         {   
  48.             fastcgi_pass 127.0.0.1:9000;   
  49.             fastcgi_index index.php;   
  50.             include fastcgi.conf;   
  51.         }   
  52.     }   
  53. }  

4、启动nginx并进行测试

  1. /data/soft/nginx/sbin/nginx -t
  2. /data/soft/nginx/sbin/nginx
  3. mkdir -p /data/www/test
  4. echo "<?php phpinfo();?>" > /data/www/test/index.php
  5. echo "/data/soft/nginx/sbin/nginx" >> /etc/rc.d/start.sh

fnmp

本文地址:http://www.92csz.com/12/542.html
如非注明则为本站原创文章,欢迎转载。转载请注明转载自:moon's blog
 

抱歉!评论已关闭.