LAMP组合: httpd 2.4.2 + mysql-5.5.24 + php-5.3.14编译安装过程:Red Hat Enterprise Linux Server release 5.8

php的安装是基于httpd和mysql的,所以,安装php之前首先要先安装httpd和mysql,这两者先后顺序不作限定。
 
一、首先我们先安装mysql:这里我们使用mysql-5.5.28版本
mysql是一个客户端工具,服务器端是mysqld
客户端用SQL语句通过连接发送至服务器端进行执行,并将结果取回在本地显示。我们只用一台主机做演示,所以客户端和服务器端在同一台主机上。
 
1、先准备mysql数据库中的数据存放的位置即文件系统,在磁盘上新建一个分区,创建出一个逻辑卷,并将其挂载至特定目录下/data下即可。
创建新的分区/dev/sda5,指定类型为8e,大小为20G
partprobe /dev/sda
在/dev/sda5上创建逻辑卷
  1. pvcreate /dev/sda5 
  2. vgcreate myvg /dev/sda5 
  3. lvcreate -L 10G -n mydata myvg 
格式化该逻辑卷
  1. mke2fs -j /dev/myvg/mydata 
新建挂载的目录
  1. mkdir /data 
  2. vim /etc/fstab  #开机自动挂载 
  3. /dev/myvg/mydata    /data   ext3    defaults 0 0 
  4. mount -a #自动挂载一下 
2、新建用户以安全方式运行进程;假设创建目录/data/mydata作为mysql数据的存放位置
  1. groupadd -r mysql 
  2. useradd -r -g mysql mysql 
  3. chown -R mysql.mysql /data/mydata 
3、从ftp://172.16.0.1/pub/Sources/mysql-5.5。下载mysql-5.5.28-linux2.6-i686.tar.gz这个压缩包,解压至指定的路径,这里将它解压到/usr/local目录下,进行安装并初始化。
  1. tar xf mysql-5.5.28-linux2.6-i686.tar.gz -C /usr/local 
  2. cd /usr/local 
  3. ln -sv mysql-5.5.28-linux2.6-i686 mysql 
  4. cd mysql 
  5.  
  6. chown -R mysql.mysql .  #将当前目录中的所有文件属主属组改为mysql别少了最后的'.'哦 
初始化mysql:
  1. scripts/mysql_install_db --user=mysql --datadir=/data/mydata  #指定路径为/data/mydata 用户为mysql 
  2. chown -R root .  #将其属主再更改为root 
4、为mysql提供配置文件
  1. cp support-files/my-large.cnf /etc/my.cnf 
  2.  
  3. 修改thread_concurrency的值为你的cpu的个数的2倍,不并添加行数据库的路径 
  4. thread_concurrency =2   #我的cpu个数为1 
  5. datadir = /data/mydata 
5、为mysql 提供服务脚本
  1. cd /usr/local/mysql 
  2. cp support-files/mysql.server /etc/rc.d/init.d/mysqld 
  3. chmod +x /etc/rc.d/init.d/mysqld 
将该服务添加至服务列表,并启动
  1. chkconfig --add mysqld 
  2. chkconfig mysqld on 
至此,mysql的简单安装就完成了,可以启动服务测试使用了。
 
为了使mysql更加规范化,并将其组件导出给系统使用,还可以添加下面一些步骤哦
 
1、修改mysql的路径和man命令的查找路径
  1. vim /etc/mysql.sh 
  2. PATH=$PATH:/usr/local/mysql/bin 
  3. export PATH 
  4.  
  5. vim /etc/man.config找到MANPATH 添加如下行: 
  6. MANPATH /usr/local/mysql/man 
2、输出mysql头文件至系统头文件路径/usr/include,这里可以通过简单的链接可以实现
  1. ln -sv /usr/loal/mysql/include /usr/include/mysql 
3、输出mysql库文件的路径:
  1. vim /etc/ld.so.conf.d/mysql.conf 
  2. /usr/local/mysql/lib 
添加完成后,让系统重新载入系统库
  1. ldconfig 
之后系统便可以使用mysql命令直接进入数据库进行管理了,与数据库操作相关的命令在内部也可以直接使用了。。
 
