您的位置:首页 > 运维架构 > Apache

Linux下编译安装apache

2014-11-15 20:39 387 查看
内容转载自:http://www.cnblogs.com/alexqdh/archive/2012/11/20/2764810.html

首先注明下面的操作都是在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了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: