Apache篇:
1、解决依赖关系
httpd-2.4.3需要较新版本的apr和apr-util(一个跨平台接口,使得httpd便于移植,具体参见各种百科),因此需要事先对其进行升级。升级方式有两种,一种是通过源代码编译安装,一种是直接升级rpm包。这里选择使用编译源代码的方式进行.
(1)下载并编译安装apr
- cd /root/work
- wget http://labs.mop.com/apache-mirror/apr/apr-1.4.6.tar.bz2
- tar -jvxf apr-1.4.6.tar.bz2
- cd apr-1.4.6 #因为apr-util依赖其,所以,此包需先安装
- ./configure --prefix=/usr/local/apr #安装目录,后面需要用
- make && make install #你懂的..
(2)下载并编译安装apr-util
- wget http://labs.mop.com/apache-mirror/apr/apr-util-1.5.1.tar.bz2
- tar -jvxf apr-util-1.5.1.tar.bz2
- cd apr-util-1.5.1
- ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr #指定安装目录和之前安装的apr
- make && make install
(3) httpd-2.4.2编译过程也要依赖于pcre-devel软件包,需要事先安装。
- yum install pcre-devel -y #此包是perl兼容正则表达式库的开发环境.
2、下载并编译安装httpd-2.4.3.tar.bz2
- wget http://labs.mop.com/apache-mirror/httpd/httpd-2.4.3.tar.bz2
- tar -jzxf httpd-2.4.3.tar.bz2
- cd httpd-2.4.3
- ./configure --prefix=/usr/local/apache \安装目录
- --sysconfdir=/etc/httpd \配置文件目录
- --enable-so \开启动态加载模块功能
- --enable-ssl \开启SSL加密传输模块支持
- --enable-cgi \开启cgi通用网关接口
- --enable-rewrite \开启URL地址
- --with-zlib \使用压缩传输
- --with-pcre \使用基于perl的正则表达式库优化速度
- --with-apr=/usr/local/apr \开启apr,刚才编译时的安装路径
- --with-apr-util=/usr/local/apr-util \同上
- --enable-mpms-shared=all \编译所有的mpm模块
- --with-mpm=event \编译默认使用event工作模型-->回车
- make -j8 && make install #-j为并行编译,数字等于CPU个数的2倍,笔者为了更快,给虚拟机环境分了4个CPU...慎用.
3、配置系统路径变量,使其支持httpd安装的命令,重启控制台生效
- echo 'export PATH=$PATH:/usr/local/apache/bin' > /etc/profile.d/httpd.sh
4、修改httpd的默认pid文件位置
- sed -i '/^ServerRoot[[:space:]]..usr.local.apache.$/aPidFile "/var/run/httpd.pid"' /etc/httpd/httpd.conf
5、为其提供SysV脚本,笔者这里直接在其它系统(rhel5.8)中,拿到一起rpm包安装的httpd的httpd脚本,进行简单的修改即可.操作如下:
- scp 172.16.35.2:/etc/init.d/httpd /etc/init.d/ #172.16.35.2是笔者的另一个虚拟机.将其httpd文件复制到本地相同位置
- sed -i 's@/usr/sbin@/usr/local/apache/bin@g' /etc/init.d/httpd #替换掉原脚本的命令调用路径
- sed -i 's@etc/httpd/conf@etc/httpd@g' /etc/init.d/httpd #替换掉原脚本的配置文件路径
- chmod 755 /etc/init.d/httpd #给予其执行权限
- chkconfig --add httpd #添加到系统service脚本调用
- chkconfig httpd on #开机自动启动,看自身需求
- service httpd start
6、简单测试默认页,返回works则表示服务已经正常工作.
- elinks -dump 127.0.0.1
PHP篇:
Ps: 开始之前,请确认MySQL篇中的yum -y groupinstall "X Software Development"和libmcrypt-2.5.7-1.2.el5.rf.i386.rpm以及libmcrypt-devel-2.5.7-1.2.el5.rf.i386.rpm安装成功.
1、下载并编译安装php
- cd /root/work
- wget http://cn2.php.net/distributions/php-5.4.8.tar.bz2
- tar -jvxf php-5.4.8.tar.bz2
- cd php-5.4.8
- ./configure --prefix=/usr/local/php \介个是安装目录
- --with-mysql=/usr/local/mysql \支持mysql
- --with-openssl \openssl的支持,一般用于https
- --with-mysqli=/usr/local/mysql/bin/mysql_config \支持优化的mysqli
- --enable-mbstring \打开对多字节,字符串的支持
- --with-freetype-dir \打开对freetype字体库的支持
- --with-jpeg-dir \打开对jpeg图片的支持
- --with-png-dir \打开对png图片的支持
- --with-zlib \ 支持数据压缩函数库
- --with-libxml-dir=/usr \ 打开libxml函数库的支持
- --enable-xml \打开对xml网页的支持
- --enable-sockets \打开套接字支持
- --with-apxs2=/usr/local/apache/bin/apxs \以模块的方式安装到apache
- --with-mcrypt \支持mcrypt加密算法的扩展
- --with-config-file-path=/etc \配置文件php.ini的路径
- --with-config-file-scan-dir=/etc/php.d \次级扫描配置文件路径
- --with-bz2 \支持对bz2文件的支持
- --enable-maintainer-zts \激活php的线程安全机制(若httpd基于worker和event模型,则此项必须要开启) --->终于可以回车了亲...
- make -j8 && make install #这就不废话了.
2、为php提供配置文件
- cp /root/work/php-5.4.8/php.ini-production /etc/php.ini
3、使httpd支持php
- echo -e 'AddType application/x-httpd-php .php\nAddType application/x-httpd-php-source .phps' >> /etc/httpd/httpd.conf #把php文本类型追加进httpd.conf
- sed -i 's/\([[:space:]]DirectoryIndex.index\.\).*l$/\1php index.html/g' /etc/httpd/httpd.conf #添加文件默认首选网页为index.php
4、制作简单测试页,检查是php安装否成功
- mv -v /usr/local/apache/htdocs/{index.html,index.php}
- echo -e '<?php\nphpinfo();\n?>' >/usr/local/apache/htdocs/index.php
- service httpd restart
- elinks -dump 127.0.0.1/index.php|tail -20|head -5
Ps: 修改httpd默认主页类型,将phpinfo代码覆盖进去,重启服务,若失败,检查selinux,笔者两次都是忘了关闭selinux而没有首次启动成功,若正常,返回的字段中应包含:PHP License
