所需软件包列表:

  1. mysql-5.0.92.tar.gz   
  2. openssl-0.9.8l.tar.gz  
  3. httpd-2.2.17.tar.gz  
  4. libxml2-2.6.31.tar.gz  
  5. freetype-2.3.5.tar.gz  
  6. zxvf zlib-1.2.3.tar.gz  
  7. libpng-1.2.40.tar.gz  
  8. gd-2.0.35.tar.gz  
  9. libmcrypt-2.5.7.tar.gz  
  10. php-5.2.17.tar.gz 

软件包全部安装在 /usr/local目录下,apahce的主目录设在/home/htdoc,mysql的数据目录设在/home/var

安装过程:

1、建立用户

  1. groupadd mysql  
  2. useradd -m mysql -g mysql -d /usr/local/mysql  
  3. groupadd www  
  4. useradd -m www -d /home/www -s /sbin/nologin 

2、安装mysql

  1. tar xzvf mysql-5.0.92.tar.gz  
  2. cd mysql-5.0.92  
  3. ./configure --prefix=/usr/local/mysql --localstatedir=/home/var --with-charset=utf8 --with-extra-charsets=all --with-berkeley-db --with-innodb --without-readline --enable-assembler --with-pthread --enable-thread-safe-client --with-client-ldflags=-all-static  
  4. make   
  5. make install 

编辑mysql配置文件

vi /etc/my.cnf

  1. [client]  
  2. character-set-server = utf8 
  3. port    = 3306 
  4. socket  = /tmp/mysql.sock  
  5.  
  6. [mysqld]  
  7. character-set-server = utf8 
  8. replicate-ignore-db = mysql 
  9. replicate-ignore-db = test 
  10. replicate-ignore-db = information_schema 
  11. user    = mysql 
  12. port    = 3306 
  13. socket  = /tmp/mysql.sock  
  14. basedir = /usr/local/mysql  
  15. datadir = /home/var  
  16. log-error = /home/var/mysql_error.log  
  17. pid-file = /home/var/mysql.pid  
  18. open_files_limit    = 10240 
  19. back_log = 600 
  20. max_connections = 5000 
  21. max_connect_errors = 6000 
  22. table_cache = 614 
  23. external-locking = FALSE 
  24. max_allowed_packet = 32M 
  25. sort_buffer_size = 1M 
  26. join_buffer_size = 1M 
  27. thread_cache_size = 300 
  28. #thread_concurrency = 8 
  29. query_cache_size = 512M 
  30. query_cache_limit = 2M 
  31. query_cache_min_res_unit = 2k 
  32. default-storage-engine = MyISAM 
  33. thread_stack = 192K 
  34. transaction_isolation = READ-COMMITTED  
  35. tmp_table_size = 246M 
  36. max_heap_table_size = 246M 
  37. long_query_time = 3 
  38. log-slave-updates  
  39. log-bin = /home/var/binlog/binlog  
  40. binlog_cache_size = 4M 
  41. binlog_format = MIXED 
  42. max_binlog_cache_size = 8M 
  43. max_binlog_size = 1G 
  44. relay-log-index = /home/var/relaylog/relaylog  
  45. relay-log-info-file = /home/var/relaylog/relaylog  
  46. relay-log = /home/var/relaylog/relaylog  
  47. expire_logs_days = 30 
  48. key_buffer_size = 256M 
  49. read_buffer_size = 1M 
  50. read_rnd_buffer_size = 16M 
  51. bulk_insert_buffer_size = 64M 
  52. myisam_sort_buffer_size = 128M 
  53. myisam_max_sort_file_size = 10G 
  54. myisam_repair_threads = 1 
  55. myisam_recover  
  56.  
  57. interactive_timeout = 120 
  58. wait_timeout = 120 
  59.  
  60. skip-name-resolve  
  61. #master-connect-retry = 10 
  62. slave-skip-errors = 1032,1062,126,1114,1146,1048,1396  
  63.  
  64. #master-host     =   192.168.1.2  
  65. #master-user     =   username 
  66. #master-password =   password  
  67. #master-port     =  3306 
  68.  
  69. server-id = 1 
  70.  
  71. innodb_additional_mem_pool_size = 16M 
  72. innodb_buffer_pool_size = 512M 
  73. innodb_data_file_path = ibdata1:256M:autoextend  
  74. innodb_file_io_threads = 4 
  75. innodb_thread_concurrency = 8 
  76. innodb_flush_log_at_trx_commit = 2 
  77. innodb_log_buffer_size = 16M 
  78. innodb_log_file_size = 128M 
  79. innodb_log_files_in_group = 3 
  80. innodb_max_dirty_pages_pct = 90 
  81. innodb_lock_wait_timeout = 120 
  82. innodb_file_per_table = 0 
  83.  
  84. #log-slow-queries = /home/var/slow.log  
  85. #long_query_time = 10 
  86.  
  87. [mysqldump]  
  88. quick  
  89. max_allowed_packet = 32M 

