1、Apache的特点

功能强大、配置简单、速度快、应用广泛、性能稳定可靠,并可做代理服务器或负载均衡来使用

2、Apache的应用场合

使用Apache运行静态HTML网页、图片(处理静态小文件能力不及Nginx)。
使用Apache结合PHP引擎运行PHP、Perl、Python等程序
使用Apache结合Tomcat/Resion运行JSP,JAVA等程序
使用Apache作代理、负载均衡、rewrite规则过滤等等。

安装Apache

1、确认主机名、检查是否已经存在httpd、如果已经存在先卸载(使用rpm -e  --nodeps)

[root@httpd /]# hostname httpd
[root@httpd /]# rpm -qa httpd
rpm -e --nodeps 加 rpm -qa httpd 查看到的包名
rpm命令-qa参数
-q 查询的意思
-a 所有软件包
-e 移除的意思
--nodeps 不做软件间的依赖检查
更过参数使用man rpm 或 rpm --help查看

2、下载httpd软件包

[root@localhost /]# wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.2.31.tar.gz
---- ::-- http://mirror.bit.edu.cn/apache/httpd/httpd-2.2.31.tar.gz
Resolving mirror.bit.edu.cn... 202.204.80.77, :da8::::56ff:fea1:
Connecting to mirror.bit.edu.cn|202.204.80.77|:... connected.
HTTP request sent, awaiting response... OK
Length: (7.2M) [application/octet-stream]
Saving to: “httpd-2.2..tar.gz” %[==================================================>] ,, 1.26M/s in .0s -- :: (1.46 MB/s) - “httpd-2.2..tar.gz” saved [/]

[root@localhost /]# ll httpd-2.2.31.tar.gz
-rw-r--r--. 1 root root 7583841 Aug 26 20:10 httpd-2.2.31.tar.gz

3、解压

[root@localhost httpd-2.2.]# tar zxvf httpd-2.2..tar.gz
[root@localhost /]# cd httpd-2.2.
[root@localhost httpd-2.2.]# ls
ABOUT_APACHE CHANGES httpd.dsp libhttpd.dep NOTICE server
acinclude.m4 config.layout httpd.mak libhttpd.dsp NWGNUmakefile srclib
Apache.dsw configure httpd.spec libhttpd.mak os support
build configure.in include LICENSE README test
BuildAll.dsp docs INSTALL Makefile.in README.platforms VERSIONING
BuildBin.dsp emacs-style InstallBin.dsp Makefile.win README-win32.txt
buildconf httpd.dep LAYOUT modules ROADMAP
[root@localhost httpd-2.2.]# ls INSTALL README #遇到不熟悉的软件是可参考这两个文件
INSTALL README
[root@localhost httpd-2.2.]# less INSTALL APACHE INSTALLATION OVERVIEW Quick Start - Unix
------------------ For complete installation documentation, see [ht]docs/manual/install.html or
http://httpd.apache.org/docs/2.2/install.html $ ./configure --prefix=PREFIX
$ make
$ make install
$ PREFIX/bin/apachectl start NOTES: * Replace PREFIX with the filesystem path under which
Apache should be installed. A typical installation
might use "/usr/local/apache2" for PREFIX (without the
quotes). * If you are a developer who will be linking your code with
Apache or using a debugger to step through server code,
./configure's --with-included-apr option may be advantageous,
as it removes the possibility of version or compile-option
mismatches with APR and APR-util code. (Many OSes now
include their own version of APR and APR-util.) * If you are a developer building Apache directly from
Subversion, you will need to run ./buildconf before running
configure. This script bootstraps the build environment and
requires Python as well as GNU autoconf and libtool. If you
build Apache from a release tarball, you don't have to run
buildconf.
[root@localhost httpd-2.2.]# less README Apache HTTP Server What is it?
----------- The Apache HTTP Server is a powerful and flexible HTTP/1.1 compliant
web server. Originally designed as a replacement for the NCSA HTTP
Server, it has grown to be the most popular web server on the
Internet. As a project of the Apache Software Foundation, the
developers aim to collaboratively develop and maintain a robust,
commercial-grade, standards-based server with freely available
source code. The Latest Version
------------------ Details of the latest version can be found on the Apache HTTP
server project page under <http://httpd.apache.org/>. Documentation
-------------

4、编译、安装

[root@localhost httpd-2.2.]# yum -y install gcc
[root@localhost httpd-2.2.]# ./configure --prefix=/usr/local/httpd-2.2. --enable-deflate --enable-expires --enable-headers --enable-modules=most --enable-so --with-mpm=worker --enable-rewrite
 checking for zlib location... not found checking whether to enable mod_deflate... configure: error: mod_deflate has been requested but can not be built due to prerequisite failures 
