CentOS 6.5安装Apache

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)

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

2、下载httpd软件包

[[email protected] /]# wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.2.31.tar.gz
--2016-08-26 20:07:22--  http://mirror.bit.edu.cn/apache/httpd/httpd-2.2.31.tar.gz
Resolving mirror.bit.edu.cn... 202.204.80.77, 2001:da8:204:2001:250:56ff:fea1:22
Connecting to mirror.bit.edu.cn|202.204.80.77|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7583841 (7.2M) [application/octet-stream]
Saving to: “httpd-2.2.31.tar.gz”

100%[==================================================>] 7,583,841   1.26M/s   in 5.0s    

2016-08-26 20:07:27 (1.46 MB/s) - “httpd-2.2.31.tar.gz” saved [7583841/7583841]

[[email protected] /]# 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、解压

[[email protected] httpd-2.2.31]# tar zxvf httpd-2.2.31.tar.gz
[[email protected] /]# cd httpd-2.2.31
[[email protected] httpd-2.2.31]# 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
[[email protected] httpd-2.2.31]# ls INSTALL README    #遇到不熟悉的软件是可参考这两个文件
INSTALL  README
[[email protected] httpd-2.2.31]# 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.
[[email protected] httpd-2.2.31]# 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、编译、安装

[[email protected] httpd-2.2.31]# yum -y install gcc
[[email protected] httpd-2.2.31]# ./configure --prefix=/usr/local/httpd-2.2.31 --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 解决 [[email protected] httpd-2.2.31]# yum -y install zlib zlib-devel 重新 [[email protected] httpd-2.2.31]# ./configure --prefix=/usr/local/httpd-2.2.31 --enable-deflate --enable-expires --enable-headers --enable-modules=most --enable-so --with-mpm=worker --enable-rewrite [[email protected] httpd-2.2.31]# echo $? 0
[[email protected] httpd-2.2.31]# make[[email protected] httpd-2.2.31]# make install
[[email protected] httpd-2.2.31]# echo $?
0

5、优化路径

[[email protected] httpd-2.2.31]# ln -s /usr/local/httpd-2.2.31/bin/* /usr/local/bin/

6、检查

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

7、启动服务

[[email protected] httpd-2.2.31]# /usr/local/bin/apachectl start
httpd: Could not reliably determine the server‘s fully qualified domain name, using localhost.localdomain for ServerName
[[email protected] httpd-2.2.31]# lsof -i :80
COMMAND   PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
httpd   14904   root    4u  IPv6  80734      0t0  TCP *:http (LISTEN)
httpd   14906 daemon    4u  IPv6  80734      0t0  TCP *:http (LISTEN)
httpd   14907 daemon    4u  IPv6  80734      0t0  TCP *:http (LISTEN)
httpd   14908 daemon    4u  IPv6  80734      0t0  TCP *:http (LISTEN)
[[email protected] httpd-2.2.31]# ps -ef | grep httpd
root     14904     1  0 21:00 ?        00:00:00 /usr/local/httpd-2.2.31/bin/httpd -k start
daemon   14905 14904  0 21:00 ?        00:00:00 /usr/local/httpd-2.2.31/bin/httpd -k start
daemon   14906 14904  0 21:00 ?        00:00:00 /usr/local/httpd-2.2.31/bin/httpd -k start
daemon   14907 14904  0 21:00 ?        00:00:00 /usr/local/httpd-2.2.31/bin/httpd -k start
daemon   14908 14904  0 21:00 ?        00:00:00 /usr/local/httpd-2.2.31/bin/httpd -k start
root     15006  1098  0 21:01 pts/0    00:00:00 grep httpd

8、测试

检查防火墙是否关闭

[[email protected] httpd-2.2.31]# /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端口访问,而不是关闭防火墙)

[[email protected] httpd-2.2.31]# /etc/init.d/iptables stop
[email protected] httpd-2.2.31]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT

关闭selinux

[[email protected] httpd-2.2.31]# setenforce 0  #临时关闭[[email protected] httpd-2.2.31]# cat /etc/selinux/config | grep SELINUX=enforcing
SELINUX=enforcing
[[email protected] httpd-2.2.31]# sed -i ‘s#SELINUX=enforcing#SELINUX=disabled#g‘ /etc/selinux/config
[[email protected] httpd-2.2.31]# cat /etc/selinux/config | grep SELINUX=
# SELINUX= can take one of these three values:
SELINUX=disabled

2、检查httpd端口80

[[email protected] httpd-2.2.31]# netstat -nlt | grep 80
tcp        0      0 :::80                       :::*                        LISTEN      

3、查看是否http进程

[[email protected] httpd-2.2.31]# ps -ef | grep http
root     14904     1  0 21:00 ?        00:00:00 /usr/local/httpd-2.2.31/bin/httpd -k start
daemon   14905 14904  0 21:00 ?        00:00:00 /usr/local/httpd-2.2.31/bin/httpd -k start
daemon   14906 14904  0 21:00 ?        00:00:00 /usr/local/httpd-2.2.31/bin/httpd -k start
daemon   14907 14904  0 21:00 ?        00:00:00 /usr/local/httpd-2.2.31/bin/httpd -k start
daemon   14908 14904  0 21:00 ?        00:00:00 /usr/local/httpd-2.2.31/bin/httpd -k start
daemon   15071 14904  0 21:03 ?        00:00:00 /usr/local/httpd-2.2.31/bin/httpd -k start
root     15147  1098  0 21:28 pts/0    00:00:00 grep http

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

