Apache httpd的设置和安装

83

我正在尝试以普通用户(非root)的身份在我的计算机上本地安装Apache HTTP服务器。

我已经下载了Apache HTTP服务器的2.4.1版本[http://httpd.apache.org/download.cgi]。但是当我尝试在我的计算机上构建和安装时,我遇到以下错误:

httpd/httpd-2.4.1 1059> ./configure
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu

Configuring Apache Portable Runtime library ...

checking for APR... no
configure: error: APR not found.  Please read the documentation.

我不确定它正在寻找什么依赖项 - 我的意思是下载包中没有包含它?我需要做什么来构建/部署Apache HTTP服务器?


1
@JimGarrison,那为什么它没有被关闭/移动? - Pacerier
9个回答

132
当出现“请阅读文档”时,它意味着您应该去阅读Apache文档(http://httpd.apache.org/docs/2.4/install.html),其中告诉您要下载最新版本的APR和APR-Util从Apache APR,将它们解压到./srclib/apr和./srclib/apr-util中(确保域名没有版本号;例如,APR发行版必须在./srclib/apr/下),然后执行。
./configure --with-included-apr

3
甜美的成功..需要在Makefile中更改行:#PROGRAM_LDADD = buildmark.o $(HTTPD_LDFLAGS) $(PROGRAM_DEPENDENCIES) $(PCRE_LIBS) $(EXTRA_LIBS) $(AP_LIBS) $(LIBS) ----> PROGRAM_LDADD = buildmark.o $(HTTPD_LDFLAGS) $(PROGRAM_DEPENDENCIES) $HOME/lib/usr/local/lib/libpcre.a $(EXTRA_LIBS) $(AP_LIBS) $(LIBS)。 - Programmer
8
注意 ./srclib 表示你的 httpd-xxx 目录内的 srclib 文件夹。 - HaoQi Li
24
为什么他们不直接为您包括那个呢?这似乎是浪费时间。 - David Williams
1
在安装Apache时,是否将apr和apr-util作为独立软件包单独安装,而不是仅将它们的源代码包含在Apache中,这样做有什么好处吗? - Zeeshan
虽然这是旧的,但根据http://httpd.apache.org/docs/2.4/programs/configure.html#installationdirectories的说法:Apache Portable Runtime(APR)是httpd源代码分发的一部分,并将与HTTP服务器一起自动构建。如果您想使用已安装的APR,则必须告诉configure apr-config脚本的路径。您可以设置已安装APR的绝对路径和名称或目录。apr-config必须存在于此目录或子目录bin中。 - foszter
显示剩余9条评论

40

对于Ubuntu 11.10,这个选项似乎运行良好:

 # APR

wget http://mirrors.axint.net/apache//apr/apr-1.4.6.tar.gz

tar -xvzf apr-1.4.6.tar.gz

cd apr-1.4.6/

./configure

make

make install

cd ..

# APR Utils

wget http://mirrors.axint.net/apache//apr/apr-util-1.4.1.tar.gz

tar -xvzf apr-util-1.4.1.tar.gz

cd apr-util-1.4.1

./configure --with-apr=/usr/local/apr

make

make install

cd ..

# Apache

wget http://apache.petsads.us//httpd/httpd-2.4.1.tar.gz

tar -xvzf httpd-2.4.1.tar.gz

cd httpd-2.4.1

./configure --enable-file-cache --enable-cache --enable-disk-cache --enable-mem-cache --enable-deflate --enable-expires --enable-headers --enable-usertrack --enable-ssl --enable-cgi --enable-vhost-alias --enable-rewrite --enable-so --with-apr=/usr/local/apr/

make

make install

cd ..

以下是更多相关信息:

来源:VaporCreations.com


除非您是root用户,否则您需要在“make install”调用上加前缀“sudo”。 - Paul Gregoire
谢谢。我漏掉了一些参数来运行./configure。 - Sean the Bean
在 Red Hat Enterprise Linux Server release 7.4 (Maipo) 上执行 make install 后,如何启动 httpd 服务? - Chaminda Bandara

28

如果你使用的是Debian/Ubuntu,只需执行以下操作:

apt-get install libapr1-dev libaprutil1-dev

然后运行./configure

完成


这对于Ubuntu用户很有帮助。 - haidarvm

21

以下是我在非root用户上安装apache-httpd的步骤:

  1. 下载并解压apache-httpd-2.4.2(但在进行./configure、make和安装之前,请遵循以下步骤:)
  2. 下载并解压APR和APR-UTIL到"./srclib/apr"和"./srclib/apr-util"文件夹中。这需要./configure --with-apr=./apache/httpd-2.4.2/srclib/apr(和)--with-included-apr(选项)。
  3. 下载、解压、./configure(带)--prefix=localURL,然后进行make和make install PCRE到"./pcre"文件夹中。这需要./configure --with-pcre=/home/username/apache/pcre(选项)。
  4. 通过输入以下命令来配置apache-httpd(我喜欢启用如下命令中写的特定选项): ./configure --enable-file-cache --enable-cache --enable-disk-cache --enable-mem-cache --enable-deflate --enable-expires --enable-headers --enable-usertrack --enable-cgi --enable-vhost-alias --enable-rewrite --enable-so --with-apr=/home/username/apache/httpd-2.4.2/srclib/apr --prefix=/home/username/apache/httpd-2.4.2/ --with-included-apr --with-pcre=/home/username/apache/pcre 注意:在配置apache-httpd时,仅当安装了OpenSSL时才使用选项"--enable-ssl",否则不要启用它。
  5. 现在在命令行中输入'make'和'make install'命令。
  6. 打开并配置'httpd.conf'文件,例如: "vi /home/eddie_kumar/apache/httpd-2.4.2/conf/httpd.conf"

重要提示:不要忘记将默认端口从80更改为其他端口,例如8080,这对于非root用户尤其重要。(如何操作?打开httpd.conf -> 搜索"Listen 80" -> 将其更改为"Listen 8080"。)

就这样,现在打开您的浏览器,输入“localhost:8080”,它应该显示“运行正常!”。


如果您是Debian用户,只需执行“apt-get install libpcre3-dev”即可。 - Reza S
在 Red Hat Enterprise Linux Server release 7.4 (Maipo) 上执行 make install 后,如何启动 httpd 服务? - Chaminda Bandara

3
如果您使用的是 Fedora 操作系统,可以使用 yum 命令来安装 APR、APR-Util 和 PCRE。您还需要下载 apr-devel、apr-util-devel 和 pcre-devel。
话虽如此,您只需在终端运行以下命令即可,就不会再出现 "configure: error: APR not found.. ..APR-Util and PCRE" 的错误提示了。
yum -y install arp apr-devel apr-util apr-util-devel pcre pcre-devel 

我正在使用 Fedora 17,并计划使用一个 shell 脚本来设置 Apache 2.4.3。因此,yum 相当顺畅,而不需要手动下载 apr、apr-util 和 pcre。

太棒了!不清楚你是否需要-devel版本。如果你使用的是Fedora或Redhat,或者是一个运行Redhat的Amazon EC2 AWS实例,那么这就是最好的答案。 - srock

1
1、你需要APR(apache portable runtime),这是apache web服务器的核心组件。
2、如果你想进行make install操作,可能需要root账户。
3、即使不需要root账户,apache也无法在非特权端口(小于1024)上启动监听。
4、获取root权限或者请有root权限的人从官方仓库安装apache(我不知道你使用的发行版),可以使用yum、apt-get等命令。

0

与Apr或pcre相关的错误需要下载源代码,并使Apache HTTPD“configure”进程了解您文件系统上这些源代码的位置。例如:如果您在./srclib(相对于apache httpd)下载了APR的源代码,则应使用
--with-included-apr
作为配置选项。

另一方面,如果您想要安装而不是构建APR / APR-UTIL,则需要在CentOS / RedHat上安装以下内容:
yum install apr-util-devel apr-devel
但是,可能发生yum提供的APR版本与此版本的Apache httpd所期望的版本不匹配。在这种情况下,您可以下载APR和APR-UTIL并使用--with-included-apr选项。

您还可以利用相同的“configure,make,make install”过程构建PCRE,然后继续构建Apache httpd。
或者您可以安装pcre: yum install pcre-devel

如果在构建PCRE时出现“编译:无法识别的选项”,那么您可能还需要其他依赖项:请参阅以下详细信息:
http://khanna111.com/wordPressBlog/2012/09/11/94087-2/
它还涵盖了“mod_deflate”和“zlib”。

0

基本步骤

tar -xvf httpd-2.4.1-customized.tar -C ../
#Balancer folder will be created
tar -xvzf openssl-1.0.1.tar.gz  -C /balancer/
cd ->/balancer/openssl-1.0.1
./config --prefix=/usr/local/ssl/ shared zlib-dynamic enable-camellia
make depend
make
make install
tar -xvzf pcre-8.30.tar.gz -C ../balancer/

/balancer/pcre-8.30
./configure  --prefix=/usr/local/pcre/
make
make install

移除 PCRE 和 OpenSSL


0

在Ubuntu机器上安装和编译Apache服务器

步骤1:安装Java JDK

sudo apt install openjdk-11-jdk

sudo gedit /etc/environment

JAVA_HOME="/usr/lib/jvm/openjdk-11"

source /etc/environment

echo $JAVA_HOME

验证Java版本

javac --version

**** 安装其他必需的软件包:**

  sudo apt-get install apache2-dev -y 

sudo apt-get install libpcre3 libpcre3-dev

步骤2:安装Apache HTTP服务器

#1 对于Ubuntu,安装包括C编译器在内的开发工具:

sudo apt-get install build-essential checkinstall

#2 下载并提取所需文件

假设所有文件都已下载到 ~/Downloads 目录中

从 Apache 下载页面 (https://httpd.apache.org/download.cgi) 下载 Apache HTTP Server httpd-2.4.41.tar.gz

以及编译 Apache HTTP 服务器所需的以下库:

****阅读要求部分(http://httpd.apache.org/docs/2.4/install.html)***

#3 提取tar文件

  • tar -xvf httpd-2.4.41.tar.gz
  • tar -xvf apr-1.7.0.tar.gz
  • tar -xvf apr-util-1.6.1.tar.gz
  • tar -xvf pcre2-10.34.tar.gz

提取后,您应该在~/Downloads目录下看到以下目录列表

  • httpd-2.4.41
  • apr-1.7.0
  • apr-util-1.6.1
  • pcre2-10.34

#4 创建一个Apache HTTP服务器的目录

*确保给予该目录所有权限,以便在编译文件时可以读取/写入

 sudo mkdir /home{your username here}/apache

给予一个 Apache 目录所有权限:
sudo chmod -R 777 /home{your username here}/apache

#5 将 arp 和 arp-util 目录复制到 ~/Downloads/httpd-2.4.41/srclib/ 中

cd ~/Downloads

mv  apr-util-1.6.1  ~/Downloads/httpd-2.4.41/srclib/apr-util

 mv  apr-1.7.0  ~/Downloads/httpd-2.4.41/srclib/apr

#6 配置编译源。 --prefix选项可用于将Web服务器安装在您可以编写文件的位置。

cd ~/Downloads/httpd-2.4.41/


./configure  --prefix=/home/{username here}/apache --with-pcre=~/Downloads/pcre2-10.34

注意: 如果您在运行上述命令时遇到问题,您也可以尝试在 /usr/local/pcre 中安装 pcre,使用以下命令:

./configure --prefix=/usr/local/pcre make sudo make install

然后通过运行以下命令来解决问题:

   cd ~/Downloads/httpd-2.4.41/

./configure --prefix=/home/{在此处输入用户名}/apache --with-pcre=/usr/local/pcre

make

  sudo make install

如果您仍然遇到一些问题,请确保~/apache及其嵌套目录具有读/写权限。如果没有,请再次运行sudo chmod -R 777 /home{您的用户名}/apache命令。

#7 编译Apache HTTP服务器。

cd ~/Downloads/httpd-2.2.25

sudo make

#8 安装 Apache HTTP 服务器。

cd ~/Downloads/httpd-2.2.25

sudo make install

可选项 #9 准备您的 Hosts 文件

sudo gedit /etc/hosts

27.0.0.1 localhost www.example.com

sudo gedit /home/{your username here}/apache/conf/httpd.conf

并复制:

Listen 8000

ServerName www.example.com:8000

#10 测试安装以确保 Apache HTTP 服务器正常工作。

/home/{your username here}//apache/bin/apachectl -k start

#./apachectl -k start httpd:/usr/local/apache/conf/httpd.conf的第66行语法错误:无法将modules/mod_authn_file.so模块加载到服务器中:/usr/local/apache/modules/mod_authn_file.so:无法打开共享对象文件:没有那个文件或目录。 - yanzhang.guo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接