首先註明下面的操作都是在root下執行或者使用sudo命令。
1)去http://httpd.apache.org/download 下載apache源碼
2)解壓到/usr/src,在下載目錄執行tar -zxvf httpd-x.x.x.tar.gz -C /usr/src (我用的是httpd-2.4.3.tar.gz)
3)進入目錄/usr/src/httpd-2.4.3,執行:./configure --prefix=/usr/local/apache2 --with-mpm=worker --enable-cache --enable-disk-cache --enable-mem-cache --enable-file-cache --enable-nonportable-atomics --enable-mods-shared=most --enable-so --enable-rewrite --enable-ssl
4)出現configure: error: APR not found。解決辦法:
4.1)去apr下載地址 http://apr.apache.org/ 下載源碼
4.2)解壓到/usr/src,在下載目錄執行tar -zxvf apr-x.x.x.tar.gz -C /usr/src/ (我用的是apr-1.4.6.tar.gz)
4.3)進入目錄/usr/src/apr-1.4.6,執行./configure --prefix=/usr/local/apr;make;make install
5)再次進入目錄/usr/src/httpd-2.4.3,增加參數--with-apr=/usr/local/apr/,重新執行:./configure --prefix=/usr/local/apache2 --with-mpm=worker --enable-cache --enable-disk-cache --enable-mem-cache --enable-file-cache --enable-nonportable-atomics --enable-mods-shared=most --enable-so --enable-rewrite --enable-ssl --with-apr=/usr/local/apr/
6)出現configure: error: APR-util not found .解決辦法
6.1)去apr-util下載地址 http://apr.apache.org/ 下載源碼
6.2)解壓到/usr/src,在下載目錄執行tar -zxvf apr-util-x.x.x.tar.gz -C /usr/src/ (我用的是apr-util-1.5.1.tar.gz)
6.3)進入目錄/usr/src/apr-util-1.5.1,執行./configure --prefix=/usr/local/apr-util;make;make install
7)再次進入目錄/usr/src/httpd-2.4.3,增加參數--with-apr-util=/usr/local/apr-util/,重新執行:./configure --prefix=/usr/local/apache2 --with-mpm=worker --enable-cache --enable-disk-cache --enable-mem-cache --enable-file-cache --enable-nonportable-atomics --enable-mods-shared=most --enable-so --enable-rewrite --enable-ssl --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/
8)出現configure: error: pcre-config for libpcre not found.解決辦法:
8.1)去pcre下載地址 http://pcre.org/ 下載源碼
8.2)解壓到/usr/src,在下載目錄執行tar -zxvf pcre-x.x.tar.gz -C /usr/src/ (我用的是pcre-8.31.tar.gz)
8.3)進入目錄/usr/src/pcre-8.31,執行./configure --prefix=/usr/local/pcre;make;make install
9)再次進入目錄/usr/src/httpd-2.4.3,增加參數--with-pcre=/usr/local/pcre,重新執行:./configure --prefix=/usr/local/apache2 --with-mpm=worker --enable-cache --enable-disk-cache --enable-mem-cache --enable-file-cache --enable-nonportable-atomics --enable-mods-shared=most --enable-so --enable-rewrite --enable-ssl --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre
10)出現configure: WARNING: OpenSSL version is too old;checking whether to enable mod_ssl... configure: error: mod_ssl has been requested but can not be built due to prerequisite failures;解決辦法:
10.1)openssl源碼下載地址http://www.openssl.org/source/ 下載源碼
10.2)解壓到/usr/src,在下載目錄執行tar -zxvf openssl-x.x.x.tar.gz -C /usr/src/ (我用的是openssl-1.0.1c.tar.gz)
10.3)進入目錄/usr/src/openssl-1.0.1c,執行./config --prefix=/usr/local/openssl;make;make install
11)再次進入目錄/usr/src/httpd-2.4.3,增加參數--with-ssl=/usr/local/openssl,重新執行:./configure --prefix=/usr/local/apache2 --with-mpm=worker --enable-cache --enable-disk-cache --enable-mem-cache --enable-file-cache --enable-nonportable-atomics --enable-mods-shared=most --enable-so --enable-rewrite --enable-ssl --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre --with-ssl=/usr/local/openssl ;make ;make install;
成功執行。
12)啓動apache,進入/usr/local/apache2/bin目錄,執行命令sudo ./httpd -k stop/start/restart 或者 sudo apachectl start/stop/restart(apachectl是執行腳本)
13)設置httpd在任何目錄下都可以運行,打開vim /etc/environment,增加配置/usr/local/apache2/bin
14)設置apache開機自動啓動,首先拷貝apachectl到目錄/etc/init.d/,執行命令sudo cp apachectl /etc/init.d/ ;然後執行sudo update-rc.d apachectl defaults
15) 在root下執行apachectl start/stop失敗,報錯:httpd: Could not reliably determine the server's fully qualified domain name。
解決辦法:(1)進入apache的安裝目錄:(視個人安裝情況而不同) [root@server ~]# cd /usr/local/apache/conf
(2)編輯httpd.conf文件,搜索"#ServerName",添加ServerName localhost:80
(3)重新啓動apache 即可。執行apachectl restart
16)遇到報錯:Permission denied: make_sock: could not bind to address 0.0.0.0:80
網上搜到的解決辦法如下:
httpd文件的權限必須是4755並且歸屬root用戶…..簡單的說,s能讓普通用戶作爲文件屬主/組運行,因爲有些程序只有文件屬主/組才能運行的,如 /usr/bin/ping,ping命令只能由 root運行,爲了讓普通用戶也能運行,就必須加上s位,你可試驗一下:
先去除s:chmod 755 ping
用普通用戶運行ping,你會發現權限不足。
加上s:chmod 4755 ping
再運行就正常了。
ps:對shell腳本設置無效!只對應用程序有效!
17)去瀏覽器輸入127.0.0.1,可以顯示apache自帶的網頁It works。該網頁的默認目錄是在/usr/local/apache2/htdocs/。apache到此就安裝OK了。
參考網址:
http://www.cnblogs.com/huzhiwei/archive/2012/07/19/2599854.html
http://johnly.blog.51cto.com/742359/152153
http://1556359.blog.51cto.com/1546359/513833