教育网站Linux+PHP+Nginx+Mysql配置文档

日期: Wednesday, May 04, 2011  ver1.0  by doupip

Monday, July 23, 2012, ver2.0  by doupip

系统要求:Linux 2.6+ 内核, 本文中的Linux操作系统为CentOS 5.5, 以下操作均以root执行.

参考:http://blog.s135.com/nginx_php_v6/

 

下载与系统准备

首先,设置系统语言格式, 用系统自带的yum命令安装、升级所需的程序库,蓝字部分:

LANG=C

yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

 

***************************************************************************************

 

下面列表为相关软件,版本与参考资料中的有些是不一致的,mysql的下载不包括在内(建议直接download到服务器上,速度比较快)

推荐用下面的官方下载地址:

cd    /usr/local/src

官方下载地址:

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz

wget "http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?modtime=1171868460&big_mirror=0"

wget "http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?modtime=1175740843&big_mirror=0"

wget "http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?modtime=1194463373&big_mirror=0"

wget http://www.php.net/get/php-5.2.17.tar.gz/from/this/mirror

wget http://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gz

wget http://pecl.php.net/get/memcache-2.2.5.tgz

wget http://bart.eaccelerator.net/source/0.9.6.1/eaccelerator-0.9.6.1.tar.bz2

wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz

wget http://blog.s135.com/soft/linux/nginx_php/imagick/ImageMagick.tar.gz

wget http://pecl.php.net/get/imagick-2.3.0.tgz

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.12.tar.gz

wget http://nginx.org/download/nginx-1.0.1.tar.gz

 

  

下载地址2:

wget http://blog.s135.com/soft/linux/nginx_php/libiconv/libiconv-1.13.1.tar.gz

wget http://blog.s135.com/soft/linux/nginx_php/mcrypt/libmcrypt-2.5.8.tar.gz

wget http://blog.s135.com/soft/linux/nginx_php/mhash/mhash-0.9.9.9.tar.gz

wget http://blog.s135.com/soft/linux/nginx_php/mcrypt/mcrypt-2.6.8.tar.gz

wget http://cn.php.net/distributions/php-5.2.17.tar.gz

wget http://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gz

wget http://blog.s135.com/soft/linux/nginx_php/memcache/memcache-2.2.5.tgz

wget http://blog.s135.com/soft/linux/nginx_php/eaccelerator/eaccelerator-0.9.6.1.tar.bz2

wget http://blog.s135.com/soft/linux/nginx_php/pdo/PDO_MYSQL-1.0.2.tgz

wget http://blog.s135.com/soft/linux/nginx_php/imagick/ImageMagick.tar.gz

wget http://blog.s135.com/soft/linux/nginx_php/imagick/imagick-2.3.0.tgz

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.12.tar.gz

wget http://nginx.org/download/nginx-1.0.1.tar.gz

 

**************************************************************************************

 

 一.PHP的安装及相关包安装

原本php5.3.6是最新稳定版本,但网上新闻说其代码已受污染,只好改用5.2.17

先安装所需的支持库:

1. Libiconv     (字符编辑库,转编码用)

1.13.1是最新版本,libiconv库为需要做转换的应用提供了一个iconv()的函数,以实现一个字符编码到另一个字符编码的转换

       wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz

tar zxvf libiconv-1.13.1.tar.gz

cd libiconv-1.13.1/

./configure --prefix=/usr/local

make

make install

cd ../

 

2. libmcrypt   (加密算法扩展库,用以各种加密码)

Libmcript是默认安装在/usr/local下的

wget "http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?modtime=1171868460&big_mirror=0"

tar zxvf libmcrypt-2.5.8.tar.gz

cd libmcrypt-2.5.8/

./configure

make

make install

cd libltdl

./configure -enable-ltdl-install

make

make install

cd http://www.cnblogs.com/

 

3.  mhash  (哈希函数库,加密及字符串处理用)

wget "http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?modtime=1175740843&big_mirror=0"

tar zxvf mhash-0.9.9.9.tar.gz

cd mhash-0.9.9.9/

./configure

make

make install

cd ../

将以上两个加密库文件都以符号链接的形式指到系统库里去,以便可以编译时可以直接调用

ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la

ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so

ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4

ln -s /usr/local/lib/libmcrypt.so.4.4.8/usr/lib/libmcrypt.so.4.4.8

ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a

ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la

ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so

ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2

