apache2.4安装部署 可以一键安装

apache 安装主要事项

1 安装apr和apr-util 、zlib、pcre、openssl
2 编译安装apache
3 配置 http.conf
4 启动apache

apache编译项说明

--enable-so:支持动态加载模块(即打开DSO支持)

--enable-rewrite:支持地址重写

--enable-ssl:支持ssl加密

--with-ssl=/usr/local/openssl:指定ssl安装位置

--enable-cgi:启用cgi

--enable-cgid: 为了支持event和worker

--enable-modules=most:明确指明要静态编译到httpd二进制文件的模块,<MODULE-LIST>为空格分隔的模块名列表、all或者most,all表示包含所有模块,most表示包含大部分常用模块

--enable-mods-shared=most:明确指明要以DSO(动态)方式编译的模块,<MODULE-LIST>为空格分隔的模块名列表、all或者most,all表示包含所有模块,most表示包含大部分模块

--enable-mpms-shared=all:启用MPM所有支持的模式,这样event、worker、prefork就会以模块化的方式安装,要用哪个就在 httpd.conf 里配置就好了。

--with-mpm=event:指定启用的mpm模式,默认使用enevt模式,在apache的早期版本2.0默认prefork,2.2版本是worker,2.4版本是event.

--with-pcre=/usr/local/pcre:支持pcre

--with-z=/usr/local/zlib:使用zlib压缩库

--with-apr=/usr/local/apr:指定apr的安装路径

--with-apr-util=/usr/local/apr-util:指定apr-util的安装路径

--enable-expires:为客户端浏览器提供缓存功能

--enable-deflate:提供对内容的压缩传输编码支持

apache一键安装脚本

#!/bin/bash
# Writed by fffmo.com on 2017/11/11
#安装必要依赖软件
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 250097156@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 250097156@qq.com
DocumentRoot "/var/www/html"
ServerName www.fffmo.com
ServerAlias fffmo.com
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
cd /usr/local/httpd/conf
赞(1) 打赏
特别声明:除特殊标注,本站文章均为原创,遵循CC BY-NC 3.0,转载请注明出处。三伏磨 » apache2.4安装部署 可以一键安装

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