Ubuntu 16.04源码编译安装Apache 2.4.25

来源:互联网 发布:淘宝怎么好评改差评 编辑:程序博客网 时间:2024/06/05 17:51

apache 安装指南:http://httpd.apache.org/docs/2.4/install.html

安装指南上面有详细的安装过程,这里我只说些注意事项:
1.编译安装apache有些依赖环境必须安装,不然后面编译会报找不到相应多文件:

  • APR(Apache portable Run-time libraries,Apache可移植运行库)和APR-Util,apr介绍可以参见:http://www.cnblogs.com/iLumia/p/4214886.html 下载地址:http://apr.apache.org/

  • PCRE库 如果没有安装过pcre的话,请先下载:https://sourceforge.net/projects/pcre/files/pcre/8.39/pcre-8.39.tar.gz/download
    除此之外,还有些磁盘空间要求,C编译器,时间同步,Perl5 可以根据需要,自行调整即可。

2.接下来是详细安装步骤:
这里我习惯把源码放在/usr/local/src下面,根据自己习惯切换目录。

  • 1.安装apr-1.5.2

切换到apr的源码目录

  cd /usr/local/src/apr-1.5.2/

安装及编译

./configure --prefix=/usr/local/apache/aprmake -j4(根据自己电脑核数×2来设定并行编译参数,提高编译速度)sudo make install
  • 2.安装apr-util-1.5.4

切换到apr-util的源码目录

cd /usr/local/src/apr-util-1.5.4/

安装及编译

./configure --prefix=/usr/local/apache/apr-util --with-apr=/usr/local/apache/aprmake -j4make install

3.安装pcre-8.39
进入安装目录

cd /usr/local/src/pcre-8.39/

安装及编译

./configure --prefix=/usr/local/pcremake -j4make install

4.安装完依赖就可以安装apache了
进入apache源码目录

cd /usr/local/src/httpd-2.4.25/

安装及编译

需要用–with参数指定我们刚才安装的依赖包位置

./configure --prefix=/usr/local/apache --with-apr=/usr/local/apache/apr --with-apr-util=/usr/local/apache/apr-util/ --with-pcre=/usr/local/pcremake -j4 make install

到此,就完成了apache的源码安装,接下来我们为apache服务
添加启动脚本:

cp /usr/local/apache/bin/apachectl /etc/init.d/httpd

添加环境变量:

echo 'export PATH=$PATH:/usr/local/apache/bin' > /etc/profile.d/httpd.shchmod a+x /etc/profile.d/httpd.shsource /etc/profile.d/httpd.sh

之后就可以多种方式管理httpd了,如果需要开机自启,将启动命令添加到/etc/rc.local 中即可。

sudo /usr/local/apache/bin/apachectl start

可能会报错说端口被占用,需要修改httpd.conf文件

sudo gedit /usr/local/apache/conf/httpd.conf

然后把ServerName行改成ServerName 127.0.0.1:80

把Listen 80行改成Listen 127.0.0.1:80

然后保存,启动apache服务.

service httpd start

注意:
如果启动服务时,报配置文件找不到,一种方法是,复制一份配置文件到相应路径,
或者你启动apache时,加-f 参数,指明配置文件绝对路径。

1 0
原创粉丝点击