二、apache的编译安装
 
1、先安装好开发环境,这里需要三个包组,"Development Libraries" "Development Tools"  "X Software Development"
另外httpd的安装还要依赖于pcre-devel的软件包,这四项可以通过yum直接安装,这里不做演示。
 
2、我们要安装的是httpd-2.4.3的版本,apache的安装还需要更新的apr和apr-util 两个软件包,系统自带的apr和apr-util版本较老,我们这里需要手动去升级,升级的方式有2种,一种是直接升级rpm包,还有一种可以通过源码来进行编译,我们这里使用源码编译进行安装。下载地址是:ftp://172.16.0.1/pub/Sources/new_lamp。
 
1),编译安装apr
将两个软件包下载至本地,
  1. tar xf apr-1.4.6.tar.bz2 
  2. cd apr-1.4.6 
  3. ./congfigure --prefix=/usr/local/apr  #指定安装路径 
  4. make && make install 
2),编译安装apr-util
 
  1. tar xf apr-uitl-1.4.1.tar.bz2 
  2. cd apr-util-1.4.1 
  3. ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr  #apr-util的安装依赖于apr,所以为其指定apr的路径 
  4. make && make install 
3、编译安装httpd-2.4.3
配置好httpd所需要的环境,接下来就可以对httpd进行安装了,首先下载httpd-2.4.3到本地,路径为:ftp://172.16.0.1/pub/Sources/new_lamp。
  1. tar xf httpd-2.4.3.tar.bz2 
  2. cd httpd-2.4.3 
  3. ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-mpms-shared=all --with-mpm=prefork 
这里解释下各选项代表的意义:
 
 --prefix=/usr/local/apache #指定httpd的安装路径
 --sysconfdir=/etc/httpd #指定安装后配置文件的路径
 --enable-so #这项是关键:支持动态模块装卸载,如果不写的话,php没办法以模块的方式编译成apache的模块了
 --enable-ssl #支持https
 --enable-cgi #支持cgi动态执行   
 --enable-rewrite #支持url重写
 --with-zlib #支持使用zlib库将数据发送到客户端之前进行压缩
 --with-pcre #和依赖的pcre软件包相关
 --with-apr=/usr/local/apr #依赖于apr告知apr的安装路径
 --with-apr-util=/usr/local/apr-util #依赖于apr-util,告知其安装路径
 --enable-mpms-shared=all  #构建MPM为动态模块,将所有的模块都设为动态共享,可以在系统运行时加载
 --with-mpm=prefork #指定安装的模块式prefork,如果安装后想要更改,可以再编辑LoadModule指令内容选择不同的模块。
 
  1. make  &&   make install 
4、设置httpd的主配置文件
 
  1. vim  /etc/httpd/httpd.conf 
  2. PidFile "/var/run/httpd.pid"    #指定Pid文件的路径 
5、安装好的httpd支持一个指令:apachectl可以启动httpd服务
可以修改PATH 的环境变量,让系统支持apachectl的相关操作。
  1. vim /etc/profile.d/apachectl 
  2. PATH=$PATH:/usr/local/apache/bin 
  3. export PATH 
运用apachectl start 就可以启动服务了。
(为httpd提供服务脚本后,这项可以不用设置的,我们可以通过httpd相关指令可以直接控制服务的开启与关闭)
 
