Skip to content

Apache 2.4.x 安装

Xiaoshi Xu edited this page Jan 12, 2018 · 5 revisions

安装步骤

# 下载需要的扩展包
wget http://mirror.esocc.com/apache/httpd/httpd-2.4.6.tar.gz  
wget http://apache.fayea.com/apache-mirror/apr/apr-1.4.8.tar.gz  
wget http://apache.fayea.com/apache-mirror/apr/apr-util-1.5.2.tar.gz  
wget http://apache.fayea.com/apache-mirror/apr/apr-iconv-1.2.1.tar.gz  

tar xzf httpd-2.4.6.tar.gz  
tar xzf apr-1.4.8.tar.gz  
tar xzf apr-util-1.5.2.tar.gz  
tar xzf apr-iconv-1.2.1.tar.gz  

mv apr-1.4.8 httpd-2.4.6/srclib/apr  
mv apr-util-1.5.2 httpd-2.4.6/srclib/apr-util  
mv apr-iconv-1.2.1 httpd-2.4.6/srclib/apr-iconv  

# 如果www已经存在可以跳过一下两行
/usr/sbin/groupadd www  
/usr/sbin/useradd -r -g www www  

cd httpd-2.4.6  
./configure --prefix=/usr/local/apache-2.4.6 --enable-so --enable-deflate=shared --enable-ssl=shared --enable-expires=shared --enable-headers=shared --enable-rewrite=shared --enable-static-support --with-included-apr --with-mpm=prefork --enable-cache --enable-file-cache --enable-modules --enable-proxy --enable-proxy-ajp --enable-proxy-connect --enable-proxy-http --with-pcre=/usr/local/pcre --localstatedir=/etc/apache
make  
make install  

ln -s /usr/local/apache-2.4.6 /usr/local/apache  

mkdir -p /var/log/apache  

# 虚拟主机配置文件源目录,每个域名一个文件  
mkdir -p /etc/apache/sites-available  
touch /etc/apache/sites-available/test-eefocus-com.conf  

# 当前启用虚拟主机配置文件目录,只包含来自site-available的软连接  
mkdir -p /etc/apache/sites-enabled  
ln -s /etc/apache/sites-available/test-eefocus-com.conf /etc/apache/sites-enabled/test-eefocus-com.conf 

配置

httpd.conf模板

# /usr/local/apache-2.4.6/conf/httpd.conf  
# 默认httpd用户和组  
User www  
Group www  
  
# 站点管理员邮箱  
ServerAdmin monitor@eefocus.com  

# 默认站点名  
ServerName test.eefocus.com  

# 默认启用的虚拟主机配置文件  
Include conf/extra/httpd-mpm.conf  
Include /etc/apache/sites-enabled/*.conf  

## 在安装libphp5后 ##  

# 加载php5模块,通常已经自动加上了  
LoadModule php5_module        modules/libphp5.so  

# 默认index文件  
DirectoryIndex index.html index.php  

# 增加Mime Type  
AddType application/x-httpd-php .php .phtml .php3 .php4 .php5 .php6  
AddType application/x-httpd-php-source .phps  

/etc/apache/sites-enabled/test-eefocus-com.conf  
<VirtualHost *:80>  
    DocumentRoot "/srv/test.eefocus.com"  
    ServerName test.eefocus.com  
    <Directory "/srv/test.eefocus.com">  
        Options -Indexes  
        Options +FollowSymLinks  
        AllowOverride All  
        Require all granted  
    </Directory>  
    ErrorLog "/var/log/apache/test.eefocus.com/error.log"  
    CustomLog "/var/log/apache/test.eefocus.com/access.log" common  
</VirtualHost>  
/usr/local/apache-2.4.6/conf/extra/httpd-mpm.conf  
<IfModule mpm_prefork_module>  
    ServerLimit          10000  
    StartServers             5  
    MinSpareServers          5  
    MaxSpareServers         10    
    MaxRequestWorkers    10000    
    MaxConnectionsPerChild   10000    
</IfModule>   

编译安装特定模块  

# 进入源代码目录  
cd modules/metadata/  

# 编译安装mod_usertrack  
/usr/local/apache-2.4.6/bin/apxs -iac mod_usertrack.c  
#自启动  

cp /usr/local/apache/bin/apachectl /etc/init.d/httpd  
vi /etc/init.d/httpd  

# 添加下面两行  
# chkconfig: 345 90 90  
# description: Apache  

chkconfig --add /etc/init.d/httpd  
service httpd start 

注意事项

  1. 方便起见, 可以使用 yum 安装,然后根据需要安装扩展。
Clone this wiki locally