[[email protected] httpd-2.2.31]# wget http://192.168.161.131
--2016-08-26 21:28:56--  http://192.168.161.131/
Connecting to 192.168.161.131:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 44 [text/html]
Saving to: “index.html”

100%[======================================>] 44          --.-K/s   in 0s      

2016-08-26 21:28:56 (7.26 MB/s) - “index.html” saved [44/44]

[[email protected] httpd-2.2.31]# curl 192.168.161.131

命令

[[email protected] httpd-2.2.31]# /usr/local/bin/apachectl
Usage: /usr/local/httpd-2.2.31/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
时间: 2024-08-01 19:16:20

CentOS 6.5安装Apache的相关文章

在CentOS 6上安装Apache和PHP

本文演示如何在CentOS 6上安装Apache和PHP.CentOS 6自带的是Apache 2.2.3和PHP 5.1.6,您可以使用默认的CentOS包管理器进行安装yum.使用yum(而不是使用源代码进行安装)的优点在于您可以获得任何安全更新(分发时),并且依赖关系被自动处理. 安装Apache 运行以下命令: sudo yum install httpd mod_ssl 因为服务器在安装Apache时不会自动启动,所以必须手动启动它. sudo /usr/sbin/apachectl

在CentOS 6 中安装 Apache,Mysql, PHP

1.安装Apache 在终端中输入下面的命令就可以安装Apache了: sudo yum install httpd sudo的意思是用root用户做什么操作.要点击y就确认下载安装了,非常方便. 然后用下面的命令来启动服务 sudo service httpd start 现在不用着急往下弄,直接在浏览器中输入DigitalOcean给你的IP地址,应该就可以访问到Apache的欢迎页面了.类似下面的样子: 是不是很酷?如果你的域名已经成功解析到你主机的IP地址上的话,用你的域名应该也可以访问

centos 源码安装apache

redhat6采用centos yum源. 第一步下载apache依赖的软件包并安装 安装 apr下载地址:http://apr.apache.org/download.cgi 解压包:tar -jxvf apr-1.5.0.tar.bz2 注意:这里的包的格式是tar.bz2格式,如果是.tar格式的用 tar -zxvf +包的名字 命令解压. 进入该包的文件夹内,依次执行以下命令: ./configure --prefix=/work/installed/apr (注意:configure

CentOS 下编译安装Apache

卸载原有的apache 首先从 http://httpd.apache.or 下载apache源码包httpd-2.4.4.tar.gz然后从 http://apr.apache.org 下载apr-1.4.6.tar.gz和apr-util-1.5.1.tar.gz然后从 http://sourceforge.net/ 下载pcre-8.32.tar.gz和pcre-devel-8.32.tar.gz 先装gcc和makeyum -y install gccyum -y install mak

centos系统yum安装apache+php+mysql

原文参考扩展来自:http://blog.csdn.net/lumengabc/article/details/38963609 先来解释一下,什么是 LAMP.正如标题所言,LAMP 实际上就是 Linux.Apache.MySQL.PHP 四个名称的缩写,当然最后一个 "P" 还有其他说法是 Perl 或者 Python.不用多说了,本文讲解的就是 Linux.Apache.MySQL.PHP 这四个东西,所以就这样解释了. 自己很早就在做网站,最初玩的是 ASP,后来主要研究 .

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

1. 更新系统内核到最新. [[email protected] ~]#yum -y update 系统更新后,如果yum安装时提示错误信息,请执行以下命令修复. [[email protected] ~]#rpm –import /etc/pki/rpm-gpg/RPM-GPG-KEY* 2. 安装Apahce, PHP, Mysql, 以及php连接mysql库组件 y[[email protected] ~]#um -y install httpd php mysql mysql-serv

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

LAMP 实际上就是 Linux.Apache.MySQL.PHP 四个名称的缩写,当然最后一个 “P” 还有其他说法是 Perl 或者 Python.不用多说了,本文讲解的就是 Linux.Apache.MySQL.PHP 这四个东西,所以就这样解释了. 由于 Linux 和 PHP 的免费,在国外是相当的流行.国内大部分主机都是 Windows 平台,而我学的 ASP 和 .Net 刚好能搭配运行起来.后来由于种种原因,我的网站都移民到了国外,而在国外找一个性价比好的 Windows 主机实

Ubuntu 16.04/CentOS 6.9安装Apache压力测试工具ab

说明: ab工具已经在Apache中包含,如果不想安装Apache,那么可以使用下面方法单独安装. 安装: Ubuntu: sudo apt-get install apache2-utils CentOS: sudo yum -y install httpd-tools 官网: http://httpd.apache.org/(Apache服务器) http://httpd.apache.org/docs/2.0/programs/(Apache工具文档大全) http://httpd.apa

尝试CentOS 6.8安装Apache服务

1.安装development tools程序包组 安装Apache服务器前需要解决依赖性问题,比如需要安装GCC.GCC++.OPENSSL等等,因为是在虚拟机里做实验,这里就通过直接安装包组的方法解决依赖性问题. (1)挂载安装光盘,并安装"Development tools"包组 [[email protected] ~]# mount /dev/cdrom /media   将光盘挂载到media目录 [[email protected] ~]# cd /etc/yum.rep