6、为httpd提供服务脚本。(这里要确定httpd服务是关闭状态)
 
  1. vim /etc/rc.d/init.d/httpd 
  2.  
  3. #!/bin/bash 
  4. # httpd        Startup script for the Apache HTTP Server 
  5. # chkconfig: - 85 15 
  6. # description: Apache is a World Wide Web server.  It is used to serve \ 
  7. #          HTML files and CGI. 
  8. # processname: httpd 
  9. # config: /etc/httpd/conf/httpd.conf 
  10. # config: /etc/sysconfig/httpd 
  11. # pidfile: /var/run/httpd.pid 
  12.  
  13. # Source function library. 
  14. . /etc/rc.d/init.d/functions 
  15.  
  16. if [ -f /etc/sysconfig/httpd ]; then 
  17.         . /etc/sysconfig/httpd 
  18. fi 
  19.  
  20. # Start httpd in the C locale by default. 
  21. HTTPD_LANG=${HTTPD_LANG-"C"} 
  22.  
  23. # This will prevent initlog from swallowing up a pass-phrase prompt if 
  24. # mod_ssl needs a pass-phrase from the user. 
  25. INITLOG_ARGS="" 
  26.  
  27. # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server 
  28. # with the thread-based "worker" MPM; BE WARNED that some modules may not 
  29. # work correctly with a thread-based MPM; notably PHP will refuse to start. 
  30.  
  31. # Path to the apachectl script, server binary, and short-form for messages. 
  32. apachectl=/usr/local/apache/bin/apachectl 
  33. httpd=${HTTPD-/usr/local/apache/bin/httpd} 
  34. prog=httpd 
  35. pidfile=${PIDFILE-/var/run/httpd.pid} 
  36. lockfile=${LOCKFILE-/var/lock/subsys/httpd} 
  37. RETVAL=0 
  38.  
  39. start() { 
  40.         echo -n $"Starting $prog: " 
  41.         LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS 
  42.         RETVAL=$? 
  43.         echo 
  44.         [ $RETVAL = 0 ] && touch ${lockfile} 
  45.         return $RETVAL 
  46.  
  47. stop() { 
  48.     echo -n $"Stopping $prog: " 
  49.     killproc -p ${pidfile} -d 10 $httpd 
  50.     RETVAL=$? 
  51.     echo 
  52.     [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} 
  53. reload() { 
  54.     echo -n $"Reloading $prog: " 
  55.     if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then 
  56.         RETVAL=$? 
  57.         echo $"not reloading due to configuration syntax error" 
  58.         failure $"not reloading $httpd due to configuration syntax error" 
  59.     else 
  60.         killproc -p ${pidfile} $httpd -HUP 
  61.         RETVAL=$? 
  62.     fi 
  63.     echo 
  64.  
  65. # See how we were called. 
  66. case "$1" in 
  67.   start) 
  68.     start 
  69.     ;; 
  70.   stop) 
  71.     stop 
  72.     ;; 
  73.   status) 
  74.         status -p ${pidfile} $httpd 
  75.     RETVAL=$? 
  76.     ;; 
  77.   restart) 
  78.     stop 
  79.     start 
  80.     ;; 
  81.   condrestart) 
  82.     if [ -f ${pidfile} ] ; then 
  83.         stop 
  84.         start 
  85.     fi 
  86.     ;; 
  87.   reload) 
  88.         reload 
  89.     ;; 
  90.   graceful|help|configtest|fullstatus) 
  91.     $apachectl $@ 
  92.     RETVAL=$? 
  93.     ;; 
  94.   *) 
  95.     echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}" 
  96.     exit 1 
  97. esac 
  98.  
  99. exit $RETVAL 
这里可以自己根据原有httpd2.2 的版本样例来进行修改
 
而后为脚本赋予权限:
  1. chmod +x /etc/rc.d/init.d/httpd 
将该服务添加至服务列表:
  1. chkconfig --add httpd 
接下来就可以通过httpd来进行服务的测试了。
 
三、编译安装php-5.4.8
 
1、安装php-5.4.8依赖于libmcrypt-2.5.7-5.el5.i386.rpm
libmcrypt-devel-2.5.7-5.el5.i386.rpm 两个rpm包,可以让php支持mcrypt加密解密扩展库,下载地址:ftp://172.16.0.1/pub/Sources/ngnix目录中,另外开发环境已经在安装httpd的时候安装过了,这里不多做详解。
 
2、安装:
先安装两个rpm包:
  1. rpm -ivh libmcrypt-2.5.7-5.el5.i386.rpm 
  2. rpm -ivh libmcrypt-devel-2.5.7-5.el5.i386.rpm  
编译安装php,将源码包下载至本地,下载地址:ftp://172.16.0.1/pub/Sources/new_lamp。
 
  1. tar xf php-5.4.8.tar.bz2 
  2. cd php-5.4.8 
  3. ./configure --prefix=/usr/local/php --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  --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt  --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2  --enable-maintainer-zts 
