下载地址,http://dev.mysql.com/downloads/mysql/
选择源码下载:source code
文件:mysql-5.5.9.tar.gz

下载后在下载目录
 $ sudo tar zxvf mysql-5.5.9.tar.gz
 查看文件夹下INSTALL-SOURCE文件,里面有各个系统的编译安装方式(英文)
 注意,安装前应当注意安装工具的完善,否则编译的时候将出错,本帖稍后的部分给出了工具列表。这里先给出安装命令。
 linux下源码的安装方式如下:

 # 安装前配置
 shell> groupadd mysql
 shell> useradd -r -g mysql mysql

 # 开始源码编译安装
 shell> tar zxvf mysql-VERSION.tar.gz
 shell> cd mysql-VERSION
 shell> cmake .
 shell> make
 shell> make install
 # 结束编译安装

 # 初始化,下列命令使mysql得到对数据库文件的拥有权。mysql_install_db脚本能刷新授权表
 shell> cd /usr/local/mysql
 shell> chown -R mysql .
 shell> chgrp -R mysql .
 shell> scripts/mysql_install_db --user=mysql
 shell> chown -R root .
 shell> chown -R mysql data
 # 可选命令,配置文件位置更改,且内有五种配置模式。
 shell> cp support-files/my-medium.cnf /etc/my.cnf
 shell> bin/mysqld_safe --user=mysql &
 # 可选命令,自启动脚本,可以mysql自动启动。
 shell> cp support-files/mysql.server /etc/init.d/mysql.server

 会遇到的问题:
 ----------------------------------------------------------
 -- MySQL 5.5.9
 -- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)
 CMake Error at cmake/readline.cmake:82 (MESSAGE):
 Curses library not found. Please install appropriate package,remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu , package name is libncurses5-dev,on RedHat and derivates it is ncurses-devel.
 Call Stack (most recent call first):
 cmake/readline.cmake:126 (FIND_CURSES)
 cmake/readline.cmake:216 (MYSQL_USE_BUNDLED_LIBEDIT)
 CMakeLists.txt:256 (MYSQL_CHECK_READLINE)
 ----------------------------------------------------------
 如回显所示,ubuntu下安装libncurses5-dev;redhat下安装ncurses-devel,并删除当前目录CMakeCache.txt(必须删除,否则报错依旧)并重新运行:
 $ cmake .
 命令
 ----------------------------------------------------------
 -- Performing Test HAVE_PEERCRED
 -- Performing Test HAVE_PEERCRED - Success
 Warning: Bison executable not found in PATH
 -- Configuring done
 -- Generating done
 -- Build files have been written to: /home/user/downloads/mysql-5.5.9
 ----------------------------------------------------------
 一个警告总算不爽,如回显所见,安装bison。
 $ sudo apt-get install bison
 ----------------------------------------------------------
 这是两个比较多的问题。



 问题总结:
 后来查看了官方的文档,编译安装的时候工具必须要有下列5个。
 =>安装工具:
 1. cmake
 ----没有自己编译安装cmake
 ----shell:~$ sudo apt-get install cmake
 ----版本:2.8.2
 2.GNU make
 ----Ubuntu自带
 ----版本:3.81
 3.GCC
 ----Ubuntu自带
 ----版本:4.4.5(官方文档:必须3.2以上)
 4.Perl
 ----Ubuntu自带
 ----版本:5.10.1
 5.libncurses5-dev (ncurses-devel)
 ----若差了这个包,在cmake的时候会报错。
 ----Debian/Ubuntu上的包名是libncurses5-dev,RedHat和其他版本对应的是ncurses-devel
 ----shell:~$ sudo apt-get install libncurses5-dev




 开启mysql:
 cd . ; ./bin/mysqld_safe &
 当然你用root命令开启的时候,应当使用--user参数,这样才是安全的启动方式。
 cd . ; ./bin/mysqld_safe --user=mysql &

 为root和你的用户名设置密码,这需要在你先启动mysql的基础上,否则会报错,说你没有连接到端口:
 ./bin/mysqladmin -u root password 'new-password'
 ./bin/mysqladmin -u root -h YourusernamE password 'new-password'
 也可一用下命令替代:
 ./bin/mysql_secure_installation


 2、编译安装php-fpm

 #相关代码, [四号程序员] http://www.coder4.com
 #下载
 wget http://us.php.net/distributions/php-5.3.6.tar.bz2
 tar -xjvf php-5.3.6.tar.bz2
 cd php-5.3.6
  
 #相关库
 sudo apt-get install libxml2-dev zlib1g-dev libcurl4-openssl-dev libpng12-dev libmcrypt-dev
  
 #configure
 './configure' '--prefix=/usr/local/php' '--with-config-file-path=/etc/php' '--disable-cli' '--enable-fpm' '--with-fpm-user=www' '--with-fpm-group=www' '--with-zlib' '--with-curl' '--with-gd' '--with-mhash' '--enable-mbstring' '--with-mcrypt' '--with-mysql=/usr/local/mysql' '--with-mysqli=/usr/local/mysql/bin/mysql_config' '--enable-pdo' '--enable-soap' '--enable-sockets' '--with-xmlrpc' '--enable-zip' '--with-pear' 
  
 #make
 make
  
 提示出错
 /usr/local/mysql/include/mysql/my_sys.h:964:27: error: mysql/psi/psi.h: No such file or directory
 /usr/local/mysql/include/mysql/m_string.h:219:26: error: mysql/plugin.h: No such file or directory
 /usr/local/mysql/include/plugin.h:51:28: 错误:mysql/services.h:没有那个文件或目录
 /usr/local/mysql/include/services.h:21:39: 错误:mysql/service_my_snprintf.h:没有那个文件或目录
 /usr/local/mysql/include/services.h:22:37: 错误:mysql/service_thd_alloc.h:没有那个文件或目录
 /usr/local/mysql/include/services.h:23:36: 错误:mysql/service_thd_wait.h:没有那个文件或目录
 /usr/local/mysql/include/services.h:24:44: 错误:mysql/service_thread_scheduler.h:没有那个文件或目录
 #修复MySQL的BUG
 mkdir /usr/local/mysql/include/mysql
 ln -s /usr/local/mysql/include/* /usr/local/mysql/include/mysql
 vi /usr/local/mysql/include/my_sys.h
 找到
  #include <mysql/psi/psi.h>
 修改为
  #include <psi/psi.h>
  
 vi /usr/local/mysql/include/m_string.h
 找到
  #include < mysql/plugin.h>
 修改为
  #include <plugin.h>
 vi /usr/local/mysql/include/plugin.h
 找到
  #include <mysql/services.h>
 修改为
  #include <services.h>

 出现以下错误:
 ext/gd/libgd/.libs/gdkanji.o: In function `do_convert':
 /root/php-5.2.12/ext/gd/libgd/gdkanji.c:350: undefined reference to `libiconv_open'
 /root/php-5.2.12/ext/gd/libgd/gdkanji.c:365: undefined reference to `libiconv'
 /root/php-5.2.12/ext/gd/libgd/gdkanji.c:381: undefined reference to `libiconv_close'
 ext/iconv/.libs/iconv.o: In function `_php_iconv_strlen':
 /root/php-5.2.12/ext/iconv/iconv.c:603: undefined reference to `libiconv_open'
 /root/php-5.2.12/ext/iconv/iconv.c:626: undefined reference to `libiconv'
 /root/php-5.2.12/ext/iconv/iconv.c:660: undefined reference to `libiconv_close'
 ext/iconv/.libs/iconv.o: In function `php_iconv_string':
 /root/php-5.2.12/ext/iconv/iconv.c:441: undefined reference to `libiconv_open'
 /root/php-5.2.12/ext/iconv/iconv.c:453: undefined reference to `libiconv'
 /root/php-5.2.12/ext/iconv/iconv.c:467: undefined reference to `libiconv'
 /root/php-5.2.12/ext/iconv/iconv.c:478: undefined reference to `libiconv_close'
 ext/iconv/.libs/iconv.o: In function `_php_iconv_strpos':
 /root/php-5.2.12/ext/iconv/iconv.c:851: undefined reference to `libiconv_open'
 /root/php-5.2.12/ext/iconv/iconv.c:879: undefined reference to `libiconv'
 /root/php-5.2.12/ext/iconv/iconv.c:993: undefined reference to `libiconv_close'
 ext/iconv/.libs/iconv.o: In function `_php_iconv_appendl':
 /root/php-5.2.12/ext/iconv/iconv.c:348: undefined reference to `libiconv'
 /root/php-5.2.12/ext/iconv/iconv.c:385: undefined reference to `libiconv'
 ext/iconv/.libs/iconv.o: In function `_php_iconv_substr':
 /root/php-5.2.12/ext/iconv/iconv.c:723: undefined reference to `libiconv_open'
 /root/php-5.2.12/ext/iconv/iconv.c:747: undefined reference to `libiconv'
 /root/php-5.2.12/ext/iconv/iconv.c:802: undefined reference to `libiconv_close'
 /root/php-5.2.12/ext/iconv/iconv.c:806: undefined reference to `libiconv_close'
 /root/php-5.2.12/ext/iconv/iconv.c:755: undefined reference to `libiconv_open'
 ext/iconv/.libs/iconv.o: In function `_php_iconv_mime_decode':
 /root/php-5.2.12/ext/iconv/iconv.c:1354: undefined reference to `libiconv_open'
 /root/php-5.2.12/ext/iconv/iconv.c:1465: undefined reference to `libiconv_close'
 /root/php-5.2.12/ext/iconv/iconv.c:1468: undefined reference to `libiconv_open'
 /root/php-5.2.12/ext/iconv/iconv.c:1823: undefined reference to `libiconv_close'
 /root/php-5.2.12/ext/iconv/iconv.c:1826: undefined reference to `libiconv_close'
 ext/iconv/.libs/iconv.o: In function `php_iconv_stream_filter_dtor':
 /root/php-5.2.12/ext/iconv/iconv.c:2465: undefined reference to `libiconv_close'
 ext/iconv/.libs/iconv.o: In function `_php_iconv_mime_encode':
 /root/php-5.2.12/ext/iconv/iconv.c:1043: undefined reference to `libiconv_open'
 /root/php-5.2.12/ext/iconv/iconv.c:1057: undefined reference to `libiconv_open'
 /root/php-5.2.12/ext/iconv/iconv.c:1316: undefined reference to `libiconv_close'
 /root/php-5.2.12/ext/iconv/iconv.c:1319: undefined reference to `libiconv_close'
 /root/php-5.2.12/ext/iconv/iconv.c:1176: undefined reference to `libiconv'
 /root/php-5.2.12/ext/iconv/iconv.c:1128: undefined reference to `libiconv'
 /root/php-5.2.12/ext/iconv/iconv.c:1160: undefined reference to `libiconv'
 /root/php-5.2.12/ext/iconv/iconv.c:1319: undefined reference to `libiconv_close'
 /root/php-5.2.12/ext/iconv/iconv.c:1228: undefined reference to `libiconv'
 /root/php-5.2.12/ext/iconv/iconv.c:1259: undefined reference to `libiconv'
 /root/php-5.2.12/ext/iconv/iconv.c:1303: undefined reference to `libiconv'
 ext/iconv/.libs/iconv.o: In function `php_iconv_stream_filter_append_bucket':
 /root/php-5.2.12/ext/iconv/iconv.c:2615: undefined reference to `libiconv'
 /root/php-5.2.12/ext/iconv/iconv.c:2615: undefined reference to `libiconv'
 ext/iconv/.libs/iconv.o:/root/php-5.2.12/ext/iconv/iconv.c:2537: more undefined references to `libiconv' follow
 ext/iconv/.libs/iconv.o: In function `php_iconv_stream_filter_ctor':
 /root/php-5.2.12/ext/iconv/iconv.c:2491: undefined reference to `libiconv_open'
 ext/xmlrpc/libxmlrpc/.libs/encodings.o: In function `convert':
 /root/php-5.2.12/ext/xmlrpc/libxmlrpc/encodings.c:73: undefined reference to `libiconv_open'
 /root/php-5.2.12/ext/xmlrpc/libxmlrpc/encodings.c:81: undefined reference to `libiconv'
 /root/php-5.2.12/ext/xmlrpc/libxmlrpc/encodings.c:101: undefined reference to `libiconv_close'
 collect2: ld returned 1 exit status
 make: *** [sapi/cli/php] ?.. 1

 解决方法:
 [root@server3 ~]$ vim Makefile
 找到下面这行:
 EXTRA_LIBS = -lcrypt   在最后添加-liconv,保存后再make通过,再make install通过。
 ------------------------------------------------------------------------------------------------------------------------------
 EXTRA_LIBS = -lcrypt -lz -lcrypt -lrt -lmysqlclient -lmhash -lmcrypt -lltdl -lldap -llber -lfreetype -lpng -lz -lj
 peg -lcurl -lz -lrt -lresolv -lm -ldl -lnsl -lrt -lxml2 -lz -lm -lssl -lcrypto -ldl -lz -lcurl -ldl -lgssapi_krb5
 -lkrb5 -lk5crypto -lcom_err -lidn -lssl -lcrypto -lz -lxml2 -lz -lm -lmysqlclient -lz -lcrypt -lnsl -lm -lxml2 -lz
  -lm -lxml2 -lz -lm -lcrypt -lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt -liconv
 --------------------------------------------------------------------------------------------------------------------------------
 make clean
 make

 #install
 sudo make install
  
 #user
 cd /usr/local/php
 useradd www
 sudo chown -R www:www ./
  
 #拷贝php配置
 sudo mkdir -p /etc/php
 sudo cp php.ini-production /etc/php/php.ini
  
 #配置
 sudo vim ./etc/php-fpm.conf
 rlimit_files = 1048576
 pm.max_children = 10
 pm.start_servers = 4
 pm.min_spare_servers = 2
 pm.max_spare_servers = 10
 pm.max_requests = 100
  
 #运行
 ./sbin/php-fpm
  
 #添加到开机启动
 ln -s /usr/local/php/sbin/php-fpm /usr/bin/
 vim /etc/rc.local
 #start php-fpm at start
 echo 134217728 > /proc/sys/kernel/shmmax
 php-fpm
  
 #安装APC
 wget http://pecl.php.net/get/APC-3.1.6.tgz
 tar -xzvf APC-3.1.6.tgz
 cd APC-3.1.6
 sudo apt-get install autoconf
 /usr/local/php/bin/phpize
 ./configure --with-php-config=/usr/local/php/bin/php-config
 make
 sudo make install
 #编辑
 vim /etc/sysconfig/php/php.ini
 #修改并添加
 extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626"
 extension=apc.so
 [apc]
 apc.enabled = 1
 apc.shm_segments = 2
 apc.shm_size = 48M

 3、编译安装nginx

 #下载
 wget http://nginx.org/download/nginx-0.8.54.tar.gz
 tar -xzvf nginx-0.8.54.tar.gz
  
 #安装相关包
 sudo apt-get install libpcre3-dev libmhash-dev
  #nginx http push module
http://pushmodule.slact.net/downloads/nginx_http_push_module-0.692.tar.gz
#nginx chunkin module
https://github.com/agentzh/chunkin-nginx-module/zipball/v0.21
 #configure
 ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --add-module=/home/lost/packet/agentzh-chunkin-nginx-module --with-http_ssl_module --add-module=/home/lost/packet/nginx_http_push_module-0.692
 #make
 make
 #install
 sudo make install
 cd /usr/local/nginx
 sudo chown -R www:www .
  
 #配置nginx.conf
 sudo vim conf/nginx.conf
 #如下
 user www www;
 worker_processes  2;
  
 error_log  /usr/local/nginx/logs/error.log;
 pid        /usr/local/nginx/logs/nginx.pid;
  
 worker_rlimit_nofile 1048576;
  
 events {
     use epoll;
     worker_connections  65535;
 }
  
 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"';
  
     sendfile        on;
     tcp_nopush     on;
  
     #keepalive_timeout  0;
     keepalive_timeout  60;
  
     #gzip
     gzip  on;
     gzip_min_length  1k;
     gzip_buffers        4 16k;
     gzip_http_version 1.0;
     gzip_comp_level 6;
     gzip_types  text/plain application/x-javascript text/css application/xml;
     gzip_vary on;
  
     server {
         listen       80;
         server_name  node11.coder4.com;
         root /usr/local/nginx/html;
         access_log  /usr/local/nginx/logs/node11.coder4.com.access.log  main;
  
         location / {
             index  index.php index.html index.htm;
         }
  
         # redirect server error pages to the static page /50x.html
         error_page  404              /404.html;
         error_page   500 502 503 504  /50x.html;
         location = /50x.html {
             root   html;
         }
  
         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
         location ~ /.php$ {
             fastcgi_pass   127.0.0.1:9000;
             fastcgi_index  index.php;
             include        fastcgi_params;
         }
  
         #deny htaccess
         location ~ //.ht {
             deny  all;
         }
  
         #ip
         location ~ .*/.(gif|jpg|jpeg|png|bmp|swf|ico)$ {
             expires      30d;
             access_log   off;
         }
     }
 }
  
 #配置fastcgi_params
 sudo vim conf/fastcgi_params
 #添加一行
 fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;