apache

  1. 安装前的准备

     yum install \
     vim \
     gcc \
     gcc-c++ \
     wget \
     make \
     libtool \
     automake \
     autoconf \
     expat-devel \
     -y \
    
  2. 安装apr、apr-util

     cd /root
     wget http://mirrors.hust.edu.cn/apache/apr/apr-1.6.3.tar.gz
     tar -zxvf apr-1.6.3.tar.gz
     cd apr-1.6.3
     ./configure
     make
     make install
    
     cd /root
     wget http://mirrors.hust.edu.cn/apache/apr/apr-util-1.6.1.tar.gz
     tar -zxvf apr-util-1.6.1.tar.gz
     cd apr-util-1.6.1
     ./configure --with-apr=../apr-1.6.3
     make
     make install
    
  3. 安装PCRE库

     cd /root
     wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz
     或者(第三方):wget https://fossies.org/linux/misc/pcre-8.39.tar.gz
     tar -zxvf pcre-8.39.tar.gz
     cd pcre-8.39
     ./configure
     make
     make install
    
  4. 安装zlib库

     cd /root
     wget http://zlib.net/zlib-1.2.11.tar.gz
     tar -zxvf zlib-1.2.11.tar.gz
     cd zlib-1.2.11
     ./configure
     make
     make install
    
  5. 安装openssl

     # openssl从1.0.2开始支持http2
     cd /root
     wget https://www.openssl.org/source/openssl-1.0.2l.tar.gz
     tar -zxvf openssl-1.0.2l.tar.gz
    
  6. 获取源码并安装

     cd /root
     wget http://mirrors.shuosc.org/apache//httpd/httpd-2.4.29.tar.gz
     tar -zxvf httpd-2.4.29.tar.gz
     cd httpd-2.4.29
     # 注意:
         # with-apr和with-apr-util要指定安装路径
         # with-z with-ssl with-pcre如安装时指定了路径,这里也要指定路径
     ./configure \
     --prefix=/usr/local/apache \
     --sysconfdir=/etc/httpd \
     --with-mpm=event \
     --with-apr=../apr-1.6.3/ \
     --with-apr-util=../apr-util-1.6.1 \
     --with-z \
     --with-ssl \
     --with-pcre \
     --enable-so \
     --enable-cgi \
     --enable-ssl \
     --enable-rewrite \
     --enable-modules=most \
     --enable-mpms-shared=all \
     make
     make install
    
  7. 修改配置

     # 注意,这里不要使用和其它web服务冲突的端口号
     vim /etc/httpd/httpd.conf
    
     ServerName localhost:80
     User www
     Group www
    
     ESC
     :wq
    
  8. 修改目录所属用户(也可不修改)

     useradd www
     chown -R www:www /usr/local/apache
    
  9. 启动与关闭测试

     # 检测
     /usr/local/apache/bin/apachectl configtest
     # 启动
     /usr/local/apache/bin/apachectl start
     # 重启
     /usr/local/apache/bin/apachectl restart
     # 关闭
     /usr/local/apache/bin/apachectl stop
    
  10. 创建软连接,编辑启动脚本

     ln -s /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd
    
     vim /etc/rc.d/init.d/httpd
    
     #chkconfig: 2345 10 90
     #description: Apache Web Server
    
     ESC
     :wq
    
  11. Apache加入系统服务

     chkconfig --add httpd
     chkconfig --list httpd
    
  12. 设置开机启动并启动

     systemctl start httpd
     systemctl enable httpd
    
  13. 查看应用状态

     ps aux|grep httpd
    
  14. 开启防火墙指定端口

     yum install firewalld
     systemctl enable firewalld
     systemctl start firewalld
     firewall-cmd --zone=public --add-port=80/tcp --permanent
     firewall-cmd --zone=public --add-port=443/tcp --permanent
     firewall-cmd --reload
    
  15. 访问Web服务查看是否正常运行

     # 访问http://xxx.xxx.xxx.xxx
     # 显示: It works! 表示一切正常
    
  16. apache-2.4.x主配置文件httpd.conf(干货)

     # apache安装目录
     ServerRoot "/usr/local/apache"
     # 默认监听端口
     #Listen 0.0.0.0:80
     Listen 80
     # 加载模块
     LoadModule mpm_event_module modules/mod_mpm_event.so
     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
     LoadModule php7_module modules/libphp7.so
     #LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
     #LoadModule mpm_worker_module modules/mod_mpm_worker.so
     #LoadModule authn_dbm_module modules/mod_authn_dbm.so
     #LoadModule authn_anon_module modules/mod_authn_anon.so
     #LoadModule authn_dbd_module modules/mod_authn_dbd.so
     #LoadModule authn_socache_module modules/mod_authn_socache.so
     #LoadModule authz_dbm_module modules/mod_authz_dbm.so
     #LoadModule authz_owner_module modules/mod_authz_owner.so
     #LoadModule authz_dbd_module modules/mod_authz_dbd.so
     #LoadModule auth_form_module modules/mod_auth_form.so
     #LoadModule auth_digest_module modules/mod_auth_digest.so
     #LoadModule allowmethods_module modules/mod_allowmethods.so
     #LoadModule file_cache_module modules/mod_file_cache.so
     #LoadModule cache_module modules/mod_cache.so
     #LoadModule cache_disk_module modules/mod_cache_disk.so
     #LoadModule cache_socache_module modules/mod_cache_socache.so
     #LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
     #LoadModule socache_dbm_module modules/mod_socache_dbm.so
     #LoadModule socache_memcache_module modules/mod_socache_memcache.so
     #LoadModule watchdog_module modules/mod_watchdog.so
     #LoadModule macro_module modules/mod_macro.so
     #LoadModule dbd_module modules/mod_dbd.so
     #LoadModule dumpio_module modules/mod_dumpio.so
     #LoadModule buffer_module modules/mod_buffer.so
     #LoadModule ratelimit_module modules/mod_ratelimit.so
     #LoadModule ext_filter_module modules/mod_ext_filter.so
     #LoadModule request_module modules/mod_request.so
     #LoadModule include_module modules/mod_include.so
     #LoadModule substitute_module modules/mod_substitute.so
     #LoadModule sed_module modules/mod_sed.so
     #LoadModule deflate_module modules/mod_deflate.so
     #LoadModule log_debug_module modules/mod_log_debug.so
     #LoadModule logio_module modules/mod_logio.so
     #LoadModule expires_module modules/mod_expires.so
     #LoadModule unique_id_module modules/mod_unique_id.so
     #LoadModule remoteip_module modules/mod_remoteip.so
     #LoadModule proxy_module modules/mod_proxy.so
     #LoadModule proxy_connect_module modules/mod_proxy_connect.so
     #LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
     #LoadModule proxy_http_module modules/mod_proxy_http.so
     #LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
     #LoadModule proxy_scgi_module modules/mod_proxy_scgi.so
     #LoadModule proxy_fdpass_module modules/mod_proxy_fdpass.so
     #LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so
     #LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
     #LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
     #LoadModule proxy_express_module modules/mod_proxy_express.so
     #LoadModule proxy_hcheck_module modules/mod_proxy_hcheck.so
     #LoadModule session_module modules/mod_session.so
     #LoadModule session_cookie_module modules/mod_session_cookie.so
     #LoadModule session_dbd_module modules/mod_session_dbd.so
     #LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
     #LoadModule ssl_module modules/mod_ssl.so
     #LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so
     #LoadModule lbmethod_bytraffic_module modules/mod_lbmethod_bytraffic.so
     #LoadModule lbmethod_bybusyness_module modules/mod_lbmethod_bybusyness.so
     #LoadModule lbmethod_heartbeat_module modules/mod_lbmethod_heartbeat.so
     #LoadModule dav_module modules/mod_dav.so
     #LoadModule info_module modules/mod_info.so
     #LoadModule dav_fs_module modules/mod_dav_fs.so
     #LoadModule vhost_alias_module modules/mod_vhost_alias.so
     #LoadModule negotiation_module modules/mod_negotiation.so
     #LoadModule actions_module modules/mod_actions.so
     #LoadModule speling_module modules/mod_speling.so
     #LoadModule userdir_module modules/mod_userdir.so
     #LoadModule rewrite_module modules/mod_rewrite.so
     # 有些配置在指定模块被成功加载后才能添加
     <IfModule !mpm_prefork_module>
         #LoadModule cgid_module modules/mod_cgid.so
     </IfModule>
     <IfModule mpm_prefork_module>
         #LoadModule cgi_module modules/mod_cgi.so
     </IfModule>
     <IfModule unixd_module>
     # 子进程用户
     User www
     Group www
     </IfModule>
     # 主服务配置
     ServerAdmin test@test.com
     ServerName localhost:80
     <FilesMatch \.php$>
         SetHandler application/x-httpd-php
     </FilesMatch>
     # 这里是全局目录默认规则
     <Directory />
         AllowOverride none
         Require all denied
     </Directory>
     # web目录默认位置
     DocumentRoot "/www"
     <Directory "/www">
         Options Indexes FollowSymLinks
         AllowOverride None
         Require all granted
     </Directory>
     # 不指定文件名时默认访问路径下的文件
     <IfModule dir_module>
         DirectoryIndex index.php index.html index.htm
     </IfModule>
     # 防止 .ht* 文件被从Web上访问
     <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>
             LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
         </IfModule>
         CustomLog "logs/access_log" common
         #CustomLog "logs/access_log" combined
     </IfModule>
     # alias_module
     <IfModule alias_module>
         ScriptAlias /cgi-bin/ "/usr/local/apache/cgi-bin/"
     </IfModule>
     # cgid_module
     <IfModule cgid_module>
         #Scriptsock cgisock
     </IfModule>
     # cgi-bin目录
     <Directory "/usr/local/apache/cgi-bin">
         AllowOverride None
         Options None
         Require all granted
     </Directory>
     # 请求头
     <IfModule headers_module>
         RequestHeader unset Proxy early
     </IfModule>
     # mime类型对照
     <IfModule mime_module>
         TypesConfig /etc/mime.types
         AddType application/x-compress .Z
         AddType application/x-gzip .gz .tgz
         #AddEncoding x-compress .Z
         #AddEncoding x-gzip .gz .tgz
         #AddType application/x-gzip .tgz
         #AddType text/html .shtml
         #AddHandler cgi-script .cgi
         #AddHandler type-map var
         #AddOutputFilter INCLUDES .shtml
     </IfModule>
     #MIMEMagicFile /etc/magic
     #ErrorDocument 500 "The server made a boo boo."
     #ErrorDocument 404 /missing.html
     #ErrorDocument 404 "/cgi-bin/missing_handler.pl"
     #ErrorDocument 402 http://www.example.com/subscription_info.html
     #MaxRanges unlimited
     #EnableMMAP off
     #EnableSendfile on
    
     # Server-pool management (MPM specific)
     #Include /etc/extra/httpd-mpm.conf
    
     # Multi-language error messages
     #Include /etc/extra/httpd-multilang-errordoc.conf
    
     # Fancy directory listings
     #Include /etc/extra/httpd-autoindex.conf
    
     # Language settings
     #Include /etc/extra/httpd-languages.conf
    
     # User home directories
     #Include /etc/extra/httpd-userdir.conf
    
     # Real-time info on requests and configuration
     #Include /etc/extra/httpd-info.conf
    
     # Virtual hosts
     #Include /etc/extra/httpd-vhosts.conf
    
     # Local access to the Apache HTTP Server Manual
     #Include /etc/extra/httpd-manual.conf
    
     # Distributed authoring and versioning (WebDAV)
     #Include /etc/extra/httpd-dav.conf
    
     # Various default settings
     #Include /etc/extra/httpd-default.conf
    
     # proxy_html_module
     <IfModule proxy_html_module>
     Include /etc/extra/proxy-html.conf
     </IfModule>
    
     # https相关配置
     # Secure (SSL/TLS) connections
     #Include /etc/extra/httpd-ssl.conf
     <IfModule ssl_module>
     SSLRandomSeed startup builtin
     SSLRandomSeed connect builtin
     </IfModule>
    
  17. 虚拟主机(Virtual hosts)配置httpd-vhosts.conf

     # 打开'#Include /xxx/httpd-vhosts.conf'的注释才能生效
     # 监听80端口
     <VirtualHost *:80>
         # 异常时向test@test.com发送邮件
         ServerAdmin test@test.com
         # web真实目录
         DocumentRoot "/www/test"
         # 服务域名
         ServerName www.test.com
         # 服务别名(可以没有)
         ServerAlias alias.test.com
         # 错误日志位置(mod_log_config)
         ErrorLog "logs/error_log"
         # 访问日志位置以及日志级别(mod_log_config)
         CustomLog "logs/access_log" common
     </VirtualHost>
    
@耿志环 2012-∞ 冀ICP备17033181号, powered by Gitbook修订: 2019-01-07 11:22:32

results matching ""

    No results matching ""