 Apache
 开一台主机安装即可:
 源码安装apache
 需要源码编译安装的软件包
 httpd-2.4.28.tar.gz #Apache主程序包
 apr-1.5.2.tar.gz #Apache依赖包
 apr-util-1.5.4.tar.gz #Apache依赖包
 pcre-8.41.tar.gz #Apache依赖包
 准备安装包:
 、
 安装make、gcc、openssl等编译工具和开发包
 [[email protected] ~]# yum -y install make gcc gcc-c++ openssl openssl-devel expat-devel
 编译安装依赖包

 编译安装依赖包apr-1.5.2.tar.gz
 [[email protected] ~]# cd lamp
 [[email protected] lamp]# ls
 apr-1.5.2.tar.gz apr-util-1.5.4.tar.gz httpd-2.4.28.tar.gz mysql-boost-5.7.19.tar.gz pcre-8.41.tar.gz php-5.6.36.tar.gz
 解压缩apr-1.5.2.tar.gz
 [[email protected] lamp]# tar zxvf apr-1.5.2.tar.gz
 [[email protected] lamp]# cd apr-1.5.2
 预编译指定安装路径
 [[email protected] apr-1.5.2]# ./configure --prefix=/usr/local/apr

 解决报错:
 [[email protected] apr-1.5.2]# vim configure
 修改
 29605 RM=‘KaTeX parse error: Unexpected character: '' at position 5: RM' ̲ 为:  29605 …RM -f’
 预编译报错,解决错误,重新执行预编译
 [[email protected] apr-1.5.2]# echo $? #检测上条命令是否执行成功
 0
 开始编译
 [[email protected] apr-1.5.2]# make && make install
 [[email protected] apr-1.5.2]# echo $?
 0
 编译安装依赖包apr-util-1.5.4.tar.gz
 [[email protected] lamp]# tar -zxvf apr-util-1.5.4.tar.gz
 [[email protected] lamp]# cd apr-util-1.5.4
 预编译
 [[email protected] apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util/ --with-apr=/usr/local/apr/bin/apr-1-config
 [[email protected] apr-util-1.5.4]# echo $?
 0
 编译安装
 [[email protected] apr-util-1.5.4]#make && make install
 [[email protected] apr-util-1.5.4]# echo $?
 0
 3.编译安装依赖包pcre-8.41.tar.gz
 [[email protected] lamp]# tar -zxvf pcre-8.41.tar.gz
 [[email protected] lamp]# cd pcre-8.41
 预编译
 [[email protected] pcre-8.41]# ./configure --prefix=/usr/local/pcre
 [[email protected] pcre-8.41]# echo $?
 编译并安装:
 [[email protected] pcre-8.41]# make && make install
 [[email protected] pcre-8.41]# echo $?
 0
 4编译安装Apache
 [[email protected] lamp]# tar -zxcf httpd-2.4.28.tar.gz
 [[email protected] lamp]# cd httpd-2.4.28
 预编译
 [[email protected] httpd-2.4.28]# ./configure --prefix=/usr/local/apache
 --enable-so
 --enable-rewrite
 --enable-ssl
 --with-apr=/usr/local/apr
 --with-apr-util=/usr/local/apr-util/
 --with-pcre=/usr/local/pcre/
 --libdir=/usr/lib64
 注:
 --enable-so #支持动态加载模块
 --enable-rewrite #支持网站地址重写
 --enable-ssl #支持ssl加密
 --with-apr=/usr/local/apr #关联apr
 --with-apr-util=/usr/local/apr-util #关联apr-util
 --with-pcre=/usr/local/pcre #关联pcre
 --libdir=/usr/lib64 #关联库文件

 [[email protected] httpd-2.4.28]# echo $?
 0
 编译安装
 [[email protected] httpd-2.4.28]# make && make install
 [[email protected] httpd-2.4.28]# echo $?
 0
 配置文件
 [[email protected] httpd-2.4.28]# ls /usr/local/apache/conf/httpd.conf
 /usr/local/apache/conf/httpd.conf
 [[email protected] ~]# vim /usr/local/apache/conf/httpd.conf
 Listen 80 #监听端口
 ServerRoot “/usr/local/apache” #配置文件根目录
 ServerAdmin [email protected] #管理员邮箱
 ServerName localhost:80 #服务器主机名
 DocumentRoot “/usr/local/apache/htdocs” #网站根补录
 DirectoryIndex index.html #默认首页打开html文件

 网站根目录
 [[email protected] httpd-2.4.28]# ls /usr/local/apache/htdocs/
 index.html
 [[email protected] ~]# cat /usr/local/apache/htdocs/index.html

It works!


 生成启动脚本
 [[email protected] ~]# cp /usr/local/apache/bin/apachectl /etc/init.d/
 [[email protected] ~]# chmod +x /etc/init.d/apachectl
 [[email protected] ~]# ll /etc/init.d/apachectl
 -rwxr-xr-x. 1 root root 3434 4月 23 03:17 /etc/init.d/apachectl
 写个apache系统服务脚本, 以754的权限保存此文件
 [[email protected] ~]# vim /usr/lib/systemd/system/apache.service
 [Unit]
 Description=apache
 After=network.target
 [Service]
 Type=forking
 ExecStart=/etc/init.d/apachectl start
 ExecReload=/etc/init.d/apachectl restart
 ExecStop=/etc/init.d/apachectl stop
 PrivateTmp=true
 [Install]
 WantedBy=multi-user.target
 [[email protected] ~]# chmod 754 /usr/lib/systemd/system/apache.service
 添加开机自启动
 [[email protected] ~]# systemctl enable apache
 Created symlink from /etc/systemd/system/multi-user.target.wants/apache.service to /usr/lib/systemd/system/apache.service.
 启动服务
 [[email protected] ~]# /etc/init.d/apachectl restart
 报错:
 AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using fe80::48aa:e778:8276:5257. Set the ‘ServerName’ directive globally to suppress this message
 [[email protected] ~]# vim /usr/local/apache/conf/httpd.conf
 修改192行
 192 #ServerName www.example.com:80
 为:
 192 ServerName localhost:80
 重新启动:
 [[email protected] ~]# /etc/init.d/apachectl restart
 或者:
 [[email protected] ~]# systemctl restart apache
 查看端口
 [[email protected] ~]# netstat -antup | grep 80
 tcp6 0 0 :::80 ::???? LISTEN 100326/httpd
 客户端测试

配置apache虚拟主机
 apache虚拟主机实现有三种方法:
 1、通过不同的IP地址
 2、通过不同的域名
 3、通过不同的端口号
 三种都需要把虚拟主机功能打开:
 开启虚拟主机功能:
 [[email protected] ~]# vim /usr/local/apache/conf/httpd.conf
 #配置文件最下面 启用这一行
 475 #Include conf/extra/httpd-vhosts.conf
 去掉#号
 475 Include conf/extra/httpd-vhosts.conf
 重启服务
 [[email protected] ~]# systemctl restart apache
 通过不同的IP地址,解析不同的域名
 给服务器增加IP(另一个域名解析)
 [[email protected] ~]# ifconfig ens33:1 192.168.100.66
 [[email protected] ~]# ifconfig
 创建站点目录
 [[email protected] ~]# mkdir /www/html/{web1,web2} -p
 创建站点网页
 [[email protected] ~]# echo “www.baidu.com” > /www/html/web1/index.html
 [[email protected] ~]# echo “www.bdqn.com” > /www/html/web2/index.html
 定义虚拟主机文件:
 [[email protected] ~]# vim /usr/local/apache/conf/extra/httpd-vhosts.conf

 <VirtualHost 192.168.100.101:80>
 ServerAdmin [email protected]
 DocumentRoot “/www/html/web1/”
 ServerName www.baidu.com
 ServerAlias www.dummy-host.example.com
 ErrorLog “logs/dummy-host.example.com-error_log”
 CustomLog “logs/dummy-host.example.com-access_log” common


 <VirtualHost 192.168.100.66:80>
 ServerAdmin [email protected]
 DocumentRoot “/www/html/web2/”
 ServerName www.bdqn.com
 ErrorLog “logs/dummy-host2.example.com-error_log”
 CustomLog “logs/dummy-host2.example.com-access_log” common


 重启服务
 [[email protected] ~]# systemctl restart apache
 测试
Apache源码安装与虚拟主机配置
Apache源码安装与虚拟主机配置

 通过不同的域名配置虚拟主机
 定义虚拟主机文件
 [[email protected] ~]# vim /usr/local/apache/conf/extra/httpd-vhosts.conf
Apache源码安装与虚拟主机配置
 [[email protected] ~]# vim /etc/hosts
192.168.100.101 www…baidu.com
192.168.100.66 www.bdqn.com

 重启服务
 [[email protected] ~]# systemctl restart apache
 修改电脑hosts文件C:\Windows\System32\drivers\etc\hosts作解析
Apache源码安装与虚拟主机配置
测试:
Apache源码安装与虚拟主机配置
 通过不同的端口配置虚拟主机
 增加监听端口
 [[email protected] ~]# vim /usr/local/apache/conf/httpd.conf
 在52行添加监听端口
 51 Listen 80
 52 Listen 8080

 定义虚拟主机文件:
 [[email protected] ~]# vim /usr/local/apache/conf/extra/httpd-vhosts.conf
 <VirtualHost *:80>
 ServerAdmin [email protected]
 DocumentRoot “/www/html/web1/”
 ServerName www.baidu.com
 ServerAlias www.dummy-host.example.com
 ErrorLog “logs/dummy-host.example.com-error_log”
 CustomLog “logs/dummy-host.example.com-access_log” common


 <VirtualHost *:8080>
 ServerAdmin [email protected]
 DocumentRoot “/www/html/web2/”
 ServerName www.bdqn.com
 ErrorLog “logs/dummy-host2.example.com-error_log”
 CustomLog “logs/dummy-host2.example.com-access_log” common


 重启服务
 [[email protected] ~]# systemctl restart apache
 验证
Apache源码安装与虚拟主机配置

相关文章:

  • 2022-02-23
猜你喜欢
  • 2022-12-23
  • 2021-11-17
  • 2021-12-25
  • 2021-09-24
  • 2021-11-09
相关资源
相似解决方案