各选项的意义:
--prefix=/usr/local/php #指定安装路径
--with-mysql=/usr/local/mysql #指定mysql的安装路径
--with-openssl #支持加密功能
--with-mysqli=/usr/local/mysql/bin/mysql_config #指定mysql的接口
--enable-mbstring #支持多字节的字符
--with-freetype-dir #支持多种字体文件库
--with-jpeg-dir #支持jpeg图片格式
--with-png-dir #支持pnf图片格式
--with-zlib #支持使用zlib库将数据发送到客户端之前进行压缩
--with-libxml-dir=/usr
#指定扩展标记语言库文件路径
--enable-xml         #支持扩展标记语言
--enable-sockets #php可以基于sockets进行通信
--with-apxs2=/usr/local/apache/bin/apxs #指将php安装成apache的动态模块 
--with-mcypt #支持加密解密功能
-with-config-file-path=/etc #指定配置文件的路径,主配置文件php.ini放在这里)
--with-config-file-scan-dir=/etc/php.d #指定主配置文件的从配置文件路径,这里放置一些以.ini 结尾的文件
--with-bz2 #支持bz2的压缩格式
 
 
  1. make 
  2. make test   #进行安装测试 (建议在生成环境中使用)
  3. make install 
3、提供配置文件
在当前目录下:
 
  1. cp php.ini-production  /etc/php.ini     #我们是生产环境中使用,所以拷贝production的配置文件即可 
4、编辑apache的配置文件httpd.conf 以使apache支持php
 
  1. vim /etc/httpd/httpd.conf 
  2. 1),在末尾处添加如下2行:指定所能够识别php的类型 
  3. AddType application/x-httpd-php  .php 
  4. AddType application/x-httpd-php-source  .phps 
  5.  
  6. 2),定位至DirectoryIndex index.html 
  7. 修改: 
  8. DirectoryIndex index.php index.html 
之后重新启动httpd,或者让它重新载入配置文件就可以测试是否已经可以正常使用了。
尝试配置页面,httpd安装的默认网页在/usr/local/apache/htdos下
 
  1. cd /usr/local/apache/htdocs 
  2. mv index.html index.php 
  3. vim index.php  
  4. 添加: 
  5. <?php 
  6. phpinfo(); 
  7. ?> 
重新启动httpd服务器,再次访问172.16.9.2就会出现以下页面了。

LAMP:apache+mysql+php的编译安装_mysql

至此,LAMP各组件已经全部安装完成!!
 
 
 
补充(编译安装httpd选项):

(1)构建MPM为静态模块
在全部平台中,MPM都可以构建为静态模块。
在构建时选择一种MPM,链接到服务器中。
如果要改变MPM,必须重新构建。为了使用指定的MPM,请在执行configure脚本 时,使用参数 --with-mpm=NAME。
NAME是指定的MPM名称。编译完成后,可以使用 ./httpd -l 来确定选择的MPM。
 此命令会列出编译到服务器程序中的所有模块,包括 MPM。

(2)构建 MPM 为动态模块
在Unix或类似平台中,MPM可以构建为动态模块,与其它动态模块一样在运行时加载。
 构建 MPM 为动态模块允许通过修改LoadModule指令内容来改变MPM,而不用重新构建服务器程序。
 在执行configure脚本时,使用--enable-mpms-shared选项即可启用此特性。
 当给出的参数为all时,所有此平台支持的MPM模块都会被安装。还可以在参数中给出模块列表。
 默认MPM,可以自动选择或者在执行configure脚本时通过--with-mpm选项来指定,然后出现在生成的服务器配置文件中。
 编辑LoadModule指令内容可以选择不同的MPM。
 
 
四、扩展:在httpd中设置虚拟主机,安装xcache以及创建论坛
1,httpd虚拟主机配置:
首先注释掉中心主机
 
  1. vim /etc/httpd/httpd.conf 
  2. #DocumentRoot "/usr/local/apache/htdocs"  在前面加'#'将其注释掉 
  3.  
  4. Include /etc/httpd/extra/httpd-vhosts.conf      #将虚拟主机这项启用起来 
