一、服务器环境
[root@linuxidc ~]# cat /etc/RedHat-release
Red Hat Enterprise Linux Server release 5.8 (Tikanga)
[root@linuxidc ~]# uname -a
Linux linuxidc 2.6.18-308.el5 #1 SMP Fri Jan 27 17:21:15 EST 2012 i686 i686 i386 GNU/Linux
二、基础环境安装
yum install gcc gcc-c++ bison autoconf automake zlib-devel ncurses-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel pam-devel openssl-devel libxml2-devel
三、APACHE安装
1、下载并解压
wget
tar xzvf httpd-2.2.26.tar.gz
cd httpd-2.2.26
2、编译安装
./configure \
-prefix=/data/apache \
-enable-module=so \
-enable-deflate=shared \
-enable-rewrite=shared \
-enable-cache \
-enable-file-cache \
-with-mpm=worker \
-enable-threads \
Make && make install
相对来说,prefork方式速度要稍高于worker,然而它需要的cpu和memory资源也稍多于woker。
3、启动apache服务
./apachectl start
启动报错:httpd: Could not reliably determine the server's fully qualified domain name,
using 127.0.0.1 for ServerName
4、修改配置文件
vi httpd.conf
#ServerName :80
ServerName localhost:80
5、重新启动apache服务
[root@hrd bin]# ./apachectl start
[root@hrd bin]# ps -ef|grep httpd
root 5189 1 0 16:04 ? 00:00:00 /data/apache/bin/httpd -k start
daemon 5190 5189 0 16:04 ? 00:00:00 /data/apache/bin/httpd -k start
daemon 5191 5189 0 16:04 ? 00:00:00 /data/apache/bin/httpd -k start
daemon 5193 5189 0 16:04 ? 00:00:00 /data/apache/bin/httpd -k start
daemon 5195 5189 0 16:04 ? 00:00:00 /data/apache/bin/httpd -k start
root 5276 14464 0 16:04 pts/1 00:00:00 grep httpd
如上表示启动成功。
6、配置虚拟站点
a.开启虚拟站点功能。取消Incldue前的注释#
[root@hrd conf]# grep vhost httpd.conf
Include conf/extra/httpd-vhosts.conf
b.配置虚拟站点配置文件
cd /data/apache/conf/extra
<VirtualHost *:80> 端口为80
ServerAdmin webmaster@dummy-host.example.com 管理员邮箱
DocumentRoot "/home/www/wwwroot" 站点目录
ServerName linuxidc.com 站点域名
ServerAlias 站点别名
ErrorLog "logs/linuxidc-error_log" 站点错误日志
CustomLog "logs/linuxidc-access_log" common 站点日志
</VirtualHost>
C.创建网站目录和首页文件
Mkdir www
Echo www >index.html
7、重启apache服务,并检查授权文件
[root@hrd bin]# ./apachectl graceful
[root@hrd bin]# vi httpd.conf
<Directory /home/www/wwwroot> 网站目录
Options FollowSymLinks
AllowOverride None 浏览目录
Order allow,deny 允许访问
Allow from all
</Directory>
8、域名访问显示正常
四、apache优化
1、启用网站缓存功能
如果已经编译完成,没有编译mod_expires参数,手工添加
/usr/local/apache/bin/apxs
-i -a -c /usr/local/soft/httpd-2.2.26/modules/metadata/mod_expires.c
chmod 755 /usr/local/apache/modules/mod_expires.so
2、检查是否安装成功
[root@linuxidc conf]# grep mod_expires.so httpd.conf
LoadModule expires_module modules/mod_expires.so
3、添加缓存文件类型到配置文件,缓存时间设置为1年
<IfModule mod_expires.c>
ExpiresActive On 激活缓存功能
ExpiresDefault "access plus 12 month"
ExpiresByType text/html "access plus 12 months" 文本
ExpiresByType text/css "access plus 12 months" 样式
ExpiresByType image/gif "access plus 12 months" 动态
ExpiresByType image/jpeg "access plus 12 months" 图片
ExpiresByType image/jpg "access plus 12 months" 图片
ExpiresByType image/png "access plus 12 months" 图片
EXpiresByType application/x-shockwave-flash "access plus 12 months"
EXpiresByType application/x-Javascript "access plus 12 months"
ExpiresByType video/x-flv "access plus 12 months"
</IfModule>
推荐阅读:
Ubuntu 13.04 安装 LAMP\Vsftpd\Webmin\phpMyAdmin 服务及设置
CentOS 5.9下编译安装LAMP(Apache 2.2.44+MySQL 5.6.10+PHP 5.4.12)
RedHat 5.4下Web服务器架构之源码构建LAMP环境及应用PHPWind
LAMP源码环境搭建WEB服务器Linux+Apache+MySQL+PHP