[root@lamp scripts]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
[root@lamp scripts]# uname -r
3.10.0-862.el7.x86_64
[root@lamp scripts]# cat apache-2.4.38_install.sh
#!/bin/bash #安装依赖软件
yum -y install gcc gcc-c++ make wget zlib-devel openssl-devel perl perl-devel expat-devel #编译安装apr-1.5.2
cd /usr/local/src/
wget -c http://archive.apache.org/dist/apr/apr-1.5.2.tar.gz
tar -xf apr-1.5.2.tar.gz
cd apr-1.5.2
./configure --prefix=/usr/local/apache/apr && make && make install #编译安装apr-util
cd /usr/local/src/
wget -c http://archive.apache.org/dist/apr/apr-util-1.5.4.tar.gz
tar -xf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4
./configure --prefix=/usr/local/apache/apr-util --with-apr=/usr/local/apache/apr && make && make install #编译安装pcre
cd /usr/local/src/
wget -c https://jaist.dl.sourceforge.net/project/pcre/pcre/8.37/pcre-8.37.tar.gz
tar -xf pcre-8.37.tar.gz
cd pcre-8.37
./configure && make && make install #编译安装apache-2.4.38
cd /usr/local/src/
wget -c https://mirrors.aliyun.com/apache/httpd/httpd-2.4.38.tar.gz
tar -xf httpd-2.4.38.tar.gz
cd httpd-2.4.38
./configure --prefix=/usr/local/apache --with-apr=/usr/local/apache/apr/bin/apr-1-config --with-apr-util=/usr/local/apache/apr-util/bin/apu-1-config --enable-module=so --enable-mods-shared=all --enable-deflate --enable-expires --enable-headers --enable-cache --enable-file-cache --enable-mem-cache --enable-disk-cache --enable-mime-magic --enable-authn-dbm --enable-vhost-alias --enable-so --enable-rewrite --enable-ssl --with-mpm=prefork
make && make install #创建站点目录和拷贝首页文件
mkdir -p /var/www/html
mv /usr/local/apache/htdocs/index.html /var/www/html/
cd /usr/local/apache/conf/ && mv httpd.conf httpd.conf.bak #配置httpd.conf和创建自定义的基于域名的虚拟主机
cat > /usr/local/apache/conf/httpd.conf << EOF
ServerRoot "/usr/local/apache"
ServerName 127.0.0.1:80
Listen 80
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_core_module modules/mod_authn_core.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule access_compat_module modules/mod_access_compat.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule reqtimeout_module modules/mod_reqtimeout.so
LoadModule filter_module modules/mod_filter.so
LoadModule mime_module modules/mod_mime.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule env_module modules/mod_env.so
LoadModule headers_module modules/mod_headers.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule version_module modules/mod_version.so
LoadModule unixd_module modules/mod_unixd.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule dir_module modules/mod_dir.so
LoadModule alias_module modules/mod_alias.so
<IfModule unixd_module>
User daemon
Group daemon
</IfModule>
ServerAdmin 2570583786@qq.com
<Directory />
AllowOverride none
Require all denied
</Directory>
DocumentRoot "/var/www/html"
<Directory "/var/www/html">
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
<Files ".ht*">
Require all denied
</Files>
ErrorLog "logs/error_log"
LogLevel warn
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
# You need to enable mod_logio.c to use %I and %O
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog "logs/access_log" common
</IfModule>
<IfModule alias_module>
ScriptAlias /cgi-bin/ "/usr/local/apache/cgi-bin/"
</IfModule>
<IfModule cgid_module>
</IfModule>
<Directory "/usr/local/apache/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>
<IfModule headers_module>
RequestHeader unset Proxy early
</IfModule>
<IfModule mime_module>
TypesConfig conf/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .php5
</IfModule>
<IfModule proxy_html_module>
Include conf/extra/proxy-html.conf
Include conf/extra/httpd-mpm.conf
Include conf/extra/httpd-default.conf
Include conf/extra/httpd-vhosts.conf
</IfModule>
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule> <Directory "/var/www/html">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
EOF cat >> /usr/local/apache/conf/extra/httpd-vhosts.conf << EOF
<VirtualHost *:80>
ServerAdmin 2570583786@qq.com
DocumentRoot "/var/www/html"
ServerName www.test.cn
ServerAlias test.cn
ErrorLog "logs/www_log"
CustomLog "logs/www-access_log" common
</VirtualHost>
EOF #检查语法,然后启动httpd服务
/usr/local/apache/bin/apachectl -t
/usr/local/apache/bin/apachectl start

注意:由于软件下载链接有可能会失效,上面一键安装apache-2.4.38脚本有可能会失败,需自行检查软件下载链接是否失效!

测试:在windows客户端的hosts文件中添加域名解析记录  10.0.0.3   www.test.cn ,然后打开浏览器测试首页链接成功!

最新文章

  1. commons-beanutils使用
  2. 深入剖析哪些服务是Oracle 11g必须开启的
  3. Gradle digest
  4. [ An Ac a Day ^_^ ] CodeForces 601A The Two Routes 最短路
  5. PAT乙级-1041. 考试座位号(15)
  6. 基于tcp的云盘上传下载的模拟
  7. 一个很好用的在线编辑、展示、分享、交流JavaScript 代码的平台
  8. VS Code的golang开发配置 之 代码提示
  9. poj-1328(贪心+思维)
  10. JavaScript学习总结(二)——延迟对象、跨域、模板引擎、弹出层、AJAX示例
  11. CentOS的update-grub2命令
  12. [Algorithm] Find first missing positive integer
  13. 重构指南 - 分解复杂判断(Remove Arrowhead Antipattern)
  14. hadoop 2.7.3 (hadoop2.x)使用ant制作eclipse插件hadoop-eclipse-plugin-2.7.3.jar
  15. Flask框架 之 学生管理分析
  16. 倍福TwinCAT(贝福Beckhoff)基础教程 松下驱动器如何执行绝对值清零
  17. jquery的ajax(err)
  18. vijos 1053 Easy sssp
  19. 湖南长沙IOS(xcode swift) 开发交流群
  20. 什么是A记录、MX记录、CNAME记录具体介绍

热门文章

  1. 线程上下文类加载器ContextClassLoader内存泄漏隐患
  2. Vue 例子
  3. kafka 中 zookeeper 具体是做什么的?
  4. 深入学习MySQL 01 一条查询语句的执行过程
  5. Browser Security-同源策略、伪URL的域
  6. Python-logging模块简单使用
  7. mong 的 安装 和测试
  8. 【WPF学习】第十九章 控件类
  9. export 和 export default 的区别
  10. es6 promise 简单总结