1. 介紹
1.1 介紹
在linux操作系統(tǒng)下面,apache是非常流行的web服務(wù)器威恼,大部分生產(chǎn)環(huán)境都是使用apache作為web服務(wù)器的,apache和php是親密搭檔,所以學(xué)習(xí)php編程就一定要學(xué)會(huì)安裝使用apache這個(gè)web服務(wù)器軟件
2. 基本信息
2.1 安裝環(huán)境
CentOS:CentOS Linux release 7.6.1810 (Core)
Linux:Linux version 3.10.0-1062.el7.x86_64
GCC:gcc version 4.8.5 20150623?(Red Hat 4.8.5-36) (GCC)
2.2?軟件版本
apr-1.6.5.tar.gz
apr-util-1.6.1.tar.gz
httpd-2.4.46.tar.gz
2.3 驗(yàn)證時(shí)間
2020/09/12
3. 準(zhǔn)備工作
3.1 本地化
如果是新環(huán)境浊闪,我們需要設(shè)置時(shí)區(qū)以保證時(shí)間顯示正確
timedatectl?set-timezone?Asia/Shanghai
3.2?安裝wget
如果環(huán)境里沒有wget泌枪,通過yum安裝一下
yum?-y?install?wget
3.3?安裝gcc
如果環(huán)境里沒有編譯工具概荷,通過yum安裝一下
yum?-y?install?gcc?gcc-c++?make
3.4?安裝依賴包
這些是apache依賴的軟件庫(kù)
yum?-y?install?expat-devel?pcre-devel?openssl-devel?perl?libxml*?curl-devel?freetype-devel?autoconf
3.5?建立環(huán)境根目錄
建立軟件安裝根目錄
mkdir?-p?/tongfu.net/env/
3.6?建立安裝包目錄并進(jìn)入
建立軟件安裝包保存目錄
mkdir?/packages
cd?/packages
4. 安裝Apache 2.4
4.1 準(zhǔn)備
apr-1.6.5.tar.gz
apr-util-1.6.1.tar.gz
httpd-2.4.46.tar.gz
4.2 下載安裝包
下載apr,apr-util碌燕,httpd軟件包
wget?http://mirror.bit.edu.cn/apache/apr/apr-1.6.5.tar.gz
wget?http://mirror.bit.edu.cn/apache/apr/apr-util-1.6.1.tar.gz
wget?http://mirror.bit.edu.cn/apache/httpd/httpd-2.4.46.tar.gz
4.3 百度網(wǎng)盤資源
4.3.1 apr-1.6.5.tar.gz
鏈接: https://pan.baidu.com/s/1-tpTzQy7KeoOLO5IPLsIqA 提取碼: buyx
4.3.2 apr-util-1.6.1.tar.gz
鏈接: https://pan.baidu.com/s/14N5yMQKQQTOACrl4--PutA 提取碼: f2fk
4.3.3 httpd-2.4.46.tar.gz
鏈接: https://pan.baidu.com/s/1BeLWykiEc0_9Txp7AH974g 提取碼: uu7m
4.4 安裝apr
tar?xzvf?apr-1.6.5.tar.gz
cd?apr-1.6.5
./configure?--prefix=/tongfu.net/env/apr-1.6.5
make?&&?make?install
cd?..
4.5?安裝apr-util
tar?xzvf?apr-util-1.6.1.tar.gz
cd?apr-util-1.6.1
./configure?--prefix=/tongfu.net/env/apr-util-1.6.1?\
--with-apr=/tongfu.net/env/apr-1.6.5/bin/apr-1-config?
make?&&?make?install
cd?..
4.6?安裝httpd
tar?xzvf?httpd-2.4.46.tar.gz
cd?httpd-2.4.46
./configure?--prefix=/tongfu.net/env/httpd-2.4.46?\
--with-apr=/tongfu.net/env/apr-1.6.5?\
--with-apr-util=/tongfu.net/env/apr-util-1.6.1?\
--with-pcre?\
--enable-so?\
--enable-rewrite?\
--enable-ssl
make?&&?make?install
cd?..
4.7?初始化
打開 httpd.conf 配置文件
將 ServerAdmin 設(shè)置為 webmaster@tongfu.net
將 ServerName 設(shè)置為 localhost
將 Listen 設(shè)置為 8080
[root@tfdev]#?vi?/tongfu.net/env/httpd-2.4.46/conf/httpd.conf
ServerAdmin?webmaster@localhost
ServerName?localhost
Listen?8080
注意:為什么我們要把Apache的端口設(shè)置為 8080 呢误证?因?yàn)橐话闱闆r下Apache都是工作在Nginx后面的
4.8 啟動(dòng)
啟動(dòng)apache
/tongfu.net/env/httpd-2.4.46/bin/apachectl?start
4.9?自動(dòng)啟動(dòng)
添加系統(tǒng)服務(wù)腳本
[root@tfdev]#?cat?>?/lib/systemd/system/httpd.service?<<EOF
[Unit]
Description=httpd
After=network.target
[Service]
Type=forking
ExecStart=/tongfu.net/env/httpd-2.4.46/bin/apachectl?start
ExecReload=/tongfu.net/env/httpd-2.4.46/bin/apachectl?restart
ExecStop=/tongfu.net/env/httpd-2.4.46/bin/apachectl?stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
使用 systemctl 管理 httpd 服務(wù)
systemctl?enable?httpd?#?設(shè)置自動(dòng)啟動(dòng)
systemctl?start?httpd?#?啟動(dòng)服務(wù)
systemctl?stop?httpd?#?停止服務(wù)
systemctl?restart?httpd?#?重啟服務(wù)
4.10 關(guān)閉防火墻
默認(rèn)CentOS 7會(huì)開啟防火墻继薛,開發(fā)環(huán)境的話,直接將防火墻關(guān)掉就可以了
systemctl?stop?firewalld
systemctl?disable?firewalld
5.?測(cè)試
5.1?curl測(cè)試
通過curl命令測(cè)試
[root@fdev]#?curl?'http://localhost:8080/'
<html><body><h1>It?works!</h1></body></html>
5.2 瀏覽器測(cè)試
通過瀏覽器測(cè)試
【20200912】Apache2.4安裝筆記 第 1 頁 - 鬼谷子叔叔的主頁 - 同福網(wǎng) - TONGFU.net