Linux+Apache+Mysql+Perl/PHP/Python一组常用来搭建动态网站或者服务器的开源软件,本身都是各自独立的程序,但是因为常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台。我采用 Linux+Apache+Mysql+PHP来进行编译安装。
   以下是编译安装的过程:
   首先下载此次过程中需要的部分rpm包 http://down.51cto.com/data/371324
一、编译安装apache
1、解决依赖关系
要用到的rpm包
apr-1.4.6-1.i386.rpm
apr-devel-1.4.6-1.i386.rpm
apr-util-1.4.1-1.i386.rpm
apr-util-devel-1.4.1-1.i386.rpm
下载完成之后,使用

 
  
  1. #rpm -Uvh ***.rpm

进行升级
httpd-2.4.1编译过程也要依赖于pcre-devel软件包,通过安装光盘安装。
2、编译安装httpd-2.4.1
 

 
  
  1. # tar xf httpd-2.4.1.tar.bz2 
  2. # cd httpd-2.4.1 
 
  
  1. # ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib 


# make && make install
3、修改httpd的主配置文件,设置其Pid文件的路径
编辑/etc/httpd/httpd.conf,添加如下行即可:
PidFile "/var/run/httpd.pid"
4、提供SysV服务脚本/etc/rc.d/init.d/httpd,内容如下:
 

 
  
  1. #!/bin/bash 
  2. # httpd Startup script for the Apache HTTP Server 
  3. # chkconfig: - 85 15 
  4. # description: Apache is a World Wide Web server. It is used to serve \ 
  5. #    HTML files and CGI. 
  6. # processname: httpd 
  7. # config: /etc/httpd/conf/httpd.conf 
  8. # config: /etc/sysconfig/httpd 
  9. # pidfile: /var/run/httpd.pid 
  10.  
  11. # Source function library. 
  12. . /etc/rc.d/init.d/functions 
  13.  
  14. if [ -f /etc/sysconfig/httpd ]; then 
  15. . /etc/sysconfig/httpd 
  16. fi 
  17.  
  18. # Start httpd in the C locale by default. 
  19. HTTPD_LANG=${HTTPD_LANG-"C"} 
  20.  
  21. # This will prevent initlog from swallowing up a pass-phrase prompt if 
  22. # mod_ssl needs a pass-phrase from the user. 
  23. INITLOG_ARGS="" 
  24.  
  25. # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server 
  26. # with the thread-based "worker" MPM; BE WARNED that some modules may not 
  27. # work correctly with a thread-based MPM; notably PHP will refuse to start. 
  28.  
  29. # Path to the apachectl script, server binary, and short-form for messages. 
  30. apachectl=/usr/local/apache/bin/apachectl 
  31. httpd=${HTTPD-/usr/local/apache/bin/httpd} 
  32. prog=httpd 
  33. pidfile=${PIDFILE-/var/run/httpd.pid} 
  34. lockfile=${LOCKFILE-/var/lock/subsys/httpd} 
  35. RETVAL=0 
  36.  
  37. start() { 
  38. echo -n $"Starting $prog: " 
  39. LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS 
  40. RETVAL=$? 
  41. echo 
  42. [ $RETVAL = 0 ] && touch ${lockfile} 
  43. return $RETVAL 
  44.  
  45. stop() { 
  46. echo -n $"Stopping $prog: " 
  47. killproc -p ${pidfile} -d 10 $httpd 
  48. RETVAL=$? 
  49. echo 
  50. [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} 
  51. reload() { 
  52. echo -n $"Reloading $prog: " 
  53. if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then 
  54. RETVAL=$? 
  55. echo $"not reloading due to configuration syntax error" 
  56. failure $"not reloading $httpd due to configuration syntax error" 
  57. else 
  58. killproc -p ${pidfile} $httpd -HUP 
  59. RETVAL=$? 
  60. fi 
  61. echo 
  62.  
  63. # See how we were called. 
  64. case "$1" in 
  65. start) 
  66. start 
  67. ;; 
  68. stop) 
  69. stop 
  70. ;; 
  71. status) 
  72. status -p ${pidfile} $httpd 
  73. RETVAL=$? 
  74. ;; 
  75. restart) 
  76. stop 
  77. start 
  78. ;; 
  79. condrestart) 
  80. if [ -f ${pidfile} ] ; then 
  81. stop 
  82. start 
  83. fi 
  84. ;; 
  85. reload) 
  86. reload 
  87. ;; 
  88. graceful|help|configtest|fullstatus) 
  89. $apachectl $@ 
  90. RETVAL=$? 
  91. ;; 
  92. *) 
  93. echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}" 
  94. exit 1 
  95. esac 
  96.  
  97. exit $RETVAL 

