Apache 安装与配置

 

Linux 版本:CentOS-5.4-i386-bin-DVD.iso 

Apache 版本:httpd-2.4.3.tar.gz 

安装前准备:下载

httpd-2.4.3.tar.gz 、apr-1.4.6.tar.gz 、apr-util-1.4.1.tar.gz 

Apache下载路径:http://httpd.apache.org/

 Apr 下载路径:http://apr.apache.org/

  

 将文件上传至

Linux  /home/ 

目录下(可使用软件F-SecureSSHClient-v5.4.56)

  安装Apache:

 1. 解压httpd-2.4.3.tar.gz   使用命令tar –zvxf httpd-2.4.3.tar.gz ,解压完后会生成一个httpd-2.4.3的目录

   # tar –zvxf httpd-2.4.3.tar.gz 

  # cd httpd-2.4.3   

   # ./configure   

  这里提示一个错误configure: error: APR not found. Please read the documentation.  

 

2. 经网上查阅资料才知道这是Apache的关联软件,需要安装APR软件。 

这里下载apr-1.4.6.tar.gz 解压安装。

 # tar –zvxf apr-1.4.6.tar.gz 

# cd apr-1.4.6 

# ./configure --prefix=/usr/local/apr 

这里说明一下,--prefix表示要将apr安装到哪个目录;如果目录不存在,程序为什么创建;最好加上此参数;我第一次没有加,安装完成后找不到文件了;因为我们在后面的安装中

常需要这个目录;--prefix=绝对路径名 执行完毕后;执行

 

# make   

如果make执行过程中没有 error错误;

执行 # make install 

如果make install命令执行过程中没有出现任何Error;并且创建了相关的目录;我这里是/usr/local/apr目录。那么恭喜你,你的APR安装完成了;

这里如果执行安装httpd服务的话;就不再会报checking for APR... No configure: error: APR could not be located这个错误了;

 

 3. 这里再返回到httpd-2.4.3 目录执行命令:

 /configure --prefix=/usr/local/apache --with-apr=/usr/local/apr 

这时就会报checking for APR-util... no configure: error: APR-util not found. Please read the documentation 

 这就需要下载相关的APR-UTIL的包。

 这里下载的是apr-util-1.4.1.tar.gz 

解压安装 

# tar –zvxf apr-util-1.4.1.tar.gz 

# cd apr-util-1.4.1 

# ./

configure --prefix=/use/local/apr-util --with-apr=/use/local/apr/bin/apr-1-config 

执行./configure 执行这个文件时需要加上刚才安装完成的apr配置文件

如果不加此配置文件会报找不到apr异常。

 # make 

# make install 

如果

make install

能正常执行成功,则会在prefix设置的目录下面有生成相关的配置文件;这时就表示你的apr-util安装成功了

 

4.再次返回到httpd-2.4.3 目录进行安装,执行命令

 # ./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr/bin/apr-1-co

nfig --with-apr-util=/usr/local/apr-util/bin/apu-1-config 

执行过程中没有报错;继续执行

make

命令

 # make 执行完成后执行

make install 

# make install 

httpd服务安装完成

  

补充说明:

 

有些人在安装Apache 

第4步的时候执行

# ./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr/bin/apr-1-co

nfig --with-apr-util=/usr/local/apr-util/bin/apu-1-config 

会出现错误提示:configure: error: pcre-config for libpcre not found. PCRE is required and available  

这里需要下载pcre相关软件上,这里下的pcre版本是 

pcre-8.20.tar.bz2 

 

下面开始安装pcre 

# bzip -d pcre-8.20.tar.bz2 

#tar -xvf -d pcre-8.20.tar 

#./configure --prefix=/use/local/pcre  --with-apr=/usr/local/apr/bin/apr-1-config 

进行pcre-8.20目录进行pcre的安装; 

pcre的安装要需要指定apr如果不指定apr会报找不到apr异常

 # make 

# make install 

 

安装httpd服务之前可能需要安装C++

sudo apt-get install gcc g++

 

安装httpd服务

安装httpd服务需要指定apr apr-util pcre

这三个目录才能正常安装;因此他的安装命令是

 

 ./configure  --prefix=/usr/local/httpd  

--with-apr=/usr/local/apr/bin/apr-1-config  

--with-apr-util=/usr/local/apr-util/bin/apu-1-config  

--with-pcre=/usr/local/pcre/bin/pcre-config 

 

修改Apache 配置文件:

 1默认的web根目录为:htddocs。默认端口为80

必须修改否则跟系统冲突,端口号改为8088 也可以自己设定一下,根据实际情况进行修改该。

 # vi /usr/local/apache/conf/httpd.conf

 

左右方向键找到 listen 80  输入 i 修改 80 为8088 

 

按 esc 然后shift+: 输入wq 保存退出就好了

 

2.测试apache服务器

 

使用此命令是开始了本机的默认的服务

   # /usr/local/apache/bin/apachectl -k start 

进入安装目录 

# cd /usr/local/apache/bin/

# ./apachectl 

k start|stop|restart   

分别为启动

 停止

 重启

 

netstat -ltnp 检查网络端口

 验证刚才我们的端口号是否打开了

 # netstat –ltnp 

这时查看我们的端口号是否打开了

  

结果:8088打开了

 

打开浏览器输入http://IP地址:8088 出现 it works 表示连接已经正常 到此安装完毕

 

 3.配置rc.local文件将Apache的服务加入到开机自动启动

 # echo  '/usr/local/apache2/bin/apachectl -k start'  >>  /etc/rc.d/rc.local