ln -s /usr/local/lib/libmhash.so.2.0.1/usr/lib/libmhash.so.2.0.1

ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config

 

4.  mcrypt     (一个加密库,直接对应php扩展)

mcrypt是一个简单的PHPClass,提供用于处理基于mcrypt的加密和解密功能

wget "http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?modtime=1194463373&big_mirror=0"

tar zxvf mcrypt-2.6.8.tar.gz

cd mcrypt-2.6.8/

LD_LIBRARY_PATH=/usr/local ./configure

make

make install

cd ../

说明: 由于在配置Mcrypt时,会找不到libmcrypt的链接库,导致无法编译,

因为Libmcrypt的链接库在/usr/local/文件夹下。因些在配置mcrypt时要加入LD_LIBRARY_PATH=/usr/local导入键接库

下面是以上三个加密库的安装的调用图

 

 

*******************************************************************************

 

以下为mysql下载及安装.因为连接的是另外的远程服务端上已配置好的mysql,相关配置这里不讲了,但为了后面的配置能顺利进行,在nginx网站服务器上也需要进行安装

mysql部分,直接去官网注册个账号下载.貌似迅雷会快些,但还要上传至服务器.以下列表为5.5.11-1的版本参考下载地址  Red Hat版本的  x386 32位

还是用wget 选台湾的镜像ftp下载比较快下.以为包括服务端,客户端,共享包和开发包. server和client必装.还有devel和shared包最好也装上.安装之前先检查系统里是否有自带的mysql.如果有的话就卸载掉.安装顺序一般server>client>devel>shared

 

wget http://ftp.jaist.ac.jp/pub/mysql/Downloads/MySQL-5.5/MySQL-client-5.5.11-1.rhel5.i386.rpm

wget http://mysql.spd.co.il/Downloads/MySQL-5.5/MySQL-devel-5.5.11-1.rhel5.i386.rpm

wget ftp://ftp.ntu.edu.tw/pub/MySQL/Downloads/MySQL-5.5/MySQL-server-5.5.11-1.rhel5.i386.rpm

wget ftp://ftp.cs.pu.edu.tw/Unix/mysql/Downloads/MySQL-5.5/MySQL-shared-5.5.11-1.rhel5.i386.rpm

rpm -ivh MySQL-server-5.5.11-1.rhel5.i386.rpm

rpm -ivh MySQL-client-5.5.11-1.rhel5.i386.rpm

rpm -ivh MySQL-devel-5.5.11-1.rhel5.i386.rpm

rpm -ivh MySQL-shared-5.5.11-1.rhel5.i386.rpm

 

测试启动:

service mysql start

service mysql stop

或者

/etc/rc.d/init.d/mysql start

/etc/rc.d/init.d/mysql stop

*******************************************************************************

 

5. 安装php及fpm

查到php最新稳定版是5.3.6(17 March 2011),但网上有新闻说其代码已经被污染.所以下载了前一个稳定版本5.2.17

php-5.2.17-fpm-0.5.14为其对应的fpm补丁包.   Fpm是一个PHP FastCGI 进程管理器 FastCGI是一个可伸缩的,高速地在web server和脚本语言间交互的接口.

php-fpm是为PHP打的一个FastCGI管理补丁,可以平滑变更php.ini配置而无需重启php-cgi

wget http://cn.php.net/distributions/php-5.2.17.tar.gz

wget http://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gz

 

tar zxvf php-5.2.17.tar.gz

打补丁,用以上命令解压覆盖到php-5.2.17文件夹下

gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1  

以下的php配置关联了许多库,有些可能用不到.考虑到扩展性这里全部关联上, 另外,如果mysql以rpm方式安装,注意其路径(where is mysql)

cd php-5.2.17/

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr --with-mysqli=/usr/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap

(make ZEND_EXTRA_LIBS='-liconv' )是编译,make 前面可能有其他补丁的,先让前面的步骤走完,然后把其他补丁完的文件下载下来,加上这个防webshell的修改,上传覆盖,再接着make编译,安装。

make ZEND_EXTRA_LIBS='-liconv'

make install

cp php.ini-dist /usr/local/php/etc/php.ini

cd ../

 

以下装memcache及eaccelerator是为了php加速用的.

6. memcache  (一个高性能的分布式的内存对象缓存系统)

wget http://pecl.php.net/get/memcache-2.2.5.tgz

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 ../

 

7. eaccelerator  eAccelerator是一个自由开放源码php加速器

