编译安装apache

Apache从源码安装教程

首先注明下面的操作都是在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

http://callaly.net/blog/archives/94.html

http://hi.baidu.com/azazd666/item/5a4581f4160177df6225d26f

### 编译安装Apache HTTP服务器 #### 准备工作 为了成功编译安装Apache HTTP服务器,在Linux环境下需先确认已安装必要的依赖库。这些通常包括`gcc`, `make`, 和其他开发工具链组件。 #### 获取源代码 下载最新的Apache HTTP Server版本是非常重要的一步。可以从官方网站获取稳定版的压缩包文件,例如`httpd-2.4.x.tar.gz`这样的格式[^2]。 ```bash wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.4.39.tar.gz tar -zxf httpd-2.4.39.tar.gz cd httpd-2.4.39 ``` #### 安装依赖项 除了基本的构建工具外,还需要几个额外的支持库来增强Apache的功能,比如APR (Apache Portable Runtime), APR-util, 和 PCRE (Perl Compatible Regular Expressions) 库。对于某些发行版来说,可能已经预装了部分所需的库;如果没有,则可以通过包管理器或者手动编译的方式获得它们[^3]。 ##### 安装 apr ```bash # 使用系统自带仓库中的apr-devel包简化操作 sudo yum install apr-devel # 对于基于RedHat/CentOS系统的命令 # 或者 sudo apt-get install libapr1-dev # 针对Debian/Ubuntu类系统 ``` ##### 安装 apr-util 同样地,可以利用官方资源或本地镜像站点下载对应的`.tar.bz2`文件,并按照常规流程解压、配置、编译以及安装。 ##### 安装 pcre PCRE用于支持正则表达式的处理能力,这对于URL重写等功能至关重要。大多数现代Linux发行版都提供了现成的二进制包可以直接安装。 #### 编译 Apache 完成上述准备工作之后就可以正式开始编译Apache本身了: ```bash ./configure --prefix=/usr/local/apache2 \ --enable-so \ --enable-cgi \ --enable-rewrite \ --with-included-apr \ --enable-modules=most \ --enable-mods-shared=all make && sudo make install ``` 这段脚本指定了多个选项来自定义最终生成的服务端程序的行为模式及其性能特征。其中一些关键参数解释如下: - `--prefix`: 设置安装路径,默认情况下会放置到`/usr/local/apache2`目录内; - `--enable-*`: 启用特定模块或特性集; - `--with-included-apr`: 表明使用捆绑在一起发布的APR版本而非系统级实例。 #### 初始化设置与验证 一旦编译过程顺利完成,接下来就是调整初始配置文件(位于`conf/httpd.conf`) 并尝试启动新搭建起来的服务进程以检验一切是否正常运作。 ```bash /usr/local/apache2/bin/apachectl start curl localhost ``` 如果返回了一个标准HTML页面的内容片段,说明HTTP请求已经被正确接收和响应,表明整个安装过程达到了预期效果。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值