title: Linux下Apache服务器的安装与配置
date: 2019-04-07 20:39:17
categories:
- Linux
tags: - Apache
安装
在linux
中,Apache
服务器叫做httpd
。
准备
首先下载httpd
与httpd
的依赖软件。
-
Apache HTTP Server
-
APR和APR-Util
-
PCRE
没有gcc/gcc-c++
的话,先安装gcc/gcc-c++
[root@localhost /]# yum install gcc-c++
基于centos,其余系统相应变化。
先确定服务器是否联网,若安装过程出现错误,可能是缺某些依赖包,谷歌百度下,会有结果的。
安装
解压
tar -zxf apr-1.6.5.tar.gz
tar -zxf apr-util-1.6.1.tar.gz
tar -zxf pcre-8.38.tar.gz
tar -zxf httpd-2.4.37.tar.gz
默认解压到当前目录
安装
直接复制粘贴,修改成刚刚解压的相应目录。
- apr的安装
cd apr-1.6.5
./configure --prefix=/home/apr-1.6.5
make
make install
- apr-util的安装
cd ../apr-util-1.6.1
./configure --prefix=/home/apr-util --with-apr=/home/apr-1.6.5/bin/apr-1-config
make
make install
- pcre的安装
cd ../pcre-8.38
./configure --prefix=/home/pcre-8.38 --with-apr=/home/apr-1.6.5/bin/apr-1-config
make
make install
- httpd的安装
cd ../httpd-2.4.18
./configure --prefix=/home/httpd-2.4.37 --with-pcre=/home/pcre-8.38 --with-apr=/home/apr-1.6.5 --with-apr-util=/home/apr-util-1.6.1
make
make install
检查
![](https://i-blog.csdnimg.cn/blog_migrate/bc863645b7f9392057ac476bb131afd2.png)
安装成功。
配置
想要将httpd
作为文件服务器,需要更改一些配置。
- 进入
httpd
的conf
文件夹。
/home/httpd-2.4.37/conf
- 打开
httpd.conf
配置文件。
vi httpd.conf
- 更改端口号
![](https://i-blog.csdnimg.cn/blog_migrate/f0e719e8bb27b3510feb34c955a119b9.png)
- 更改主机号
![](https://i-blog.csdnimg.cn/blog_migrate/441274d388f05d6e143b8bbd47167c96.png)
- 更改文件目录
![](https://i-blog.csdnimg.cn/blog_migrate/cd7891806184be725d6c09f8a4cba207.png)
-
启动
[root@hmaster bin]# ./apachectl start [root@hmaster bin]# ./apachectl stop [root@hmaster bin]# ./apachectl restart
-
检查
出现此页面,则安装成功。
![](https://i-blog.csdnimg.cn/blog_migrate/259c906088c7af789f1ac33c4efe777f.png)
问题
遇到的问题:
-
启动时遇到的问题
httpd: Could not open configuration file /xxx/conf/httpd.conf: No such file or directory
解决办法:
./apachectl -f /xxx/httpd/conf/httpd.conf -k start
以
httpd.conf
配置文件启动。