CentOS 7.2 下使用命令行配置Apache的记录
本文仅为记录个人进行配置时的过程及问题。如果有和我一样碰到很多困难的同学,建议花点时间,翻个墙,多看看国外官网的Documentation,会感觉好很多。配置方式相当的初级简单,不慎安全,大牛轻喷。
- CentOS 72 下使用命令行配置Apache的记录
- 依赖体系的官网及下载地址
- 下载安装APR
- 下载安装APR-Util
- 安装c compiler 支持
- 安装PCRE
- 安装Apache HTTP Server
- 配置httpdconf
- 启动及关闭httpd
- 测试访问
- 后记
- 微信号13922203096欢迎交流请备注csdn
1.依赖体系的官网及下载地址:
1.Apache HTTP Server
2.APR
3.APR-Util
4.PCRE
2.下载安装APR
cd /usr /*移动到usr文件夹
mkdir server /*建立server文件夹
cd /usr/server /*移动到server文件夹
wget -d http://mirrors.hust.edu.cn/apache//apr/apr-1.5.2.tar.gz /*下载apr
tar xzvf apr-1.5.2.tar.gz /*解压缩
mv apr-1.5.2 apr /*改apr文件夹名
cd /usr/server/apr /*移动到apr文件夹
./configure /*配置安装apr
make
make install
3.下载安装APR-Util
cd /usr/server /*移动到server文件夹
wget -d http://mirrors.hust.edu.cn/apache//apr/apr-util-1.5.4.tar.gz /*下载apr-util
tar xzvf apr-util-1.5.4.tar.gz /*解压缩
mv apr-util-1.5.4.gz apr-util /*改apr-util文件夹名
cd /usr/server/apr-util /*移动到apr-util文件夹
./configure --with-apr=/usr/server/apr /*配置安装,必须要带上apr地址,--with看不懂的话可以去看官方Documentation
make
make install
4.安装c++ compiler 支持
yum -y install gcc-c++ /安装c++ compiler,建议查看yum指南
5.安装PCRE
cd /usr/server /*移动到server文件夹
wget -d https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gz /*下载pcre,注意不要选择pcre2
tar xzvf pcre-8.40.tar.gz /*tar解压缩命令,使用方法可以查看tar --help
mv pcre-8.40 pcre /*mv指令修改文件夹名为pcre
cd /usr/server/pcre /*移动到pcre文件夹
./configure /*配置安装
make
make install
6.安装Apache HTTP Server
cd /usr/server /*移动到server文件夹
wget -d http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.25.tar.gz /*下载httpd安装包
tar xzvf httpd-2.4.25.tar.gz /*解压缩
mv httpd-2.4.25 httpd /*修改文件夹名为httpd
cd /usr/server/httpd /*移动到httpd文件夹
./configure /*配置安装
make
make install
7.配置httpd.conf
请紧记这种简易安装方式下,apache默认安装在/usr/local/apache2文件夹中,启动httpd前,我们需要配置其中的httpd.conf
cd /usr/local/apache2/conf /*移动到apache的配置文件夹下
vi httpd.conf /*vi编辑
/**
找到文件中的: #ServerName www.example.com:80
改为: ServerName localhost:80 /*去掉前面的#,即去掉注释使其生效
**/
键入Esc /*键盘左上角的那个按钮-0-,退出编辑状态
:wq /*保存并退出,看不懂的详细查看vi编辑器使用方法
8.启动及关闭httpd
本文基于CentOS 7.2, 请紧记:
service xxx start/stop的启动方式已经不再有效
请改用:
systemctl start xxxxx.service 即启动xxxxx服务
systemctl stop xxxxx.service 即停止xxxxx服务
systemctl restart xxxxx.service 即重启xxxxx服务
systemctl enable xxxxx.service 即允许开机启动xxxx服务
如果看不懂的话,请百度systemctl
接下来我们对系统输入以下命令启动,并查看httpd监听状态
systemctl start httpd.service /*启动httpd服务
Failed to start httpd.service:Unit not found. /*系统反应无法启动,没有这个单元,原因是上面的安装方法并没有将httpd注册到systemctl
/** 下面我们尝试手动启动 **/
cd /usr/local/apache2/bin /*移动到httpd安装的文件夹,路径请看上文
./httpd -k start /*手动启动,没有报错
netstat -lnp|grep 80 /*捕捉80端口状态,如果你真的要深究,请百度netstat
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 6167/./httpd /*启动成功
./httpd -k start 即启动
./httpd -k stop 即关闭
9.测试访问
打开浏览器输入你的ip地址(x.x.x.x:80)或者直接在服务器的浏览器上键入localhost
10.后记
如果有有哪位同学还看手动启动不顺眼,希望使用systemctl方式来启动,我再写