LAMP-Apache的安装

有部分linux版本中已经安装了apache,先检查系统中是否已经存在httpd的服务

#查看是否存在
[root@localhost ~]# rpm -qa|grep httpd
httpd-2.2.15-60.el6.centos.4.x86_64
httpd-tools-2.2.15-60.el6.centos.4.x86_64

#存在,请将apache停止服务并删除
service httpd stop

#删除:如果出错,是因为有依赖关系,必须先删除依赖的应用,但是我们也可以忽略  使用--nodeps 忽略依赖
[root@localhost yum.repos.d]# rpm -e httpd-2.2.15-60.el6.centos.4.x86_64
error: Failed dependencies:
    httpd >= 2.2.0 is needed by (installed) gnome-user-share-2.28.2-3.el6.x86_64
[root@localhost yum.repos.d]# rpm -e --nodeps httpd-2.2.15-60.el6.centos.4.x86_64


[root@localhost ~]# rpm -e --nodeps  httpd-tools


一、软件下载

1 、Apache Http Server

地址:  http://httpd.apache.org/download.cgi#apache24

2 、APR和APR-util

地址:   http://apr.apache.org/download.cgi

1 、PCRE

地址:   https://sourceforge.net/projects/pcre/files/pcre/


二、安装

1、必须安装gcc/gcc-c++

#查看是否安装
[root@localhost ~]# gcc -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)

#没有安装,则安装
yum install -y gcc-c++

2、下载并安装apr

#下载
wget https://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-1.6.2.tar.gz

#解压
tar -zxvf apr-1.6.2.tar.gz

#配置并编译安装
cd apr-1.6.2
./configure --prefix=/usr/local/apr
make && make install

3、安装apr-util
 
#安装前需要先安装expat 库,否则只会会报错
yum install expat-devel

#下载
wget https://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-util-1.6.0.tar.gz

#解压
tar -zxvf apr-util-1.6.0.tar.gz

#配置并编译安装
cd apr-util-1.6.0
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config
make && make install

4、安装pcre

#解压
tar -zxvf pcre-8.41.tar.gz

#配置并编译安装
cd pcre-8.41
./configure --prefix=/usr/local/pcre --with-apr=/usr/local/apr/bin/apr-1-config
make && make install

5、安装apache

#下载
wget https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-2.4.27.tar.gz

#解压
tar -zxvf httpd-2.4.27.tar.gz

#配置并编译安装
cd httpd-2.4.27
./configure --prefix=/usr/local/apache --with-pcre=/usr/local/pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
make && make install

三,Apache设置为linux系统服务,并卡机启动

1、将apache启动脚本复制到系统服务目录

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

2、添加apache的环境变量

 echo -e '\nexport PATH=/usr/local/apache/bin:/usr/local/apache/lib:$PATH\n' >> /etc/profile && source /etc/profile

3、加入自启动服务

#编辑启动脚本
vim /etc/rc.d/init.d/httpd

#给脚本中添加注释
#chkconfig:2345 64 36


#当进行chkconfig --add httpd操作时,如果没有指定level那么就会来这个注释中取值

#添加到自启服务列表并开启自启
chkconfig --add httpd
chkconfig httpd on

4、修改配置文件

#编辑httpd.conf 文件
vim /usr/local/apache/conf/httpd.conf

将ServerName前面的#去掉, 
#ServerName www.example.com:80

5、启动服务
[root@localhost httpd-2.4.27]# service httpd start
Starting httpd:                                            [  OK  ]