CentOS 5.3搭建Apache2.2.4+Mysql5.1.4+PHP5.3服务器
留着,仅供自己下次安装用。都是在网上找的方法,只是给组合了下。
(温馨提示:如果你复制的安装过程,可能有类似这样的错误:
configure: warning: /usr/local/php:: invalid host type
…
configure: error: can only configure for one host and one target at a time
我写的是–with-前面是两个-,但是wp经过了处理变成一个-了,所以你在记事本里面把-替换成两个-就行了
)
1、使用 yum 程序安装所需开发包(以下为标准的 RPM 包名称)
# yum install gcc gcc-c++ gcc-g77 flex bison autoconf automake bzip2-devel zlib-devel ncurses-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel pam-devel
# 这里我们将编译GD所必须的一些小软件比如libpng,libtiff,freetype,libjpeg等先用RPM的方式一并安装好,避免手动编译浪费时间,同时也能避免很多错误,这几个小软件的编译很麻烦。这几个小软件编译错误了,GD当然安装不了,php5的编译当然也没戏了。所以我们抓大放小,对这些小牛鬼蛇神采取快速简洁的方式进行安装。并且对服务器的性能也不能产生什么影响。
2、源码编译安装所需包 (Source)
(1) GD2
# cd /usr/local/src
# wget http://www.boutell.com/gd/http/gd-2.0.33.tar.gz
# tar xzvf gd-2.0.33.tar.gz
# cd gd-2.0.33
# ./configure –prefix=/usr/local/gd2 –mandir=/usr/share/man //./configure 配置。
# make //make 是用来编译的,它从 Makefile 中读取指令,然后编译。
# make install //make install 是用来安装的,它也从 Makefile 中读取指令,安装到指定的位置。
(2) Apache 日志截断程序
# cd /usr/local/src
# wget http://cronolog.org/download/cronolog-1.6.2.tar.gz
# tar xzvf cronolog-1.6.2.tar.gz
# cd cronolog-1.6.2
# ./configure –prefix=/usr/local/cronolog
# make
# make install
(3) libxml 库程序
# cd /usr/local/src
# wget http://ftp.gnome.org/pub/gnome/sources/libxml2/2.6/libxml2-2.6.26.tar.gz
# tar zxvf libxml2-2.6.26.tar.gz
# cd libxml2-2.6.26
# ./configure –prefix=/usr/local/libxml2
# make
# make install
接下来进入正题,建议安装顺序Mysql,Apache,PHP
3、本来想尝试用编译源码的方法安装Mysql,可是官主的5.1.4没有,就下载了5.1.3的,可是尝试装到非默认路径怎么都是出错,没办法就用了5.1.4的按照解压包里的INSTALL的提示,一步步安装到了/usr/local/mysql,挺简单。
# useradd mysql //添加 mysql 用户
# cd /usr/local/mysql
# ./bin/mysql_install_db –user=mysql
# chown -R root:mysql . //设置权限,注意后面有一个 “.”
# chown -R mysql /var/lib/mysql //设置 mysql 目录权限
# chgrp -R mysql . //注意后面有一个 “.”
# cp share/mysql/my-medium.cnf /etc/my.cnf
# cp share/mysql/mysql.server /etc/rc.d/init.d/mysqld //开机自动启动 mysql。
# chmod 755 /etc/rc.d/init.d/mysqld
# chkconfig –add mysqld
4、编译安装 Apache2.24
这个最简单了,基本不会有错误发生。
# tar zxvf httpd-2.2.4.tar.gz
# cd httpd-2.2.4
依次安装apr和apr-util(这两个文件夹在httpd-2.2.4/srclib/里面,如下操作)
# cd srclib/apr
# ./configure –prefix=/usr/local/apr –enable-threads –enable-other-child USE=ipv6
# make && make install
# cd ../apr-util
# ./configure –prefix=/usr/local/apr-util –with-apr=/usr/local/apr/ –with-mysql=/usr/local/mysql
# make && make install
yum install openssl-devel.x86_64
cd /usr/local/src/httpd-2.2.4
./configure –prefix=/usr/local/apache2 –enable-mods-shared=all –enable-deflate=shared –with-mysql=/usr/local/mysql –enable-cache –enable-file-cache –enable-mem-cache –enable-disk-cache –enable-static-support –enable-static-htpasswd –enable-static-htdigest –enable-static-rotatelogs –enable-static-logresolve –enable-static-htdbm –enable-static-ab –enable-static-checkgid –disable-cgid –disable-cgi –with-mpm=worker –with-apr=/usr/local/apr/ –with-apr-util=/usr/local/apr-util/ –enable-ssl –with-ssl=/usr/include/openssl
# make
# make install
# echo ‘/usr/local/apache2/bin/apachectl start ‘ >> /etc/rc.local //将 apachectl 的调用加入到你的系统启动文件中。
注解:
./configure //配置源代码树
–prefix=/usr/local/apache2 //体系无关文件的顶级安装目录PREFIX ,也就Apache的安装目录。
–enable-module=so //打开 so 模块,so 模块是用来提 DSO 支持的 apache 核心模块
–enable-mods-shared=all //编译全部的模板,对于不需要我们可以在httpd.conf去掉。
–enable-cache //支持缓存
–enable-file-cache //支持文件缓存
–enable-mem-cache //支持记忆缓存
–enable-disk-cache //支持磁盘缓存
–enable-static-support //支持静态连接(默认为动态连接)
–enable-static-htpasswd //使用静态连接编译 htpasswd – 管理用于基本认证的用户文件
–enable-static-htdigest //使用静态连接编译 htdigest – 管理用于摘要认证的用户文件
–enable-static-rotatelogs //使用静态连接编译 rotatelogs – 滚动 Apache 日志的管道日志程序
–enable-static-logresolve //使用静态连接编译 logresolve – 解析 Apache 日志中的IP地址为主机名
–enable-static-htdbm //使用静态连接编译 htdbm – 操作 DBM 密码数据库
–enable-static-ab //使用静态连接编译 ab – Apache HTTP 服务器性能测试工具
–enable-static-checkgid //使用静态连接编译 checkgid
–disable-cgid //禁止用一个外部 CGI 守护进程执行CGI脚本
–disable-cgi //禁止编译 CGI 版本的 PHP
–with-mpm=worker // 让apache以worker方式运行
–enable-ssl // 编译 ssl模块。
将apache设置成开机自启动:
在/etc/rc.d/rc.local文件中加入一行
/usr/local/apache2/bin/apachectl start
这样每次重新启动系统以后,apache也会随系统一起启动.
或者
# cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd
然后 vi /etc/rc.d/init.d/httpd 添加(#!/bin/sh下面)
# chkconfig: 2345 10 90
# description: Activates/Deactivates Apache Web Server
最后,运行chkconfig把Apache添加到系统的启动服务组里面:
# chkconfig –add httpd
# chkconfig httpd on
5、编译安装php5.3
下载curl 安装到/usr/loca/curl
./configure –prefix=/usr/local/php –with-apxs2=/usr/local/apache2/bin/apxs –with-zlib-dir –with-bz2 –with-tiff-dir –with-libxml-dir=/usr/local/libxml2 –with-gd=/usr/local/gd2 –with-freetype-dir –with-jpeg-dir –with-png-dir –with-ttf –enable-mbstring –with-mysql=/usr/local/mysql –with-mysqli=/usr/local/mysql/bin/mysql_config –with-config-file-path=/etc –with-iconv –disable-ipv6 –enable-static –enable-maintainer-zts –enable-memory-limit –enable-zend-multibyte –enable-inline-optimization –enable-sockets –enable-soap –with-openssl –with-curl=/usr/local/curl
# make
# make install
# cp php.ini-recommended /etc/php.ini
6、整合apache 与php
# vi /usr/local/apache2/conf/httpd.conf
在最后一行加上:
AddType application/x-httpd-php .php
查找:(设置 WEB 默认文件)
DirectoryIndex index.html
替换为:
DirectoryIndex index.php index.html index.htm //在 WEB 目录不到默认文件,httpd 就会执行 /var/www/error/noindex.html
找到这一段:
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be “All”, “None”, or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride none
更改为AllowOverride all
允许apache rewrite
# 监听443端口,支持https连接
取消注释 httpd.conf 中的 Include conf/extra/httpd-ssl.conf
保存httpd.conf,退出。
# /usr/local/apache2/bin/apachectl restart //重启 Apache
以上就完成了,因为我用到的东西比较简单,所以这是最基本的安装了。









