1. 程式人生 > >apache編譯安裝

apache編譯安裝

mod 主程序 阿帕奇 排名 archive 4.2 onf openssl with

cetos7.4下編譯安裝:
Apache是世界使用排名第一的Web服務器軟件。它可以運行在幾乎所有廣泛使用的計算機平臺上,由於其跨平臺和安全性被廣泛使用,是最流行的Web服務器端軟件之一。它快速、可靠並且可通過簡單的API擴充,將Perl/Python等解釋器編譯到服務器中。同時Apache音譯為阿帕奇!(引用網絡中的詞)
需要源碼編譯安裝的軟件包
httpd-2.4.28.tar.gz #Apache主程序包
apr-1.5.2.tar.gz #Apache依賴包
apr-util-1.5.4.tar.gz #Apache依賴包
pcre-8.41.tar.gz #Apache依賴包

下載源碼安裝包
http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.28.tar.gz http://archive.apache.org/dist/apr/apr-1.6.2.tar.gz
http://archive.apache.org/dist/apr/apr-util-1.6.0.tar.gz
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.41.tar.gz
首先下載最新的源碼包
安裝之前請先安裝make、gcc、openssl等編譯工具和開發包
[root@localhost ~]# yum -y install make gcc gcc-c++ openssl openssl-devel expat-devel

安裝依賴包:apr-1.5.2.tar.gz
[root@localhost ~]# tar xf apr-1.5.2.tar.gz
[root@localhost ~]# cd apr-1.5.2
[root@localhost apr-1.5.2]# ./configure --prefix=/usr/local/apr && make && make install
編譯安裝依賴包apr-util-1.5.4.tar.gz
[root@localhost ~]# tar xf apr-util-1.5.4.tar.gz
[root@localhost ~]# cd apr-util-1.5.4

[root@localhost apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util/ --with-apr=/usr/local/apr/bin/apr-1-config && make && make install
編譯安裝依賴包pcre-8.41.tar.gz
[root@localhost pcre-8.41]# tar xf pcre-8.41.tar.gz
[root@localhost ~]# cd pcre-8.41
[root@localhost pcre-8.41]# ./configure --prefix=/usr/local/pcre && make && make install

編譯安裝apache
[root@localhost ~]# tar xf httpd-2.4.28.tar.gz -C /usr/local/src/
[root@localhost ~]# cd /usr/local/src/httpd-2.4.28/
[root@localhost httpd-2.4.28]# ./configure --prefix=/usr/local/apache --enable-so --enable-rewrite --enable-ssl --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre/ && make && make install
註:
--enable-so #支持動態加載模塊
--enable-rewrite #支持網站地址重寫
--enable-ssl #支持ssl加密
--with-apr=/usr/local/apr #關聯apr
--with-apr-util=/usr/local/apr-util #關聯apr-util
--with-pcre=/usr/local/pcre #關聯pcre
--libdir=/usr/lib64 #關聯庫文件
配置文件
[root@localhost httpd-2.4.28]# ls /usr/local/apache/conf/httpd.conf
/usr/local/apache/conf/httpd.conf
網站根目錄
[root@localhost httpd-2.4.28]# ls /usr/local/apache/htdocs/
index.html
生成啟動腳本
[root@localhost httpd-2.4.28]# cp /usr/local/apache/bin/apachectl /etc/init.d
[root@localhost httpd-2.4.28]# chmod +x /etc/init.d/apachectl

寫個apache系統服務腳本, 以754的權限保存此文件
[Unit]
Description=apache
After=network.target
[Service]
Type=forking
ExecStart=/etc/init.d/apachectl start
ExecReload=/etc/init.d/apachectl restart
ExecStop=/etc/init.d/apachectl stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target

啟動apache報錯:
[root@localhost httpd-2.4.28]# /etc/init.d/apachectl restart
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 httpd-2.4.28]# vim /usr/local/apache/conf/httpd.conf
改成:
ServerName 192.168.140.138(服務器IP):80

啟動apache
/etc/init.d/apachectl start

測試:
技術分享圖片

apache編譯安裝