始初化及相关配置

  1. /usr/local/mysql/bin/mysql_install_db --user=mysql  
  2. chown -R mysql:mysql /home/var  
  3. /usr/local/mysql/bin/mysqld_safe --user=mysql &  
  4. cp ./support-files/mysql.server /etc/rc.d/init.d/mysql  
  5. chmod +x /etc/rc.d/init.d/mysql  
  6. chkconfig --add mysql  
  7. service mysql start  
  8. /usr/local/mysql/bin/mysqladmin -u root password 123456 

3、安装openssl

  1. tar zxvf openssl-0.9.8l.tar.gz  
  2. cd openssl-0.9.8l  
  3. ./config  
  4. make  
  5. make install 

4、安装apache

  1. tar zxvf httpd-2.2.17.tar.gz   
  2. cd httpd-2.2.17  
  3. ./configure --prefix=/usr/local/apache --with-mysql=/usr/local/mysql --enable-module=so --enable-shared=max --enable-rewrite --with-mpm=worker --enable-ssl=static --with-ssl=/usr/local/ssl  
  4. make    
  5. make install  

把apache添加chkconfig

  1. cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd  
  2. vi /etc/rc.d/init.d/httpd  
  3. 加入下面两行:  
  4. #chkconfig:345 85 15  
  5. #description: Start and stops the Apache HTTP Server.  
  6.  
  7. chmod +x /etc/rc.d/init.d/httpd   
  8. chkconfig --add httpd 

5、安装GD、libxml、libmcrypt等支持

  1. #install Libxml  
  2. tar zxvf libxml2-2.6.31.tar.gz   
  3. cd libxml2-2.6.31  
  4. ./configure --prefix=/usr/local/libxml2  
  5. make  
  6. make install  
  7.  
  8. #install jpeg6  
  9. mkdir -pv /usr/local/jpeg6/{,bin,lib,include,man/man1,man1}  
  10. tar zxvf jpegsrc.v6b.tar.gz   
  11. cd jpeg-6b/  
  12. ./configure --prefix=/usr/local/jpeg6 --enable-shared --enable-static  
  13. make   
  14. make install  
  15.  
  16. #install freetype  
  17. tar zxvf freetype-2.3.5.tar.gz   
  18. cd freetype-2.3.5  
  19. ./configure --prefix=/usr/local/freetype  
  20. make  
  21. make install  
  22.  
  23. #install zlib  
  24. tar zxvf zlib-1.2.3.tar.gz   
  25. cd zlib-1.2.3  
  26. ./configure --prefix=/usr/local/zlib  
  27. make  
  28. make install  
  29.  
  30. #install libpng  
  31. tar zxvf libpng-1.2.40.tar.gz   
  32. cd libpng-1.2.40  
  33. cp scripts/makefile.std makefile  
  34. make  
  35. make install  
  36.  
  37. #install gd  
  38. tar zxvf gd-2.0.35.tar.gz   
  39. cd gd-2.0.35  
  40. ./configure --prefix=/usr/local/gd --with-png=/usr/local/libpng --with-zlib=/usr/local/zlib --with-freetype=/usr/local/freetype --with-jpeg=/usr/local/jpeg6 --with-libxml=/usr/local/libxml2  
  41. make  
  42. make install  
  43.  
  44. #install libmcrypt  
  45. tar zxvf libmcrypt-2.5.7.tar.gz   
  46. cd libmcrypt-2.5.7  
  47. ./configure  
  48. make  
  49. make install 

6、安装PHP

  1. tar zxvf php-5.2.17.tar.gz   
  2. cd php-5.2.17   
  3. ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-libxml-dir=/usr/local/libxml2 --with-gd=/usr/local/gd/ --with-jpeg-dir=/usr/local/jpeg6/ --with-zlib-dir=/usr/local/zlib --with-png-dir=/usr/local/lib --with-freetype-dir=/usr/local/freetype --with-mysql=/usr/local/mysql --with-mcrypt=/usr/local/lib/libmcrypt --enable-mbstring --with-openssl --enable-ftp --with-curl --enable-sockets  
  4. make  
  5. make install  
  6. cp php.ini-dist /usr/local/php/lib/php.ini 

7、配置apache与PHP关联

vi /usr/local/apache/conf/httpd.conf

红色为插入,蓝色为修改

  1. ……  
  2. User www  
  3. Group www 
  4. ……  
  5. <IfModule dir_module> 
  6.     DirectoryIndex index.html index.php  
  7. IfModule> 
  8. ……  
  9. AddType application/x-compress .Z  
  10. AddType application/x-gzip .gz .tgz  
  11. AddType application/x-httpd-php .php .html .htm  

8、最后启动服务

  1. service httpd start