wget http://bart.eaccelerator.net/source/0.9.6.1/eaccelerator-0.9.6.1.tar.bz2

tar jxvf eaccelerator-0.9.6.1.tar.bz2

cd eaccelerator-0.9.6.1/

/usr/local/php/bin/phpize

./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config

make

make install

cd ../

 

8. PDO_MYSQL

PDO_MYSQL是PHP Data Objects (PDO) interface的一个mysql扩展,YII框架也必须要用到.

wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz

tar zxvf 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/

make

make install

cd ../

 

9. ImageMagick

一套功能强大、稳定而且免费的图像处理及转换的工具集和开发包

wget http://blog.s135.com/soft/linux/nginx_php/imagick/ImageMagick.tar.gz

tar zxvf ImageMagick.tar.gz

cd ImageMagick-6.5.1-2/

./configure

make

make install

cd ../

 

10. imagick同上,也是进行图形处理的包

wget http://pecl.php.net/get/imagick-2.3.0.tgz

tar zxvf imagick-2.3.0.tgz

cd imagick-2.3.0/

/usr/local/php/bin/phpize

./configure --with-php-config=/usr/local/php/bin/php-config

make

make install

cd ../

 

至此,php相关的安装过程结束,以下为相关配置: -----------------------------------------------------------

 

11、修改php.ini文件

手工修改:

查找/usr/local/php/etc/php.ini中的extension_dir = "./"

修改为extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"

或者将以上路径下的.so文件拷贝进指定的扩展目录下也可以

  并在此行后增加以下几行,然后保存:

  extension = "memcache.so"

  extension = "pdo_mysql.so"

  extension = "imagick.so"

  再查找output_buffering = Off

  修改为output_buffering = On

  再查找; cgi.fix_pathinfo=0

  去掉注释, 修改为cgi.fix_pathinfo=0,防止Nginx文件类型错误解析漏洞。

自动修改(就是用sed作字符替换):

sed -i 's#extension_dir = "./"#extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"\nextension = "memcache.so"\nextension = "pdo_mysql.so"\nextension = "imagick.so"\n#' /usr/local/php/etc/php.ini

sed -i 's#output_buffering = Off#output_buffering = On#' /usr/local/php/etc/php.ini

sed -i "s#; always_populate_raw_post_data = On#always_populate_raw_post_data = On#g" /usr/local/php/etc/php.ini

sed -i "s#; cgi.fix_pathinfo=0#cgi.fix_pathinfo=0#g" /usr/local/php/etc/php.ini

 

12. 配置eAccelerator加速PHP

这里暂时看不懂,照做就OK了,

mkdir -p /usr/local/eaccelerator_cache

vi /usr/local/php/etc/php.ini

在最后加上:

[eaccelerator]

zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"

eaccelerator.shm_size="64"

eaccelerator.cache_dir="/usr/local/eaccelerator_cache"

eaccelerator.enable="1"

eaccelerator.optimizer="1"

eaccelerator.check_mtime="1"

eaccelerator.debug="0"

eaccelerator.filter=""

eaccelerator.shm_max="0"

eaccelerator.shm_ttl="3600"

eaccelerator.shm_prune_period="3600"

eaccelerator.shm_only="0"

eaccelerator.compress="1"

eaccelerator.compress_level="9"

 

13. 创建一个专门管理网站的用户,如教育

/usr/sbin/groupadd www

/usr/sbin/useradd -g www www

mkdir -p /home/html/foredu

chmod +w /home/html/foredu

 

14. 修改php-fpm配置文件

       重新配置一份php-fpm.conf

mv /usr/local/php/etc/php-fpm.conf /usr/local/php/etc/php-fpm.conf.bak

vi /usr/local/php/etc/php-fpm.conf

