CentOS如何源码安装apache/HTTP服务
这篇文章主要介绍了CentOS如何源码安装apache/HTTP服务,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
CentOS 源码安装apache/HTTP服务
httpd:是一个提供网站服务的程序
监听端口:80
环境准备:
Linux CentOS7.3系统
使用一台服务端,一台客户端即可;
一、安装httpd
1:安装
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setensorce 0
[root@localhost ~]# rpm -e httpd –nodeps #卸载系统自带的httpd
[root@localhost ~]# mkdir /media/cdrom #创建挂载点文件夹
[root@localhost ~]# mount /dev/cdrom /media/cdrom #挂载光盘
[root@localhost ~]# yum -y install gcc* apr-devel apr-util-devel pcre-devel #安装开发包
[root@localhost ~]# tar zxvf httpd-2.4.25.tar.gz #解压缩包
[root@localhost ~]# cd httpd-2.4.25
[root@localhost httpd-2.4.25]# ./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi
注释:
--prefix:制定程序的安装目录
--enable-so:启用动态加载模块DSO的支持,使httpd具备进一步扩展功能的能力
--enable-rewrite:启用网页地址重写功能,用于网站优化
--enable-charset-lite:启动字符集支持,以便支持使用各种字符集编码的网页
--enable-cgi:启用cgi脚本程序支持,扩展网站的应用访问能力
[root@localhost httpd-2.4.25]# make && make install
[root@localhost httpd-2.4.25]# ls /usr/local/httpd
[root@localhost httpd-2.4.25]# /usr/local/httpd/bin/apachectl start
[root@localhost httpd-2.4.25]# netstat -anpt |grep httpd
[root@localhost httpd-2.4.25]# /usr/local/httpd/bin/apachectl stop
[root@localhost httpd-2.4.25]# netstat -anpt |grep httpd
2:优化执行路径
[root@localhost httpd-2.4.25]# ln -s /usr/local/httpd/bin/* /usr/local/bin/
[root@localhost httpd-2.4.25]# ls -l /usr/local/bin/httpd /usr/local/bin/apachectl
#查看软连接
[root@localhost httpd-2.4.25]# httpd -v
[root@localhost httpd-2.4.25]# apachectl start
[root@localhost httpd-2.4.25]# netstat -anpt |grep httpd
[root@localhost httpd-2.4.25]# apachectl stop
[root@localhost httpd-2.4.25]# netstat -anpt |grep httpd
3:添加httpd系统服务
使用chkconfig添加为系统服务
[root@localhost httpd-2.4.25]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd #复制配置文件
[root@localhost httpd-2.4.25]# vi /etc/init.d/httpd //编辑配置文件
添加:
#!/bin/sh
#chkconfig:35 85 21
#description:httpd server
[root@localhost httpd-2.4.25]# chkconfig --add httpd #加入系统服务,开机启动
[root@localhost httpd-2.4.25]# chkconfig --list httpd
[root@localhost httpd-2.4.25]# service httpd start #启动httpd
二、httpd服务器的基本配置
1:确定网站的名称、ip地址和域名
2:配置并启动httpd
[root@localhost ~]# vim /usr/local/httpd/conf/httpd.conf
修改(前面的数字是行号):
ServerName www.bdqn.com ##200行
[root@localhost ~]# apachectl -t #检测配置文件语法
2:启动httpd服务
[root@localhost ~]# systemctl start httpd #启动httpd
[root@localhost ~]# netstat -anpt | grep httpd
3:部署网页
[root@localhost ~]# vim /usr/local/httpd/htdocs/index.html #编辑主页
It works!
[root@localhost ~]# service httpd restart #重启httpd服务
4:测试
打开网站
http://192.168.10.101
5:查看站点访问情况
[root@localhost ~]# tail /usr/local/httpd/logs/access_log
[root@localhost ~]# tail /usr/local/httpd/logs/error_log
三、httpd.conf配置文件解释
1:全局配置项
[root@localhost ~]# vim /usr/local/httpd/conf/httpd.conf ServerRoot "/usr/local/httpd" Listen 80 #监听端口(默认80) User daemon #用户 (默认daemon) Group daemon #用户组(默认daemon) ServerAdmin you@example.com #邮箱地址 ServerName www.bdqn.com #网站域名 DocumentRoot "/usr/local/httpd/htdocs" #网页存储位置 DirectoryIndex index.html #默认主页 ErrorLog "logs/error_log" #错误日志文件存储位置 LogLevel warn #日志级别 CustomLog "logs/access_log" common #正常访问日志 Include conf/extra/proxy-html.conf #虚拟主机路径 |
2:区域配置项
[root@localhost ~]# vim /usr/local/httpd/conf/httpd.conf AllowOverride none Require all denied Options Indexes FollowSymLinks AllowOverride None Require all granted #允许所有主机访问还可以拒绝所有人访问 |
感谢你能够认真阅读完这篇文章,希望小编分享的"CentOS如何源码安装apache/HTTP服务"这篇文章对大家有帮助,同时也希望大家多多支持,关注行业资讯频道,更多相关知识等着你来学习!