linux怎么安装apache服务器

压缩包安装方式

1、下载httpd-2.4.29.tar.gz

2、上传到服务器/usr/local/software

1

2

tar -zxvf httpd-2.4.29.tar.gz

./configure --prefix=/usr/local/apache2/ # 设置apache安装目录

若没有安装过Apr,会报错:

1

2

checking for APR... no

configure: error: APR not found.  Please read the documentation.

3、接下来安装apr,首先下载apr-1.6.3.tar.gz

4、上传到服务器/usr/local/software

1

2

3

4

5

tar -zxvf apr-1.6.3.tar.gz

cd apr-1.6.3

.configure

make

make install

又会报错:

1

2

checking for APR-util... no

configure: error: APR-util not found.  Please read the documentation.

5、下载apr-util-1.6.1.tar.gz

6、上传到服务器/usr/local/software

1

2

3

tar -zxvf apr-util-1.6.1.tar.gz

cd apr-util-1.6.1

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

此时还会报错:

1

2

3

4

5

xml/apr_xml.c:35:19: 致命错误:expat.h:没有那个文件或目录

 #include

                   ^

编译中断。

make: *** [xml/apr_xml.lo] 错误 1

7、猜测是可能缺expat的开发库

1

2

3

4

yum install expat-devel # 中间会让你输入y

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

make # 成功!

make install

8、此时再回去安装apache,不仅要指定apr的路径,还要指定apr-util的路径

1

./configure --prefix=/usr/local/apache2/  --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/

依旧报错,不少人到这里可能已经崩溃了,但这个错误跟前面遇到的类似

1

2

checking for pcre-config... false

configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

9、下载pcre-8.41.tar.gz

10、上传到服务器/usr/local/software

1

2

tar -zxvf pcre-8.41.tar.gz

./configure

又再次报错,我保证这是最后一次了

1

2

3

4

checking windows.h usability... no

checking windows.h presence... no

checking for windows.h... no

configure: error: You need a C++ compiler for C++ support.

10、安装c++环境

1

2

3

4

5

yum install -y gcc gcc-c++

# 错了那么多次,别忘了现在的位置,接下来还是要安装pcre

./configure

make

make install

11、好了,绕了一大圈,接下来还是要安装apache

1

2

3

4

5

cd ..

cd apache

./configure --prefix=/usr/local/apache2/  --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/

make

make install

好惨啊!最后一步又报错:

1

2

3

4

5

6

7

8

/usr/local/apr-util//lib/libaprutil-1.so: undefined reference to `XML_GetErrorCode' 

/usr/local/apr-util//lib/libaprutil-1.so: undefined reference to `XML_SetEntityDeclHandler' 

/usr/local/apr-util//lib/libaprutil-1.so: undefined reference to `XML_ParserCre

collect2: error: ld returned 1 exit status

make[2]: *** [htpasswd] 错误 1

make[2]: Leaving directory `/usr/local/software/apache/support'

make[1]: *** [all-recursive] 错误 1

make[1]: Leaving directory `/usr/local/software/apache/support'

这种报错没见过,果断网上搜索一番,答案即是:apr版本太高;

12、于是我下载了apr-util-1.5 http://archive.apache.org/dist/apr/apr-util-1.5.2.tar.gz

13、上传到服务器/usr/local/software

1

2

3

4

5

tar -zxvf apr-util-1.5.2.tar.gz

cd apr-util-1.5.2

./configure --prefix=/usr/local/apr-util-1.5/ --with-apr=/usr/local/apr

make

make install

14、重复步骤11,唯一不同的地方就是现在配置指定的是:apr-util-1.5,这很重要!!!

1

2

3

4

5

cd ..

cd apache

./configure --prefix=/usr/local/apache2/  --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util-1.5/

make # make时间会比较长

make install

完美结尾:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

Installing configuration files

mkdir /usr/local/apache2/conf

mkdir /usr/local/apache2/conf/extra

mkdir /usr/local/apache2/conf/original

mkdir /usr/local/apache2/conf/original/extra

Installing HTML documents

mkdir /usr/local/apache2/htdocs

Installing error documents

mkdir /usr/local/apache2/error

Installing icons

mkdir /usr/local/apache2/icons

mkdir /usr/local/apache2/logs

Installing CGIs

mkdir /usr/local/apache2/cgi-bin

Installing header files

mkdir /usr/local/apache2/include

Installing build system files

mkdir /usr/local/apache2/build

Installing man pages and online manual

mkdir /usr/local/apache2/man

mkdir /usr/local/apache2/man/man1

mkdir /usr/local/apache2/man/man8

mkdir /usr/local/apache2/manual

make[1]: Leaving directory `/usr/local/software/apache'

15、进入配置文件位置:/usr/local/apache2/conf

1

2

3

4

5

cp httpd.conf httpd.conf.bak    # 备份配置文件

vim httpd.conf

# 放掉191行的注释,修改为:

ServerName [你的IP]:80

:wq

16、启动apache

1

2

3

/usr/local/apache2/bin/apachectl start

# 或者

/usr/local/apache2//bin/httpd -k start

关闭防火墙,在浏览器地址栏中输入服务器的ip就会出现网页:It works!

17、关闭apache

1

2

3

4

5

ps -ef|grep apache

/usr/local/apache2/bin/apachectl stop

# 或者

/usr/local/apache2//bin/httpd -k stop

# 没错,bin前面就是//

这种原文件安装的方式太过复杂,其实安装apache服务还有另一种方式,不知道跟我前面这种安装有没有冲突,今天也一并试一试。

yum源安装方式

1、yum源安装(需要联网下载)

1

2

首先关闭apache服务

yum install httpd # 中间过程中输入:y

Result:

作为依赖被安装:

1

2

3

4

5

  apr.x86_64 0:1.4.8-3.el7_4.1     

  apr-util.x86_64 0:1.5.2-6.el7       

  httpd-tools.x86_64 0:2.4.6-67.el7.centos.6     

  mailcap.noarch 0:2.1.41-2.el7       

完毕!

2、yum的安装位置在:/etc/httpd/conf,我进入后备份配置文件先,修改的地方跟之前不一样,在95行,仅供参考

1

2

3

4

5

cd /etc/httpd/conf

cp httpd.conf httpd.conf.bak

# 放掉95行的注释,修改为:

ServerName [你的IP]:80

:wq

3、启动服务

1

systemctl start httpd.service

在浏览器输入ip,出现apache预置的html,完美!!!

4、关闭服务

1

systemctl stop httpd.service

5、我再次去启动第一种方式安装的httpd

1

/usr/local/apache2/bin/apachectl start

刷新浏览器赫然出现:It works!,说明两种安装方式没有冲突哈。

posted on 2020-11-30 01:01  卖小女孩的小男孩  阅读(253)  评论(0)    收藏  举报