内容如下:

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

 

    Pid file

    /usr/local/php/logs/php-fpm.pid

    Error log file

    /usr/local/php/logs/php-fpm.log

    Log level

    notice

    When this amount of php processes exited with SIGSEGV or SIGBUS ...

    10

    ... 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.

    1m

    Time limit on waiting child's reaction on signals from master

    5s

    Set to 'no' to debug fpm

    yes

 

 

   

      Name of pool. Used in logs and stats.

      default

      Address to accept fastcgi requests on.

      Valid syntax is 'ip.ad.re.ss:port' or just 'port' or '/path/to/unix/socket'

      127.0.0.1:9000

     

        Set listen(2) backlog

        -1

        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.

       

       

        0666

     

      Additional php.ini defines, specific to this pool of workers.

     

        /usr/sbin/sendmail -t -i

        0

     

      Unix user of processes

      www

      Unix group of processes

      www

      Process manager settings

     

        Sets style of controling worker process count.

        Valid values are 'static' and 'apache-like'

        static

        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.

        128

        Settings group for 'apache-like' pm style

       

          Sets the number of server processes created on startup.

          Used only when 'apache-like' pm_style is selected

          20

          Sets the desired minimum number of idle server processes.

          Used only when 'apache-like' pm_style is selected

          5

          Sets the desired maximum number of idle server processes.

          Used only when 'apache-like' pm_style is selected

          35

       

     

      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'

      0s

      The timeout (in seconds) for serving of single request after which a php backtrace will be dumped to slow.log file

      '0s' means 'off'

      0s

      The log file for slow requests

      logs/slow.log

      Set open file desc rlimit

      65535

      Set max core size rlimit

      0

      Chroot to this directory at the start, absolute path

     

      Chdir to this directory at the start, absolute path

     

      Redirect workers' stdout and stderr into main error log.

      If not set, they will be redirected to /dev/null, according to FastCGI specs

      yes

      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

      1024

      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.

      127.0.0.1

      Pass environment variables like LD_LIBRARY_PATH

      All $VARIABLEs are taken from current environment

     

        $HOSTNAME

        /usr/local/bin:/usr/bin:/bin

        /tmp

        /tmp

        /tmp

        $OSTYPE

        $MACHTYPE

        2

     

   

 

如果安装 Nginx + PHP 用于程序调试,请将以下的0改为1,以便显示PHP错误信息,否则,Nginx 会报状态为500的空白错误页,另外, php-cgi进程,监听127.0.0.1的9000端口,进程数为128(如果服务器内存小于3GB,可以只开启64个进程),用户为www, 都是在以上的进行的配置

 

启动命令:

ulimit -SHn 65535
/usr/local/php/sbin/php-fpm start

 

start|stop|quit|restart|reload|logrotate,修改php.ini后不重启php-cgi,重新加载配置文件使用reload

至此,php相关安装及配置完成.

 

二.Nginx的安装

1、安装nginx所需的pcre库:

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.12.tar.gz

tar zxvf pcre-8.12.tar.gz

cd pcre-8.12/

./configure

make && make install

cd ../

 

2. 安装nginx

wget http://nginx.org/download/nginx-1.0.1.tar.gz

tar zxvf nginx-1.0.1.tar.gz

cd nginx-1.0.1/

./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

make && make install

cd ../

 

3. 创建nginx日志目录

mkdir -p /home/logs

chmod +w /home/logs

chown -R www:www /home/logs

4. 修改nginx.conf的文件

mv  /usr/local/nginx/conf/nginx.conf  /usr/local/nginx/conf/nginx.conf.bak

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

以下为内容:

user  www www;

worker_processes 8;

error_log  /home/logs/nginx_error.log  crit;

pid        /usr/local/nginx/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.

worker_rlimit_nofile 65535;

events

{

  use epoll;

  worker_connections 65535;

}

http

