首页 > 代码库 > LAMP搭建2:Apache安装

LAMP搭建2:Apache安装

1.进入/usr/local/src/目录下去下载Apache的安装包httpd-2.2.29.tar.gz

[root@CentOS6 support-files]# cd /usr/local/src

[root@CentOS6 src]# ls

httpd-2.2.9.tar.gz

2.解压安装包

[root@CentOS6 src]# tar zxvf httpd-2.2.9.tar.gz

3.进入安装目录

[root@CentOS6 src]# cd httpd-2.2.9

[root@CentOS6 httpd-2.2.9]# ls

ABOUT_APACHE      CHANGES        include         modules           srclib

acinclude.m4      config.layout  INSTALL         NOTICE            support

Apache.dsw        configure      InstallBin.dsp  NWGNUmakefile     test

apachenw.mcp.zip  configure.in   LAYOUT          os                VERSIONING

build             docs           libhttpd.dsp    README

BuildAll.dsp      emacs-style    LICENSE         README.platforms

BuildBin.dsp      httpd.dsp      Makefile.in     ROADMAP

buildconf         httpd.spec     Makefile.win    server

4.查看安装说明文件INSTALL可以看到安装步骤

……

$ ./configure --prefix=PREFIX

$ make

$ make install

$ PREFIX/bin/apachectl start

……

5.使用下面的参数配置安装选项,回车即可

[root@CentOS6 httpd-2.2.9]# ./configure --prefix=/usr/local/apache2 --with-included-apr --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --with-pcre

其中:

--prefix 指定安装目录

--with-include-apr 依赖包apr,支持httpd,可以跨平台运作

--with-pcre 正则相关的库

shared表示以动态共享的方式安装

有错改错,缺少什么库就安装:

如checking whether to enable mod_deflate... configure: error: mod_deflate has been requested but can not be built due to prerequisite failures

yum install  zlib-devel

6.直到配置没有问题然后开始编译

[root@CentOS6 httpd-2.2.9]# echo $?

0

[root@CentOS6 httpd-2.2.9]# make

7.编译没问题然后开始安装

[root@CentOS6 httpd-2.2.9]# echo $?

0

[root@CentOS6 httpd-2.2.9]# make install

8.安装成功

[root@CentOS6 httpd-2.2.9]# echo $?

0

[root@CentOS6 httpd-2.2.9]# ls /usr/local/apache2/

bin    cgi-bin  error   icons    lib   man     modules

build  conf     htdocs  include  logs  manual

9.现在还不能直接运行,需要编辑Apache主配置文件httpd.conf:

[root@CentOS6 httpd-2.2.9]# vim /usr/local/apache2/conf/httpd.conf

将ServerName改为localhost:80,去掉前面的注释符#

……

# ServerName gives the name and port that the server uses to identify itself.

# This can often be determined automatically, but we recommend you specify

# it explicitly to prevent problems during startup.

#

# If your host doesn‘t have a registered DNS name, enter its IP address here.

#

ServerName localhost:80

……

10.将Apache加入系统环境变量:

[root@CentOS6 support-files]# vim /etc/profile.d/path.sh

#!/bin/bash

export PATH=$PATH:/etc/init.d/:/usr/local/mysql/bin/:/usr/local/apache2/bin/

[root@CentOS6 support-files]# source /etc/profile.d/path.sh

11.检查配置是否正确,正确则启动Apache

[root@CentOS6 httpd-2.2.9]# apachectl -t

Syntax OK

[root@CentOS6 httpd-2.2.9]# apachectl start

httpd (pid 22581) already running

12.查看Apache的进程和端口

[root@CentOS6 httpd-2.2.9]# ps aux|grep httpd

[root@CentOS6 httpd-2.2.9]# netstat -lnp


LAMP搭建2:Apache安装