linux下安装apache

来源:互联网 发布:中国硕士人数知乎 编辑:程序博客网 时间:2024/06/10 23:51

1、下载apache安装包
下载地址:http://httpd.apache.org/
# wget http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.2.32.tar.gz

2、解压安装包
# tar -zxvf httpd-2.2.32.tar.gz

3、编译安装
进入到解压目录执行命令
# ./configure –prefix=/usr/local/apache2/

可能会报错:
这里写图片描述
这是因为没有安装C++的环境,yum安装就行啦
# yum install -y gcc gcc-c++

再重新配置:# ./configure –prefix=/usr/local/apache2/
然后编译:# make
安装:# make install

4、启动apache
在启动apache之前,最好查看下配置文件/usr/local/apache2/conf/httpd.conf(注意安装目录)。把ServerName改成 127.0.0.1:80,并把前面的#号去掉。
这里写图片描述
下面就可以启动Apache了。
# /usr/local/apache2/bin/apachectl start(注意安装目录)

5、安装2.4版本的apache。
如果要安装2.4版本的apache,在配置(./configure )的时候会分别出现了apr not found、APR-util not found、pcre-config for libpcre not found的问题。
http://apr.apache.org/download.cgi 下载apr-1.4.5.tar.gz、apr-util-1.3.12.tar.gz
http://sourceforge.net/projects/pcre/files/latest/download 下载pcre-8.31.zip
5.1 解决apr not found问题
# tar -zxf apr-1.4.5.tar.gz
# ./configure –prefix=/usr/local/apr
# make
# make install

5.2 解决APR-util not found问题
# tar -zxf apr-util-1.3.12.tar.gz
# ./configure –prefix=/usr/local/apr-util -with-apr=/usr/local/apr/bin/apr-1-config
# make
# make install

5.3 解决pcre-config for libpcre not found问题
# unzip pcre-8.31.zip
# cd pcre-8.31
# ./configure –prefix=/usr/local/pcre
# make[root@localhost pcre-8.31]
# make install

以上安装过程都需注意安装目录。

6、将apache安装为系统服务
# cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd

然后
# vi /etc/rc.d/init.d/httpd 添加(#!/bin/sh下面)

# chkconfig: 2345 50 90

# description: Activates/Deactivates Apache Web Server

最后,运行chkconfig把Apache添加到系统的启动服务组里面:

# chkconfig –add httpd
# chkconfig httpd on
然后再
# service httpd start

OK成功了,但是 # service httpd status 却一直报错
这里写图片描述

这个是由于编译安装的时候没有加上 –enable- module=so 。这是一个大坑!!!

0 0
原创粉丝点击