{

  include       mime.types;

  default_type  application/octet-stream;

  #charset  gb2312;

     

  server_names_hash_bucket_size 128;

  client_header_buffer_size 32k;

  large_client_header_buffers 4 32k;

  client_max_body_size 8m;

     

  sendfile on;

  tcp_nopush     on;

  keepalive_timeout 60;

  tcp_nodelay on;

 

  fastcgi_connect_timeout 300;

  fastcgi_send_timeout 300;

  fastcgi_read_timeout 300;

  fastcgi_buffer_size 64k;

  fastcgi_buffers 4 64k;

  fastcgi_busy_buffers_size 128k;

  fastcgi_temp_file_write_size 128k;

 

  gzip on;

  gzip_min_length  1k;

  gzip_buffers     4 16k;

  gzip_http_version 1.0;

  gzip_comp_level 2;

  gzip_types       text/plain application/x-javascript text/css application/xml;

  gzip_vary on;

  #limit_zone  crawler  $binary_remote_addr  10m;

  server

  {

    listen       80;

    server_name  www.2277.com;

    index index.html index.htm index.php;

    root  /home/html/foredu/test;

 

    #limit_conn   crawler  20;   

                            

    location ~ .*\.(php|php5)?$

    {     

      #fastcgi_pass  unix:/tmp/php-cgi.sock;

      fastcgi_pass  127.0.0.1:9000;

      fastcgi_index index.php;

      include fcgi.conf;

    }

   

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

    {

      expires      30d;

    }

 

    location ~ .*\.(js|css)?$

    {

      expires      1h;

    }   

 

    log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '

              '$status $body_bytes_sent "$http_referer" '

              '"$http_user_agent" $http_x_forwarded_for';

    access_log  /home/logs/access.log  access;

      }

#以下两段没有什么用处

  server

  {

    listen       80;

    server_name  www.2277.com;

    index index.html index.htm index.php;

    root  /data0/htdocs/www;

 

    location ~ .*\.(php|php5)?$

    {     

      #fastcgi_pass  unix:/tmp/php-cgi.sock;

      fastcgi_pass  127.0.0.1:9000;

      fastcgi_index index.php;

      include fcgi.conf;

    }

 

    log_format  wwwlogs  '$remote_addr - $remote_user [$time_local] "$request" '

               '$status $body_bytes_sent "$http_referer" '

               '"$http_user_agent" $http_x_forwarded_for';

    access_log  /home/logs/wwwlogs.log  wwwlogs;

  }

 

  server

  {

    listen  80;

    server_name  status.2277.com;

 

    location / {

    stub_status on;

    access_log   off;

    }

  }

}

 

5. 在/usr/local/nginx/conf/目录中创建fcgi.conf文件:

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;

 

启动Nginx

ulimit -SHn 65535

/usr/local/nginx/sbin/nginx

 

三.YII框架

 

1. 将YII框架代码及写好的test文件代码打包上传至/home/html/foredu下

    2. 确认nginx.conf中的域名及文件夹位置正确.如有修改则重启相关服务

    3. test代码文件中,以下文件夹权限设置为777(这里面都会生成文件)

upload

assets

protected/runtime

protected/manager/runtime

js/kindeditor/attached 此目录可能需要手工建

4. 修改protected/config/db.php中的数据库的配置项

5. 测试打开test页面

 

四. 其他优化项

配置到以上即可.

以下为系统优化项,也可以略过****************************************************************

1. 如果是加到开机启动项中:

       ulimit -SHn 65535

/usr/local/php/sbin/php-fpm start

/usr/local/nginx/sbin/nginx

 

2.优化linux内核参数

vi /etc/sysctl.conf

末尾增加:

       # Add

net.ipv4.tcp_max_syn_backlog = 65536

net.core.netdev_max_backlog =  32768

net.core.somaxconn = 32768

 

net.core.wmem_default = 8388608

net.core.rmem_default = 8388608

net.core.rmem_max = 16777216

net.core.wmem_max = 16777216

 

net.ipv4.tcp_timestamps = 0

net.ipv4.tcp_synack_retries = 2

net.ipv4.tcp_syn_retries = 2

 

net.ipv4.tcp_tw_recycle = 1

#net.ipv4.tcp_tw_len = 1

net.ipv4.tcp_tw_reuse = 1

 

net.ipv4.tcp_mem = 94500000 915000000 927000000

net.ipv4.tcp_max_orphans = 3276800

 

#net.ipv4.tcp_fin_timeout = 30

#net.ipv4.tcp_keepalive_time = 120

net.ipv4.ip_local_port_range = 1024  65535

 

使配置生效: /sbin/sysctl –p

 

3. 测试及平滑变更nginx配置

       每次修改nginx.conf后,可以用以下命令测试语法是否正确:

       /usr/local/nginx/sbin/nginx –t

       OK的话屏幕显示以下两行信息,说明配置文件正确:

  the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

  the configuration file /usr/local/nginx/conf/nginx.conf was tested successfully

平滑重启:

/usr/local/nginx/sbin/nginx –s reload

定时切割日志:

vi /usr/local/nginx/sbin/cut_nginx_log.sh

内容如下:

        # This script run at 00:00

# The Nginx logs path

logs_path="/usr/local/nginx/logs/"

 

mkdir -p ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/

mv ${logs_path}access.log ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/access_$(date -d "yesterday" +"%Y%m%d").log

kill -USR1 `cat /usr/local/nginx/nginx.pid`

 

crontab –e

00 00 * * * /bin/bash  /usr/local/nginx/sbin/cut_nginx_log.sh

********************************************************************************

全文完..

你可能感兴趣的:(linux)