解决
缺少
zlib-devel
[root@localhost httpd-2.2.]# yum -y install zlib zlib-devel
重新
[root@localhost httpd-2.2.]# ./configure --prefix=/usr/local/httpd-2.2. --enable-deflate --enable-expires --enable-headers --enable-modules=most --enable-so --with-mpm=worker --enable-rewrite
[root@localhost httpd-2.2.31]# make
[root@localhost httpd-2.2.31]# make install
[root@localhost httpd-2.2.31]# echo $?
0

5、优化路径

[root@localhost httpd-2.2.]# ln -s /usr/local/httpd-2.2./bin/* /usr/local/bin/

6、检查

[root@localhost httpd-2.2.]# /usr/local/bin/apachectl -t
httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
Syntax OK

[root@localhost httpd-2.2.31]# cd /usr/local/httpd-2.2.31/conf/
[root@localhost conf]# pwd
/usr/local/httpd-2.2.31/conf

[root@localhost conf]# vim httpd.conf

ServerName www.httpd.com:80

[root@httpd conf]# /usr/local/bin/apachectl -t
Syntax OK

7、启动服务

[root@localhost conf]# /usr/local/bin/apachectl start
[root@localhost conf]# lsof -i :
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
httpd root 4u IPv6 0t0 TCP *:http (LISTEN)
httpd daemon 4u IPv6 0t0 TCP *:http (LISTEN)
httpd daemon 4u IPv6 0t0 TCP *:http (LISTEN)
httpd daemon 4u IPv6 0t0 TCP *:http (LISTEN)
[root@localhost conf]# ps -ef | grep httpd
root : ? :: /usr/local/httpd-2.2./bin/httpd -k start
daemon : ? :: /usr/local/httpd-2.2./bin/httpd -k start
daemon : ? :: /usr/local/httpd-2.2./bin/httpd -k start
daemon : ? :: /usr/local/httpd-2.2./bin/httpd -k start
daemon : ? :: /usr/local/httpd-2.2./bin/httpd -k start
root : pts/ :: grep httpd

[root@localhost conf]# cp /usr/local/httpd-2.2.31/bin/apachectl /etc/init.d/httpd
[root@localhost conf]# vim /etc/init.d/httpd

#chkconfig: 35 85 15

[root@localhost conf]# chkconfig --add httpd

8、测试

检查防火墙是否关闭

[root@localhost httpd-2.2.]# /etc/init.d/iptables stop
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]

打开浏览器访问http://192.168.161.131/

如果访问不了It works 页面、排查

1、iptables防火墙和selinux是否关闭(在生产环境中允许80端口访问,而不是关闭防火墙)

[root@localhost httpd-2.2.]# /etc/init.d/iptables stop
root@localhost httpd-2.2.]# iptables -I INPUT -p tcp --dport -j ACCEPT

关闭selinux

[root@localhost httpd-2.2.31]# setenforce 0  #临时关闭
[root@localhost httpd-2.2.]# cat /etc/selinux/config | grep SELINUX=enforcing
SELINUX=enforcing
[root@localhost httpd-2.2.]# sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
[root@localhost httpd-2.2.]# cat /etc/selinux/config | grep SELINUX=
# SELINUX= can take one of these three values:
SELINUX=disabled

2、检查httpd端口80

[root@localhost httpd-2.2.]# netstat -nlt | grep
tcp ::: :::* LISTEN

3、查看是否http进程

[root@localhost httpd-2.2.]# ps -ef | grep http
root : ? :: /usr/local/httpd-2.2./bin/httpd -k start
daemon : ? :: /usr/local/httpd-2.2./bin/httpd -k start
daemon : ? :: /usr/local/httpd-2.2./bin/httpd -k start
daemon : ? :: /usr/local/httpd-2.2./bin/httpd -k start
daemon : ? :: /usr/local/httpd-2.2./bin/httpd -k start
daemon : ? :: /usr/local/httpd-2.2./bin/httpd -k start
root : pts/ :: grep http

4、在服务器上wget http://192.168.161.131

[root@localhost httpd-2.2.]# wget http://192.168.161.131
---- ::-- http://192.168.161.131/
Connecting to 192.168.161.131:... connected.
HTTP request sent, awaiting response... OK
Length: [text/html]
Saving to: “index.html” %[======================================>] --.-K/s in 0s -- :: (7.26 MB/s) - “index.html” saved [/] [root@localhost httpd-2.2.]# curl 192.168.161.131

