搭建服務器系列-第八篇-安裝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 則表示安裝成功.!在這裏插入圖片描述

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