知识共享许可协议
本作品采用知识共享署名-非商业性使用-禁止演绎 3.0 未本地化版本许可协议进行许可。

安装 Nginx 1.6.1
  • 下载

    wget http://nginx.org/download/nginx-1.6.1.tar.gz
    tar zxvf nginx-1.6.1.tar.gz
    cd nginx-1.6.1
    
  • 安装

    ./configure --prefix=/opt/nginx --with-cc-opt="-Wno-deprecated-declarations"
    make
    sudo make install
    
  • 配置

    sudo vim /opt/nginx/conf/nginx.conf
    
    user  nobody;
    worker_processes  4;
    
    error_log  logs/error.log;
    
    pid        logs/nginx.pid;
    
    events {
        worker_connections  1024;
    }
    
    http {
        include       mime.types;
        default_type  application/octet-stream;
    
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';
        server_names_hash_bucket_size 128;
        client_header_buffer_size 32k;
        large_client_header_buffers 4 32k;
        client_max_body_size 1024m;
    
        sendfile        on;
        tcp_nopush     on;
    
        keepalive_timeout  65;
    
        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;
        fastcgi_intercept_errors 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;
    
        gzip  on;
    
        access_log  logs/access.log  main;
    
        server {
            listen       80;
            server_name  _;
            return 444;
        }
    
        include /opt/nginx/conf/sites-enabled/*;
        include /opt/nginx/conf/deny.ip;
    
    }
    
    sudo mkdir -p /opt/nginx/conf/sites-enabled/
    touch /opt/nginx/conf/deny.ip
    sudo vim /opt/nginx/conf/sites-enabled/web.dev.conf
    
    server {
        server_name web.dev;
        access_log /Users/nate/www/logs/web.dev.access.log ;
        error_log /Users/nate/www/logs/web.dev.error.log ;
        root /Users/nate/www/web.dev/public;
    
        error_page 404 /404.html;
    
        location / {
            root /Users/nate/www/web.dev/public;
            index index.html index.htm index.php;
        }
    
        location ~ \.php$ {
            include /opt/nginx/conf/fastcgi_params;
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME /Users/nate/www/web.dev/public$fastcgi_script_name;    }
    }
    
    设定目录
    mkdir -p /Users/nate/www/web.dev/public
    mkdir -p /Users/nate/www/logs
    
  • 启动

    sudo ln -s /opt/nginx/sbin/nginx /usr/bin/nginx     
    sudo nginx
    
  • 停止

    sudo killall nginx
    ps aux | grep nginx | grep -v grep | awk '{print $2}' | xargs -n 1 sudo kill -9
    
安装 PHP
  • 安装ICU

    wget http://download.icu-project.org/files/icu4c/4.8.1.1/icu4c-4_8_1_1-src.tgz
    tar zxvf icu4c-4_8_1_1-src.tgz
    cd icu/source
    
    ./runConfigureICU MacOSX
    make
    sudo make install
    
  • 安装 gettext

    wget http://ftp.gnu.org/gnu/gettext/gettext-latest.tar.gz
    tar zxvf gettext-latest.tar.gz
    cd gettext-0.19.2/
    
    ./configure
    make
    sudo make install
    
  • 下载

    wget http://cn2.php.net/get/php-5.5.15.tar.gz/from/this/mirror -O ./php-5.5.15.tar.gz
    tar zxvf php-5.5.15.tar.gz
    cd php-5.5.15
    
  • 安装

    ./configure \
     --prefix=/opt/php \
     --with-gd \
     --with-jpeg-dir \
     --with-png-dir \
     --with-freetype-dir \
     --with-iconv \
     --with-zlib \
     --enable-xml \
     --enable-bcmath \
     --enable-shmop \
     --enable-sysvsem \
     --enable-inline-optimization \
     --enable-mbregex \
     --enable-fpm \
     --enable-mbstring \
     --enable-ftp \
     --enable-gd-native-ttf \
     --with-openssl \
     --enable-pcntl \
     --enable-sockets \
     --with-xmlrpc \
     --enable-zip \
     --enable-soap \
     --without-pear \
     --with-gettext \
     --enable-session \
     --with-curl \
     --with-mysql=mysqlnd \
     --with-mysqli=mysqlnd \
     --with-pdo-mysql=mysqlnd
    
    make
    sudo make install
    
  • 配置

    sudo cp php.ini-production /opt/php/lib/php.ini
    
    sudo vim /opt/php/lib/php.ini
    
        date.timezone = Asia/Shanghai
    
    sudo cp /opt/php/etc/php-fpm.conf.default /opt/php/etc/php-fpm.conf
    sudo vim /opt/php/etc/php-fpm.conf
        pid = run/php-fpm.pid
        error_log = log/php-fpm.log
        og_level = notice
        daemonize = yes
        rlimit_files = 2560
        limit_core = 0
        process.max = 128
    
        pm.max_children = 100
        pm.start_servers = 30
        pm.min_spare_servers = 20
        pm.max_spare_servers = 80
    
  • 启动

    sudo ln -s /opt/php/sbin/php-fpm /usr/sbin/php-fpm
    sudo ln -s /opt/php/bin/php /usr/bin/php
    sudo php-fpm -D
    
  • 停止

    ps aux | grep php-fpm | grep -v grep  | awk '{print $2}' | xargs -n 1 sudo kill -9
    
安装 MySQL
  • 下载

    http://www.percona.com/software/percona-server
    wget http://www.percona.com/redir/downloads/Percona-Server-5.6/LATEST/source/tarball/percona-server-5.6.19-67.0.tar.gz
    tar zxvf percona-server-5.6.19-67.0.tar.gz
    cd percona-server-5.6.19-67.0
    
  • 检查是否有用户和组

    dscl . -read /Users/mysql
    dscl . -read /Groups/mysql
    
  • cmake

    sudo cmake -DCMAKE_INSTALL_PREFIX=/opt/mysql \
    -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \
    -DDEFAULT_CHARSET=gbk \
    -DDEFAULT_COLLATION=gbk_chinese_ci \
    -DWITH_EXTRA_CHARSETS:STRING=armscii8,ascii,big5,cp1250,cp1251,cp1256,cp1257,cp850,cp852,cp866,cp932,dec8,eucjpms,euckr,gb2312,gbk,geostd8,greek,hebrew,hp8,keybcs2,koi8r,koi8u,latin1,latin2,latin5,latin7,macce,macroman,sjis,swe7,tis620,ucs2,ujis,utf8 \
    -DWITH_MYISAM_STORAGE_ENGINE=1 \
    -DWITH_INNOBASE_STORAGE_ENGINE=1 \
    -DENABLED_LOCAL_INFILE=1 \
    -DMYSQL_DATADIR=/data/mysql \
    -DMYSQL_TCP_PORT=3306 
    
  • 编译安装

    sudo make -j 4
    sudo make install
    
  • 生成配置信息

    https://tools.percona.com/wizard
    
  • 更新配置文件

    sudo vim /etc/my.cnf
    
  • 初始化数据库

    cd /opt/mysql
    sudo chmod 755 ./scripts/mysql_install_db
    sudo mkdir -p /data/mysql
    sudo ./scripts/mysql_install_db --user=mysql --basedir=/opt/mysql --datadir=/data/mysql
    sudo chmod -R 755 /data/mysql
    
    sudo cp /opt/mysql/support-files/mysql.server /opt/mysql/bin/
    sudo chmod a+x /opt/mysql/bin/mysql.server
    
  • 启动

    sudo /opt/mysql/bin/mysql.server start
    
  • 软链接

    sudo ln -s /opt/mysql/bin/mysql /usr/bin/mysql
    
  • 修改密码

    mysql -uroot -p
    
    use mysql;
    select host,user,password from user;
    delete from user where user='';
    update user set password=password('123123') where user='root';
    flush privileges;
    exit
    
  • 重启

    sudo /opt/mysql/bin/mysql.server restart
    
  • 停止

    sudo /opt/mysql/bin/mysql.server stop