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 #编辑主页
<html><body><h1>it works!</h1></body></html>
[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 #邮箱地址 servername #网站域名 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 <directory /> #根目录 allowoverride none require all denied </directory>
<directory "/usr/local/httpd/htdocs"> #限制路径 options indexes followsymlinks allowoverride none require all granted #允许所有主机访问还可以拒绝所有人访问 </directory>
|
推荐阅读
-
Linux+php+apache+oracle环境搭建之CentOS下安装Oracle数据库
-
centos7上编译安装php7以php-fpm方式连接apache
-
Centos7通过yum跟源码编译安装Nginx
-
CentOS 7.x安装部署Memcached服务器的详细方法
-
CentOS7服务器环境下vsftpd安装及配置方法
-
CentOS6.5服务器环境安装VPN的方法
-
CentOS 7中 Apache Web 服务器安装配置教程
-
Apache Web服务器的完全安装指南
-
CentOS服务器apache绑定多个域名的方法
-
centos6.5中用yum方式安装php5.4与apache2.2的步骤