命令

[root@localhost httpd-2.2.]# /usr/local/bin/apachectl
Usage: /usr/local/httpd-2.2./bin/httpd [-D name] [-d directory] [-f file]
[-C "directive"] [-c "directive"]
[-k start|restart|graceful|graceful-stop|stop]
[-v] [-V] [-h] [-l] [-L] [-t] [-T] [-S]
Options:
-D name : define a name for use in <IfDefine name> directives
-d directory : specify an alternate initial ServerRoot
-f file : specify an alternate ServerConfigFile
-C "directive" : process directive before reading config files
-c "directive" : process directive after reading config files
-e level : show startup errors of level (see LogLevel)
-E file : log startup errors to file
-v : show version number
-V : show compile settings
-h : list available command line options (this page)
-l : list compiled in modules
-L : list available configuration directives
-t -D DUMP_VHOSTS : show parsed settings (currently only vhost settings)
-S : a synonym for -t -D DUMP_VHOSTS
-t -D DUMP_MODULES : show all loaded modules
-M : a synonym for -t -D DUMP_MODULES
-t : run syntax check for config files
-T : start without DocumentRoot(s) check

apache目录下的命令和文件介绍

[root@localhost httpd-2.2.]# pwd
/usr/local/httpd-2.2.
[root@localhost httpd-2.2.]# ls
bin cgi-bin error icons lib man modules
build conf htdocs include logs manual
[root@localhost httpd-2.2.]# tree bin
bin
├── ab    #apache HTTP服务器性能测试工具、同类软件jmeter、loadrunner、webbench等
├── apachectl #apache启动命令、apachectl是一个脚本
├── apr--config
├── apu--config
├── apxs   #apxs是一个apache HTTP服务器编译和安装扩展模块的工具、在进行DSO方式编译模块时会用到
├── checkgid
├── dbmmanage
├── envvars
├── envvars-std
├── htcacheclean #清理磁盘缓冲区的命令、需要编译时指定相关参数才可使用。
├── htdbm
├── htdigest
├── htpasswd    #建立和更新基本认证文件
├── httpd    #httpd为apache的控制程序、apachectl执行时会调用httpd。
├── httxt2dbm
├── logresolve
└── rotatelogs   #apache自带的日志轮询命令 directories, files

[root@localhost httpd-2.2.31]# ll conf/
total 92
drwxr-xr-x. 2 root root 4096 Aug 26 20:48 extra  #额外的apache配置文件目录、httpd-vhosts.conf默认就在此目录
-rw-r--r--. 1 root root 13646 Aug 26 20:48 httpd.conf  #apache的主配置文件
-rw-r--r--. 1 root root 12958 Aug 26 20:48 magic
-rw-r--r--. 1 root root 53011 Aug 26 20:48 mime.types
drwxr-xr-x. 3 root root 4096 Aug 26 20:48 original

[root@localhost httpd-2.2.31]# ll htdocs/   #编译安装时apache的默认站点目录
total 4
-rw-r--r--. 1 1000 1000 44 Nov 21 2004 index.html   #默认首页文件

[root@localhost httpd-2.2.31]# ll logs/  #apache默认日志文件路径
total 12
-rw-r--r--. 1 root root 454 Aug 29 16:09 access_log  #apache默认访问日志
srwx------ 1 daemon root 0 Aug 29 16:09 cgisock.1216
-rw-r--r--. 1 root root 868 Aug 29 16:09 error_log  #apache错误日志文件
-rw-r--r-- 1 root root 5 Aug 29 16:09 httpd.pid  #httpd的pid文件、http进程启动后、会把所有进程的ID写到此文件。

[root@localhost httpd-2.2.31]# ll modules/  #apache模块目录
total 12
-rw-r--r--. 1 root root 9194 Aug 26 20:47 httpd.exp

apache优化

[root@localhost httpd-2.2.]# cd conf/
[root@localhost conf]# vim httpd.conf
<Directory "/usr/local/httpd-2.2.31/htdocs">
Options Indexes FollowSymLinks #如果没有首页的情况下会展示目录结构、 建议把Indexes删除 或改为-Indexes 、如果把目录展示禁用后、没有首页的情况下会报错403

