搭建服务器系列-第八篇-安装Apache服务器

第八篇:安装Apache服务器

选择安装方式

  1. yum 安装
  2. 源码安装

本篇选择源码安装

1.安装依赖
yum -y install wget make gcc gcc-c++ pcre openssl openssl-devel zlib unzip cmake ncurses-devel libjpeg libjpeg-devel libpng libpng-devel libxml2 libxml2-devel curl-devel libtool libtool-ltdl libtool-ltdl-devel libevent libevent-devel zlib-static zlib-devel autoconf pcre-devel gd perl freetype freetype-devel
2.安装apr
wget http://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-1.7.1.tar.gz
tar xf apr-1.7.1.tar.gz 
cd apr-1.7.1
./configure --prefix=/usr/local/apr/
make && make install

安装成功之后 执行 echo $? 如果为0 则表示安装成功

3.安装apr-util
wget http://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-util-1.6.1.tar.gz
tar -zxvf apr-util-1.6.1.tar.gz
cd apr-util-1.6.1
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install
警告

如果遇到 apr-util 执行make命令时报错 提示 “xml/apr_xml.c:35:19: error: expat.h: No such file or directory” 则是缺少 expat库 可以使用 yum进行安装
yum install expat-devel
安装成功之后,再次执行 make && make install 进行安装

4.安装Apache服务

首先进行创建用户
groupadd apache #添加用户组
useradd -g apache apache -s /bin/nologin -M #创建用户 无需登录 无家目录

下载Apache源码
wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.4.39.tar.gz
解压
tar -zvxf httpd-2.4.39.tar.gz
进入目录
cd httpd-2.4.39

进行编译

>./configure --prefix=/usr/local/httpd/ \
--sysconfdir=/etc/httpd/ \
--with-include-apr \
--disable-userdir \
--enable-headers \
--with-mpm=worker \
--enable-modules=most \
--enable-so \
--enable-deflate \
--enable-defate=shared \
--enable-expires-shared \
--enable-rewrite=shared \
--enable-static-support \
--with-apr=/usr/local/apr/ \
--with-apr-util=/usr/local/apr-util/bin \
--with-ssl \
--with-z 

安装成功之后提示

    Server Version: 2.4.39
    Install prefix: /usr/local/httpd/
    C compiler:     gcc -std=gnu99
    CFLAGS:          -g -O2 -pthread  
    CPPFLAGS:        -DLINUX -D_REENTRANT -D_GNU_SOURCE  
    LDFLAGS:           
    LIBS:             
    C preprocessor: gcc -E

执行成功之后进行安装 make && make install

5.修改Apache 配置(/etc/httpd/httpd.conf)

安装成功之后进行用户的修改
vim /etc/httpd/httpd.conf
修改服务器
ServerAdmin [email protected] 修改成 ServerAdmin localhost
ServerName www.example.com:80 修改成 ServerName localhost:80

####### 6.配置Apache 开启自启动
cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd #将脚本复制 init.d文件中
修改你的vim /etc/init.d/httpd脚本 在开始处#!/bin/bash之后的行后插入

# chkconfig: 345 61 61
# description:Apache httpd

增加http到 chkconfig 启动文件中

chkconfig --add httpd
chkconfig --level 2345 httpd on

查看是否成功
chkconfig --list | grep httpd
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off

####### 7.启动|停止|重启|apache方式

启动|停止|重启   /etc/init.d/httpd start|stop|restart

#扩展
启动          /usr/local/httpd/bin/apachectl -f /etc/httpd/httpd.conf
暴力停止      /usr/local/httpd/bin/apachectl -k stop
优雅停止      /usr/local/httpd/bin/apachectl -k graceful-stop
优雅的重启   /usr/local/httpd/bin/apachectl -k graceful
暴力重启     /usr/local/httpd/bin/apachectl -k restart

开启成功之后 进行访问如果显示 It Works 则表示安装成功.!在这里插入图片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章