Linux系统服务器上安装Apache

时间:2024-04-02 12:03:45

一、首先下载安装Apache需要的依赖包

APR、APR-Util、PCRE,gcc-c++、gcc

APR下载地址:http://apr.apache.org/download.cgi

APR-Util下载地址:http://apr.apache.org/download.cgi

PCRE下载地址:https://sourceforge.net/projects/pcre/files/pcre/

HTTPD下载地址:http://httpd.apache.org/download.cgi

在linux上操作  通过#wget  下载地址  下载安装包到linux上

下载APR:

#wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.5.2.tar.gz

下载APR-Util:

#wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.5.4.tar.gz

下载PCRE:

#wget  ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.41.tar.gz

下载HTTPD:

#wget http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.27.tar.gz

下载并解压之后就如图所示:

Linux系统服务器上安装Apache

二、Apache安装步骤

第一步:先查看一下是否存在gcc、gcc-c++

Linux系统服务器上安装Apache

如果已经存在就可以不用安装了,不存在再安装

[[email protected] lamp]# yum install  gcc-c++

[[email protected] lamp]# yum install  gcc

第二步:安装包APR和APR-Util

1、安装Apr

因为刚开始已经将压缩包解压,所以直接进入apr文件(--prefix=/usr/local/apr这是在指定软件安装的目录,若该文件不存在,会自动生成apr空文件夹)

[[email protected] lamp]# cd apr-1.5.2

[[email protected] apr-1.5.2]# ./configure --prefix=/usr/local/apr

Linux系统服务器上安装Apache

[[email protected] apr-1.5.2]# make

[[email protected] apr-1.5.2]# make install

Linux系统服务器上安装Apache

这样表示Apr已经好了。

2、安装Apr-util

同理,apr-util压缩包已经解压好了,直接进入文件中

[[email protected] lamp]# cd apr-util-1.5.4

[[email protected] apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config

Linux系统服务器上安装Apache

[r[email protected] apr-util-1.5.4]# make

[[email protected] apr-util-1.5.4]# make install

Linux系统服务器上安装Apache

这样apr-util安装好了

第三步:安装PRCE

同样pcre安装包已经解压好了

[[email protected] lamp]# cd pcre-8.41

[[email protected] pcre-8.41]# ./configure --prefix=/usr/local/pcre-8.41

Linux系统服务器上安装Apache

[[email protected] pcre-8.41]# make

[[email protected] pcre-8.41]# make install

Linux系统服务器上安装Apache

出现这样就已经安装好了

第四步:安装HTTPD

[[email protected] lamp]# cd httpd-2.4.27

[[email protected]i43o69css0svslZ httpd-2.4.27]#  ./configure --prefix=/usr/local/apache --with-pcre=/usr/local/pcre-8.41 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util

[[email protected] httpd-2.4.27]# make

[[email protected] httpd-2.4.27]# make install

安装完成

第五步:启动Aapache

[[email protected] httpd-2.4.27]# /usr/local/apache/bin/apachectl start

第六步:访问Apache

在浏览器上输入ip访问出现如图所示,表示Apache安装成功。

Linux系统服务器上安装Apache


Apache安装问题锦集

问题1:缺少包gcc-c++导致安装包apr-util不通过

Linux系统服务器上安装Apache

一般出现这个错误是因为没有安装包gcc-c++,只要安装即可,安装步骤如步骤一所示。

问题2:checking for APR-util... configure: error: the --with-apr-util parameter is incorrect

[[email protected] httpd-2.4.27]#  ./configure --prefix=/usr/local/apache  --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
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
configure:
configure: Configuring Apache Portable Runtime library...
configure:
checking for APR... yes
  setting CC to "gcc"
  setting CPP to "gcc -E"
  setting CFLAGS to " -g -O2 -pthread"
  setting CPPFLAGS to " -DLINUX -D_REENTRANT -D_GNU_SOURCE"
  setting LDFLAGS to " "
configure:
configure: Configuring Apache Portable Runtime Utility library...
configure:
checking for APR-util... configure: error: the --with-apr-util parameter is incorrect. It must specify an install prefix, a build directory, or an apu-config file.

一般是由于APR-util没有安装成功,可以通过验证该目录是否为空来判断,因为你有时候执行了make,忘了执行make isntall命令有可能导致这个错误。

问题3:没有指定PCRE参数

[[email protected] httpd-2.4.27]#  ./configure --prefix=/usr/local/apache  --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
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
configure:
configure: Configuring Apache Portable Runtime library...
configure:
checking for APR... yes
  setting CC to "gcc"
  setting CPP to "gcc -E"
  setting CFLAGS to " -g -O2 -pthread"
  setting CPPFLAGS to " -DLINUX -D_REENTRANT -D_GNU_SOURCE"
  setting LDFLAGS to " "
configure:
configure: Configuring Apache Portable Runtime Utility library...
configure:
checking for APR-util... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for gcc option to accept ISO C99... -std=gnu99
checking for pcre-config... false
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

问题4:安装前忘了先安装APR相关包
[[email protected] httpd-2.4.27]#  ./configure --prefix=/usr/local/appache/
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
configure:
configure: Configuring Apache Portable Runtime library...
configure:
checking for APR... no
configure: error: APR not found.  Please read the documentation.

问题5:启动服务时报错
[[email protected] httpd-2.4.27]#  /usr/local/apache/bin/apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using iZ2ze5cti43o69css0svslZ  .gfg1.esquel.com. Set the 'ServerName' directive globally to suppress this message
这个时候需要编辑httpd.conf配置文件,添加SeraverName的具体IP地址。如下所示
[[email protected]  conf]# cd /usr/local/apache/conf/
[[email protected]  conf]# ls
extra  httpd.conf  magic  mime.types  original
[[email protected]  conf]# vi httpd.conf
ServerAdmin [email protected]
#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
#ServerName www.example.com:80
ServerName 192.168.9.122:80
#
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other

# <Directory> blocks below.

#
"httpd.conf" 502L, 18179C written

[[email protected]  conf]# /usr/local/apache/bin/apachectl restart

httpd not running, trying to start

[[email protected]  conf]# /usr/local/apache/bin/apachectl start
httpd (pid 7797) already running

如果从其它电脑连接访问Apache时,输入url地址例如:http://192.168.9.122页面没有显示正常,而上面配置也OK,那么你必须关闭防火墙,有时候甚至需要重启电脑才能OK,重启Apache服务都无效。
[[email protected]  conf]# chkconfig iptables off
[[email protected]  conf]# chkconfig iptables off
[[email protected]  conf]# /usr/local/apache/bin/apachectl restart
[[email protected]  conf]# /usr/local/apache/bin/apachectl restart

注:用的是阿里云的服务器的话需要在网络与安全下的安全组中添加80端口

Linux系统服务器上安装Apache