编辑虚拟主机配置文件
  1. <VirtualHost *:80> 
  2.     DocumentRoot "/web/test" 
  3.     ServerName www.test.com 
  4.         <Directory "/web/test"> 
  5.         AllowOverride none 
  6.         Options none 
  7.         Require all granted 
  8.         </Directory> 
  9. </VirtualHost> 
在/web/test下编辑一个html文档,重启服务,即可进行访问。

LAMP:apache+mysql+php的编译安装_Linux_02

2、安装xcache:为php加速的一个工具
1),安装xcache:下载地址ftp:// 172.16.0.1/pub/Sources/new_lamp.
 
  1. tar xf xcache-2.0.0.tar.gz 
  2. cd xcache-2.0.0 
  3. /usr/local/php/bin/phpize       #生成php扩展模块 
  4. ./configure --enable-xchahe --with-php-config=/usr/local/php-config  #为其指定php的配置文件路径 
  5. make && make install 
 
2)、编辑php主配置文件php.ini
整合php和xcache
将xcache提供的配置文件按导入php.ini
 
  1. mkdir /etc/php.d 
  2. cp xcache.ini  /etc/php.d       #xcache.ini 在当前目录下 
编辑xcache.ini,找到zend_extension开头的行进行修改
 
  1. vim /etc/php.d/xcache.ini 
  2. zend_extension =/usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so 
注:如果php.ini文件中有多条zend_extension指令行,要确保此新增的行排在第一位。
如下,在访问页面中就可以看到新增xcache.ini所在路径了
 
 

LAMP:apache+mysql+php的编译安装_release_03

3、论坛的创建
下载Discuz_7.2_FULL_SC_GBK.zip,下载地址:ftp://172.16.0.1/pub/Sources/LAMP
 
  1. touch tmp       #将解压缩后的文件放在该文件中 
  2. unzip Discuz_7.2_FULL_SC_GBK.zip > tmp 
在当前目录下生成一个目录upload,切换到该目录
 
  1. cd upload 
  2. mv * /web/test  #将该目录下的文件全部移到/web/test下
访问该网页之前编辑php配置文件,以便安装论坛时出错。
 
  1. vim /etc/php.ini 
  2. short_open_tag = On     #这一项默认为off,将其启动 
访问www.test.com/install #第一次进入安装论坛页面要加上install
会出现以下页面

LAMP:apache+mysql+php的编译安装_mysql_04

按照安装步骤进行安装:
 

LAMP:apache+mysql+php的编译安装_release_05

文件权限出现错误,根据提示改变其权限,如下:
(这一步是赋予启动httpd进程的用户以所有权限,这里的用户deamon是根据httpd的配置文件中的User的定义来决定的,你的可能会不一样哦)
 
  1. [root@www ~]# cd /web/test 
  2. [root@www test]# setfacl -m u:daemon:rw- config.inc.php  
  3. [root@www test]# setfacl -m u:daemon:rwx p_w_uploads/ 
  4. [root@www test]# setfacl -m u:daemon:rwx forumdata/ 
  5. [root@www test]# setfacl -m u:daemon:rwx forumdata/cache/ 
  6. [root@www test]# setfacl -m u:daemon:rwx forumdata/templates/ 
  7. [root@www test]# setfacl -m u:daemon:rwx forumdata/threadcaches/ 
  8. [root@www test]# setfacl -m u:daemon:rwx forumdata/logs/ 
  9. [root@www test]# setfacl -m u:daemon:rwx uc_client/data/cache/ 
刷新该页面;
 

LAMP:apache+mysql+php的编译安装_release_06

进入下一步:
 

LAMP:apache+mysql+php的编译安装_Linux_07

这里填写的数据库和用户名最好是存在的,密码最好在创建数据库中指定用户时设定好(这里不多做详解,有关mysql可以参考前面的文章^_^)
 

LAMP:apache+mysql+php的编译安装_安装_08

 
一个简易的论坛就创建完成了,你可以在里面进行操作了!!!