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

Linux系统服务器上安装Apache

2017-07-25 15:51 309 查看
一、首先下载安装Apache需要的依赖包

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

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

APR-Util下载地址:http:/
4000
/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

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



二、Apache安装步骤

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



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

[root@iZ2ze5cti43o69css0svslZ lamp]# yum install  gcc-c++

[root@iZ2ze5cti43o69css0svslZ lamp]# yum install  gcc

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

1、安装Apr

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

[root@iZ2ze5cti43o69css0svslZ lamp]# cd apr-1.5.2

[root@iZ2ze5cti43o69css0svslZ apr-1.5.2]# ./configure --prefix=/usr/local/apr



[root@iZ2ze5cti43o69css0svslZ apr-1.5.2]# make

[root@iZ2ze5cti43o69css0svslZ apr-1.5.2]# make install



这样表示Apr已经好了。

2、安装Apr-util

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

[root@iZ2ze5cti43o69css0svslZ lamp]# cd apr-util-1.5.4

[root@iZ2ze5cti43o69css0svslZ apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config



[root@iZ2ze5cti43o69css0svslZ apr-util-1.5.4]# make

[root@iZ2ze5cti43o69css0svslZ apr-util-1.5.4]# make install



这样apr-util安装好了

第三步:安装PRCE

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

[root@iZ2ze5cti43o69css0svslZ lamp]# cd pcre-8.41

[root@iZ2ze5cti43o69css0svslZ pcre-8.41]# ./configure --prefix=/usr/local/pcre-8.41



[root@iZ2ze5cti43o69css0svslZ pcre-8.41]# make

[root@iZ2ze5cti43o69css0svslZ pcre-8.41]# make install



出现这样就已经安装好了

第四步:安装HTTPD

[root@iZ2ze5cti43o69css0svslZ lamp]# cd httpd-2.4.27

[root@iZ2ze5cti43o69css0svslZ 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

[root@iZ2ze5cti43o69css0svslZ httpd-2.4.27]# make

[root@iZ2ze5cti43o69css0svslZ httpd-2.4.27]# make install

安装完成

第五步:启动Aapache

[root@iZ2ze5cti43o69css0svslZ httpd-2.4.27]# /usr/local/apache/bin/apachectl start

第六步:访问Apache

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



Apache安装问题锦集

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



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

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

[root@iZ2ze5cti43o69css0svslZ 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参数

[root@iZ2ze5cti43o69css0svslZ 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相关包
[root@iZ2ze5cti43o69css0svslZ 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:启动服务时报错

[root@iZ2ze5cti43o69css0svslZ 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地址。如下所示

[root@iZ2ze5cti43o69css0svslZ  conf]# cd /usr/local/apache/conf/

[root@iZ2ze5cti43o69css0svslZ  conf]# ls

extra  httpd.conf  magic  mime.types  original

[root@iZ2ze5cti43o69css0svslZ  conf]# vi httpd.conf

ServerAdmin you@example.com

#

# 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

[root@iZ2ze5cti43o69css0svslZ  conf]# /usr/local/apache/bin/apachectl restart

httpd not running, trying to start

[root@iZ2ze5cti43o69css0svslZ  conf]# /usr/local/apache/bin/apachectl start

httpd (pid 7797) already running

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

[root@iZ2ze5cti43o69css0svslZ  conf]# chkconfig iptables off

[root@iZ2ze5cti43o69css0svslZ  conf]# chkconfig iptables off

[root@iZ2ze5cti43o69css0svslZ  conf]# /usr/local/apache/bin/apachectl restart

[root@iZ2ze5cti43o69css0svslZ  conf]# /usr/local/apache/bin/apachectl restart

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

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: