目錄
一、編譯環境安裝
安裝Apache之前,我們需要安裝編譯Apache和所依賴的一些軟件包,其中有:gcc、gcc-c++、apr、apr-util、pcre等包。
① 安裝gcc、gcc-c++編譯環境
[root@localhost ~]# yum install gcc gcc-c++
② 安裝apr-1.6.5依賴包
[root@localhost src]# wget https://downloads.apache.org/apr/apr-1.6.5.tar.gz //下載壓縮包
[root@localhost src]# tar -zxvf apr-1.6.5.tar.gz //解壓
[root@localhost src]# cd apr-1.6.5 //進入解壓包目錄下
[root@localhost apr-1.6.5]# ./configure --prefix=/usr/local/apr-1.6.5 //配置
...省略部分信息
config.status: executing libtool commands
rm: cannot remove 'libtoolT': No such file or directory
config.status: executing default commands //配置過程報錯
//解決方法:將configure文件中 RM='$RM' 修改爲 RM='$RM -f';
[root@localhost apr-1.6.5]# make clean //清除之前產生配置文件
[root@localhost apr-1.6.5]# ./configure --prefix=/usr/local/apr-1.6.5 //再次配置即可成功
[root@localhost apr-1.6.5]# make && make install //編譯並安裝
③ 安裝apr-util-1.6.1依賴包
[root@localhost src]# wget https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz //下載壓縮包
[root@localhost src]# tar -zxvf apr-util-1.6.1.tar.gz //解壓
[root@localhost src]# cd apr-util-1.6.1 //進入解壓包目錄下
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util-1.6.1 --with-apr=/usr/local/apr-1.6.5/ //配置 apr-util需要和apr相關聯
[root@localhost apr-util-1.6.1]# make && make install //編譯並安裝
...省略部分信息
xml/apr_xml.c:35:19: 致命錯誤:expat.h:沒有那個文件或目錄 //編譯過程報錯
//解決方法:缺少expat庫,執行命令yum install expat-devel -y即可;
[root@localhost apr-util-1.6.1]# make && make install //再次編譯並安裝
④ 安裝pcre-8.42依賴包
[root@localhost src]# wget https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz //下載壓縮包
[root@localhost src]# tar -zxvf pcre-8.42.tar.gz //解壓
[root@localhost src]# cd pcre-8.42 ////進入解壓包目錄下
[root@localhost pcre-8.42]# ./configure --prefix=/usr/local/pcre-8.42
[root@localhost pcre-8.42]# make && make install //編譯並安裝
二、安裝Apache
[root@localhost src]# wget http://archive.apache.org/dist/httpd/httpd-2.4.41.tar.gz //下載httpd-2.4.41.tar.gz至/usr/local/src/目錄下
[root@localhost src]# tar -zxvf httpd-2.4.41.tar.gz //解壓
[root@localhost httpd-2.4.41]# ./configure --prefix=/usr/local/httpd-2.4.41 --with-apr=/usr/local/apr-1.6.5/ --with-apr-util=/usr/local/apr-util-1.6.1/ --with-pcre=/usr/local/pcre-8.42/ //配置 httpd需要和apr、apr-util、pcre相關聯
[root@localhost httpd-2.4.41]# make && make install //編譯並安裝
三、啓動httpd服務
[root@localhost local]# /usr/local/httpd-2.4.41/bin/apachectl start //啓動服務
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message //啓動報錯
[root@localhost local]# vim httpd-2.4.41/conf/httpd.conf //解決方法:編輯httpd.conf文件,搜索"#ServerName",添加ServerName localhost:80;
...省略部分信息
#ServerName www.example.com:80
ServerName localhost:80
...省略部分信息
[root@localhost local]# /usr/local/httpd-2.4.41/bin/apachectl restart //重啓服務
四、驗證是否啓動成功
- # netstat -tunl | grep 80 //查看80端口狀態
tcp6 0 0 :::80 :::* LISTEN
- # ps -ef | grep httpd //查看httpd進程
root 118816 1 0 21:20 ? 00:00:00 /usr/local/httpd-2.4.41/bin/httpd -k start
daemon 118938 118816 0 21:36 ? 00:00:00 /usr/local/httpd-2.4.41/bin/httpd -k start
daemon 118939 118816 0 21:36 ? 00:00:00 /usr/local/httpd-2.4.41/bin/httpd -k start
daemon 118940 118816 0 21:36 ? 00:00:00 /usr/local/httpd-2.4.41/bin/httpd -k start
root 119114 7439 0 21:45 pts/0 00:00:00 grep --color=auto httpd
- 通過瀏覽器訪問本地ip