而后为此脚本赋予执行权限:
# chmod +x /etc/rc.d/init.d/httpd
加入服务列表:
# chkconfig --add httpd


接下来就可以启动服务进行测试。
二、安装mysql-5.5.19
1、准备数据存放的文件系统
新建一个逻辑卷:

 
  
  1. #fdisk /dev/sda 


假设我们的物理卷组为sda5
创建物理卷:

 
  
  1. #pvcreate /dev/sda5 


创建卷组:

 
  
  1. #vgcreate myvg /dev/sda5 


创建逻辑卷:

 
  
  1. #lvcreate -L 4G -n mydata myvg 


格式化:

 
  
  1. #mkfs -t ext3 /dev/myvg/mydata 


并将其挂载至/mydata/data 目录,此目录作为mysql数据的存放路径

 
  
  1. #mkdir -pv /mydata/data 
  2. #mount /dev/sda5 /mydata/data 


实现开机启动
vim /etc/fstab添加如下行:

 
  
  1. /dev/myvg/mydata /mydata ext3 defaults 0 0 


2、新建用户以安全方式运行进程:

 

 
  
  1. # groupadd -r mysql 
  2. # useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql 
  3. # chown -R mysql:mysql /mydata/data 

3、安装并初始化mysql-5.5.19
 

 
  
  1. # tar xf mysql-5.5.19-linux2.6-i686.tar.gz -C /usr/local 
  2. # cd /usr/local/ 
  3. # ln -sv mysql-5.5.19-linux2.6-i686 mysql 
  4. # cd mysql  
  5. # chown -R mysql:mysql . 
  6. # scripts/mysql_install_db --user=mysql --datadir=/mydata/data 
  7. # chown -R root . 

4、为mysql提供主配置文件:

 
  
  1. # cd /usr/local/mysql 
  2. # cp support-files/my-large.cnf /etc/my.cnf 


并修改此文件中thread_concurrency的值为你的CPU个数乘以2,比如这里使用如下行:

 
  
  1. thread_concurrency = 2 


添加如下行来指定mysql数据文件的存放位置:

 
  
  1. datadir = /mydata/data 


5、为mysql提供sysv服务脚本:

 
  
  1. # cd /usr/local/mysql 
  2. # cp support-files/mysql.server /etc/rc.d/init.d/mysqld 


添加至服务列表:

 
  
  1. # chkconfig --add mysqld 
  2. # chkconfig mysqld on 


启动服务测试使用了。
为了使用mysql的安装符合系统使用规范,并将其开发组件导出给系统使用,这里还需要进行如下步骤:
6、输出mysql的man手册至man命令的查找路径:
编辑/etc/man.config,添加如下行即可:
MANPATH /usr/local/mysql/man
7、输出mysql的头文件至系统头文件路径/usr/include:
这可以通过简单的创建链接实现:

 
  
  1. # ln -sv /usr/local/mysql/include /usr/include/mysql 


8、输出mysql的库文件给系统库查找路径:

 
  
  1. # echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf 


而后让系统重新载入系统库:

 
  
  1. # ldconfig 


9、定义环境变量,定义过后直接使用命令#mysql进入数据库

编辑 #vim /etc/profile  添加如下行

 
  
  1. PATH=$PATH:/usr/local/mysql/bin 


  重读配置文件:

 
  
  1. #source /etc/profile 

三、编译安装php-5.3.10

1、解决依赖关系:

请配置好yum源(可以是本地系统光盘)后执行如下命令:

 
  
  1. # yum -y groupinstall "X Software Development"  


安装下列rpm包:
libmcrypt-2.5.7-5.el5.i386.rpm
libmcrypt-devel-2.5.7-5.el5.i386.rpm
2、编译安装php-5.3.10
 

 
  
  1. # tar xf php-5.3.10.tar.bz2 
  2. # cd php-5.3.10 
 
  
  1. # ./configure --prefix=/usr/local/php --with-mcrypt --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --with-apxs2=/usr/local/apache/bin/apxs 


**--with-mcrypt选项以让php支持mycrpt扩展。**

 
  
  1. # make 
  2. # make test  
  3. # make intall 


为php提供配置文件:

 
  
  1. # cp php.ini-production /usr/local/php/lib/php.ini 


3、 编辑apache配置文件httpd.conf,以apache支持php

 
  
  1. # vim /etc/httpd/httpd.conf 


1、添加如下二行

 
  
  1. AddType application/x-httpd-php .php 
  2. AddType application/x-httpd-php-source .phps 


2、定位至DirectoryIndex index.html
修改为:

 
  
  1. DirectoryIndex index.php index.html 


重新启动httpd服务,或让其重新载入配置文件即可测试php是否已经可以正常使用。