首先注明下面的操作都是在root下执行或者使用sudo命令。
1)去下载apache源码
2)解压到/usr/src,在下载目录执行tar-zxvfhttpd-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:APRnotfound。解决办法:
4.1)去apr下载地址下载源码
4.2)解压到/usr/src,在下载目录执行tar-zxvfapr-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;makeinstall
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-utilnotfound.解决办法
6.1)去apr-util下载地址下载源码
6.2)解压到/usr/src,在下载目录执行tar-zxvfapr-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;makeinstall
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-configforlibpcrenotfound.解决办法:
8.1)去pcre下载地址下载源码
8.2)解压到/usr/src,在下载目录执行tar-zxvfpcre-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;makeinstall
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:OpenSSLversionistooold;checkingwhethertoenablemod_ssl…configure:error:mod_sslhasbeenrequestedbutcannotbebuiltduetoprerequisitefailures;解决办法:
10.1)openssl源码下载地址下载源码
10.2)解压到/usr/src,在下载目录执行tar-zxvfopenssl-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;makeinstall
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;makeinstall;
成功执行。
12)启动apache,进入/usr/local/apache2/bin目录,执行命令sudo./httpd-kstop/start/restart或者sudoapachectlstart/stop/restart(apachectl是执行脚本)
13)设置httpd在任何目录下都可以运行,打开vim/etc/environment,增加配置/usr/local/apache2/bin
14)设置apache开机自动启动,,首先拷贝apachectl到目录/etc/init.d/,执行命令sudocpapachectl/etc/init.d/;然后执行sudoupdate-rc.dapachectldefaults
15)在root下执行apachectlstart/stop失败,报错:httpd:Couldnotreliablydeterminetheserver’sfullyqualifieddomainname。
自己选择的路,跪着也要把它走完。