Linux, Ningx, MySQL, PHP - LNMP


CentOS

安装 EPEL 源

yum install -y epel-release

安装软件

yum -y install nginx
yum -y install mysql-server
yum -y install php-fpm
yum -y install php-mysql
yum -y install php-gd
yum -y install php-mbstring
yum -y install php-mcrypt
yum -y install php-mhash
yum -y install php-pdo
yum -y install php-tidy
yum -y install php-xml
yum -y install php-xmlrpc
yum -y install php-eaccelerator
yum -y install php-pecl-memcache

Debian

安装 DEB 源

# add the source to /etc/apt/sources.list
# the latest mysql package source
sudo echo "deb http://packages.dotdeb.org stable all" >> /etc/apt/sources.list
sudo echo "deb-src http://packages.dotdeb.org stable all" >> /etc/apt/sources.list
# the latest php packages source
sudo echo "deb http://php53.dotdeb.org stable all" >> /etc/apt/sources.list
sudo echo "deb-src http://php53.dotdeb.org stable all" >> /etc/apt/sources.list
# the latest nginx packages source
sudo echo "deb http://ppa.launchpad.net/nginx/development/ubuntu lucid main" >> /etc/apt/sources.list
# for two missing packages(libicu, libkrb)
# ubuntu 10.10 beta does not need this
# sudo echo "deb http://security.ubuntu.com/ubuntu jaunty-security main" >> /etc/apt/sources.list
# add the gpg key
# gpg --keyserver keys.gnupg.net --recv-key 89DF5277
# gpg -a --export 89DF5277 | sudo apt-key add -
sudo apt-key adv --keyserver keys.gnupg.net --recv-keys 89DF5277
# add ppa gpg key
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C300EE8C

安装软件

sudo apt-get install nginx
sudo apt-get install mysql-server
sudo apt-get install php-fpm

Nginx

user nobody nobody;
worker_processes 1;
worker_rlimit_nofile 51200;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

events {
    use epoll;
    worker_connections 1024;
}

http {
    #charset utf-8
    include      mime.types;
    default_type application/octet-stream;

    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 /var/log/nginx/access.log access;

    gzip              on;
    gzip_min_length   1000;
    gzip_buffers      4 8k;
    gzip_types        text/* text/css application/javascript application/x-javascript;
    gzip_comp_level   9;
    gzip_proxied      any;
    gzip_vary         on;
    gzip_http_version 1.1;

    sendfile on;
    tcp_nopush on;
    output_buffers  4 32k;
    postpone_output 1460;
    keepalive_timeout 30;
    server_names_hash_bucket_size 128;
    server_name_in_redirect off;
    client_header_buffer_size 128k;
    large_client_header_buffers 4 256k;
    client_header_timeout 1m;
    client_body_timeout   1m;
    send_timeout          1m;

    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;

    #log proxy errors
    #proxy_intercept_errors on;
    
    include doku.conf;
}
server {
    #charset utf-8;
    listen       80;
    server_name  localhost;    

    if (-d $request_filename) {
        rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
    }

    location / {
        root      /var/www/html/www;
        index     index.html index.htm index.php;
        #autoindex on;
        
        rewrite ^(/)_media/(.*) $1lib/exe/fetch.php?media=$2 last;
        rewrite ^(/)_detail/(.*) $1lib/exe/detail.php?media=$2 last;
        rewrite ^(/)_export/([^/]+)/(.*) $1doku.php?do=export_$2&id=$3 last;
        
        if (!-f $request_filename) {
            rewrite ^(/)(.*)?(.*)  $1doku.php?id=$2&$3 last;
            rewrite ^(/)$ $1doku.php last;
        }
    }

    # redirect 404 error page to the static page /404.html
    error_page 404 /404.html;
    location = /404.html {
        root html;
    }

    # redirect server error pages to the static page /50x.html
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root html;
    }

    # make the static file expires in 30 days.
    location ~* ^.+\.(jpg|jpeg|gif|png|bmp|swf|flv|css|js)$ {
        root       /var/www/html/www;
        access_log off;
        expires    30d;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #location ~ \.php$ {
    #    proxy_pass http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    location ~ .+\.php$ {
        root          /var/www/html/www;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include       fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    location ~ /\.ht {
        deny all;
    }
}

MySQL

service mysqld start
mysql_secure_installation