CentOS 6.5安装Apache的更多相关文章

  1. 在CentOS 6上安装Apache和PHP

    本文演示如何在CentOS 6上安装Apache和PHP.CentOS 6自带的是Apache 2.2.3和PHP 5.1.6,您可以使用默认的CentOS包管理器进行安装yum.使用yum(而不是使 ...

  2. 在CentOS 6 中安装 Apache,Mysql, PHP

    1.安装Apache 在终端中输入以下的命令就能够安装Apache了: sudo yum install httpd sudo的意思是用root用户做什么操作.要点击y就确认下载安装了,非常方便. 然 ...

  3. CentOS 下编译安装Apache

    CentOS 下编译安装Apache 卸载原有的apache 首先从 http://httpd.apache.or 下载apache源码包httpd-2.4.4.tar.gz然后从 http://ap ...

  4. centos手动编译安装apache、php、mysql

    64位centos 5.5手动安装lamp,要求curl.json.pdo_mysql.gd,记录如下. centos 5.4.5.5.5.6的内核都是2.6.18,都可以安装php 5.3. 卸载旧 ...

  5. CentOS 6.4安装Apache+MySQL+PHP的图文教程

    LAMP 实际上就是 Linux.Apache.MySQL.PHP 四个名称的缩写,当然最后一个 “P” 还有其他说法是 Perl 或者 Python.不用多说了,本文讲解的就是 Linux.Apac ...

  6. 转载:centos上yum安装apache+php+mysql等

    1. 更新系统内核到最新. [root@linuxfei ~]#yum -y update 系统更新后,如果yum安装时提示错误信息,请执行以下命令修复. [root@linuxfei ~]#rpm ...

  7. centos 7.2 安装apache,mysql,php5.6

    安装Apache.PHP.Mysql.连接Mysql数据库的包: yum -y install httpd yum -y install php yum -y install php-fpm yum  ...

  8. Ubuntu 16.04/CentOS 6.9安装Apache压力(并发)测试工具ab

    说明: ab工具已经在Apache中包含,如果不想安装Apache,那么可以使用下面方法单独安装. 安装: Ubuntu: sudo apt-get install apache2-utils Cen ...

  9. Centos 7 集成安装Apache+PHP+Kerberos+LDAP+phpLDAPadmin

    一.安装Apache 1.1.安装Apache Apache程序是目前拥有很高市场占有率的Web服务程序之一,其跨平台和安全性广泛被认可且拥有快速.可靠.简单的API扩展. 它的名字取自美国印第安人土 ...

  10. 如何在CentOS 7上安装Apache

    使用systemctl管理Apache服务 我们可以像任何其他系统单元一样管理Apache服务. 要停止Apache服务,请运行: sudo systemctl stop httpd 要再次启动,请键 ...

随机推荐

  1. Linux爆新漏洞,长按回车键70秒即可获得root权限

    漏洞来源这个安全问题来源于Cryptsetup存在的一个漏洞(CVE-2016-4484).Cryptsetup是在Linux统一密钥设置(Linux Unified Key Setup, LUKS) ...

  2. JAVA内存机制

    Java程序运行时,数据会分区存放,JavaStack(Java栈). heap(堆).method(方法区). 一.JVM内存模型 1.Java栈Java栈的区域很小,只有1M,特点是存取速度很快, ...

  3. WinForm------分页控件dll下载地址

    转载: http://files.cnblogs.com/wuhuacong/TestPager_SqlLite.rar

  4. python实现软件的注册功能(机器码+注册码机制)

    http://www.cnblogs.com/cquptzzq/p/5940583.html 一.前言: 目的:完成已有python图像处理工具的注册功能 功能:用户运行程序后,通过文件自动检测认证状 ...

  5. 利用a标签解析URL

    参考资料 http://www.cnblogs.com/Wayou/p/things_you_dont_know_about_frontend.html 很多时候我们有从一个URL中提取域名,查询关键 ...

  6. Android studio 的初始设置

    [声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4 ...

  7. CLR 公共语言运行库

    1..支持多语言..只是语言是面向CLR的..均可以在此基础上运行. 2..程序集加载..程序打包之后的Dll文件由CLR(公共语言运行库)来编译并加载到可以执行状态..由CLR(公共语言运行库)加载 ...

  8. linux lsmod命令 及相关信息

    lsmod  (list modules) 语法:lsmod 功能: lsmod命令:是一个小程序,用来显示文件.proc/modules的信息,也就是显示当前内核模块装载的模块. 补充说明: 执行l ...

  9. 看见了就转来了, 涉及到UBOOT 地址的一个问题.

    addr = (_bss_end + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);什么意思? 这是UBOOT 中的一个分配视频帧缓冲区地址的函数,我想问的是:加一个 ...

  10. php基础语法-函数等

    php是弱类型语言, 但并不是 无类型 语言! 同样有变量类型, ====================================================== 形容词(短语)修饰名词的 ...