设为首页 收藏本站
查看: 445|回复: 0

[经验分享] 在windows下使用Apache2.2

[复制链接]

尚未签到

发表于 2016-5-21 04:05:18 | 显示全部楼层 |阅读模式
  
在Microsoft Windows下使用Apache2.2
  This document explains how to install, configure and runApache 2.0 under Microsoft Windows. If you find any bugs, orwish to contribute in other ways, please use our bug reportingpage.
  This document assumes that you are installing a binarydistribution of Apache. If you want to compile Apache yourself(possibly to help with development or tracking down bugs),see Compiling Apache for MicrosoftWindows.
  Because of the current versioning policies on MicrosoftWindows operating system families, this document assumes thefollowing:

  • Windows NT:This means all versions ofWindows that are based on the Windows NT kernel. Includes WindowsNT, Windows 2000, Windows XP and Windows .Net Server 2003.
  • Windows 9x:This means older,consumer-oriented versions of Windows. Includes Windows 95 (alsoOSR2), Windows 98 and Windows ME.


  • DSC0000.gif Operating System Requirements
  • Downloading Apache for Windows
  • Installing Apache for Windows
  • Customizing Apache for Windows
  • Running Apache as a Service
  • Running Apache as a Console Application
  • Testing the Installation

DSC0001.gif
Operating System Requirements
  The primary Windows platform for running Apache 2.0 is WindowsNT. The binary installer only works with the x86 family ofprocessors, such as Intel and AMD processors. Running Apache onWindows 9x is not thoroughly tested, and it is never recommended onproduction systems.
  On all operating systems, TCP/IP networking must be installedand working. If running on Windows 95, the Winsock 2 upgrade mustbe installed. Winsock 2 for Windows 95 can be downloaded from here.
  On Windows NT 4.0, installing Service Pack 6 is stronglyrecommended, as Service Pack 4 created known issues with TCP/IPand Winsock integrity that were resolved in later Service Packs.


Downloading Apache for Windows
  Information on the latest versions of Apache can be found on theweb site of the Apache web server athttp://httpd.apache.org/download.cgi.There you will find the current release, as well as more recent alphaor beta test versions, and a list of HTTP and FTP mirrors from whichyou can download the Apache web server. Please use a mirror near toyou for a fast and reliable download.
  For Windows installations you should download the version ofApache for Windows with the .msiextension. This is asingle Microsoft Installer file, which contains a ready-to-runversion of Apache. There is a separate .zipfile,which contains only the source code. You can compile Apacheyourself with the Microsoft Visual C++ (Visual Studio) tools.


Installing Apache for Windows
  You need Microsoft Installer 1.2 or above for the installationto work. On Windows 9x you can update your Microsoft Installer toversion 2.0 hereand on Windows NT 4.0 and 2000 the version 2.0 update can be foundhere.Windows XP does not need this update.
  Note that you cannot install two versions of Apache 2.0 on thesame computer with the binary installer. You can, however, installa version of the 1.3 series anda version of the2.0 series on the same computer without problems. If you need tohave two different 2.0 versions on the same computer, you have tocompile and install Apache from thesource.
  Run the Apache .msifile you downloaded above. Theinstallation will ask you for these things:

  •   Network Domain.Enter the DNS domain in whichyour server is or will be registered in. For example, if yourserver's full DNS name is server.mydomain.net, you wouldtype mydomain.nethere.
  •   Server Name.Your server's full DNS name.From the example above, you would type server.mydomain.nethere.
  •   Administrator's Email Address.Enter theserver administrator's or webmaster's email address here. Thisaddress will be displayed along with error messages to the clientby default.
  •   For whom to install ApacheSelect forAll Users, on Port 80, as a Service - Recommendedif you'dlike your new Apache to listen at port 80 for incoming traffic.It will run as a service (that is, Apache will run even if no oneis logged in on the server at the moment) Select only forthe Current User, on Port 8080, when started Manuallyifyou'd like to install Apache for your personal experimenting orif you already have another WWW server running on port 80.
  •   The installation type.Select Typicalfor everything except the source code and libraries for moduledevelopment. With Customyou can specify what toinstall. A full install will require about 13 megabytes of freedisk space. This does notinclude the size of your website(s).
  •   Where to install.The default path isC:\Program Files\Apache Software Foundationunder which a directory called Apache2.2will be created by default.
  During the installation, Apache will configure the files in theconfsubdirectory to reflect the chosen installationdirectory. However, if any of the configuration files in thisdirectory already exist, they will not be overwritten. Instead, thenew copy of the corresponding file will be left with the extension.default. So, for example, if conf\httpd.confalready exists, it will be renamed as conf\httpd.conf.default.After the installation you should manually check to see what newsettings are in the .defaultfile, and if necessary,update your existing configuration file.
  Also, if you already have a file called htdocs\index.html,it will not be overwritten (and no index.html.defaultwill be installed either). This means it should be safe to installApache over an existing installation, although you would have tostop the existing running server before doing the installation, andthen start the new one after the installation is finished.
  After installing Apache, you must edit the configuration filesin the confsubdirectory as required. These fileswill be configured during the installation so that Apache is readyto be run from the directory it was installed into, with thedocuments server from the subdirectory htdocs. Thereare lots of other options which you should set before you reallystart using Apache. However, to get started quickly, the filesshould work as installed.


Customizing Apache for Windows
  Apache is configured by the files in the confsubdirectory. These are the same files used to configure the Unixversion, but there are a few different directives for Apache onWindows. See the directive indexfor all the available directives.
  The main differences in Apache for Windows are:

  •   Because Apache for Windows is multithreaded, it does notuse a separate process for each request, as Apache does on Unix.Instead there are usually only two Apache processes running: aparent process, and a child which handles the requests. Withinthe child process each request is handled by a separate thread.
      The process management directives are also different:
      MaxRequestsPerChild:Like the Unix directive, this controls how many requests a singlechild process will serve before exiting. However, unlike on Unix,a single process serves all the requests at once, not just one.If this is set, it is recommended that a very high number isused. The recommended default, MaxRequestsPerChild 0,causes the child process to never exit.
    Warning: The server configurationfile is reread when a new child process is started. If you havemodified httpd.conf, the new child may not start oryou may receive unexpected results.
      ThreadsPerChild:This directive is new. It tells the server how many threads itshould use. This is the maximum number of connections the servercan handle at once, so be sure to set this number high enough foryour site if you get a lot of hits. The recommended default isThreadsPerChild 50.
  •   The directives that accept filenames as arguments must useWindows filenames instead of Unix ones. However, because Apacheuses Unix-style names internally, you must use forward slashes,not backslashes. Drive letters can be used; if omitted, the drivewith the Apache executable will be assumed.
  •   While filenames are generally case-insensitive onWindows, URLs are still treated internally as case-sensitivebefore they are mapped to the filesystem.  For example, the<Location>,Alias, and ProxyPassdirectives all usecase-sensitive arguments.  For this reason, it is particularlyimportant to use the <Directory>directive when attemptingto limit access to content in the filesystem, since thisdirective applies to any content in a directory, regardless ofhow it is accessed.  If you wish to assure that only lowercaseis used in URLs, you can use something like:
      RewriteEngine On
    RewriteMap lowercase int:tolower
    RewriteCond %{REQUEST_URI} [A-Z]
    RewriteRule (.*) ${lowercase:$1} [R,L]
  •   Apache for Windows contains the ability to load modules atruntime, without recompiling the server. If Apache is compilednormally, it will install a number of optional modules in the\Apache2.2\modulesdirectory. To activate these orother modules, the new LoadModuledirective must be used. For example, to activate the statusmodule, use the following (in addition to the status-activatingdirectives in access.conf):
      LoadModule status_module modules/mod_status.so

      Information on creatingloadable modulesis also available.
  •   Apache can also load ISAPI (Internet Server ApplicationProgramming Interface) extensions (i.e. internet serverapplications), such as those used by Microsoft IIS and otherWindows servers. More informationis available. Note that Apache cannotloadISAPI Filters.
  •   When running CGI scripts, the method Apache uses to findthe interpreter for the script is configurable using theScriptInterpreterSourcedirective.
  •   Since it is often difficult to manage files with nameslike .htaccessin Windows, you may find it useful tochange the name of this per-directory configuration file usingthe AccessFilenamedirective.
  •   Any errors during Apache startup are logged into theWindows event log when running on Windows NT. This mechanismacts as a backup for those situations where Apache cannot evenaccess the normally used error.logfile. You canview the Windows event log by using the Event Viewer applicationon Windows NT 4.0, and the Event Viewer MMC snap-in on newerversions of Windows.
    Note that there is no startup error logging onWindows 9x because no Windows event log exists on those operatingsystems.


Running Apache as a Service
  Apache can be run as a service on Windows NT. There is somehighly experimental support for similar behavior on Windows 9x.
  You can install Apache as a service automatically during theinstallation. If you chose to install for all users, theinstallation will create an Apache service for you. If you specifyto install for yourself only, you can manually register Apache as aservice after the installation. You have to be a member of theAdministrators group for the service installation to succeed.
  Apache comes with a utility called the Apache Service Monitor.With it you can see and manage the state of all installed Apacheservices on any machine on your network. To be able to manage anApache service with the monitor, you have to first install theservice (either automatically via the installation or manually).
  You can install Apache as a Windows NT service as follows fromthe command prompt at the Apache binsubdirectory:
  httpd.exe -k install

  If you need to specify the name of the service you want toinstall, use the following command. You have to do this if youhave several different service installations of Apache on yourcomputer.
  httpd.exe -k install -n "MyServiceName"

  If you need to have specifically named configuration files fordifferent services, you must use this:
  httpd.exe -k install -n "MyServiceName" -f "c:\files\my.conf"

  If you use the first command without any special parameters except-k install, the service will be called Apache2and the configuration will be assumed to be conf\httpd.conf.
  Removing an Apache service is easy. Just use:
  httpd.exe -k uninstall

  The specific Apache service to be uninstalled can be specified by using:
  httpd.exe -k uninstall -n "MyServiceName"

  Normal starting, restarting and shutting down of an Apacheservice is usually done via the Apache Service Monitor, by usingcommands like NET START Apache2and NET STOPApache2or via normal Windows service management. Beforestarting Apache as a service by any means, you should test theservice's configuration file by using:
  httpd.exe -n "MyServiceName" -t

  You can control an Apache service by its command line switches,too. To start an installed Apache service you'll use this:
  httpd.exe -k start

  To stop an Apache service via the command line switches, usethis:
  httpd.exe -k stop

  or
  httpd.exe -k shutdown

  You can also restart a running service and force it to rereadits configuration file by using:
  httpd.exe -k restart

  By default, all Apache services are registered to run as thesystem user (the LocalSystemaccount). TheLocalSystemaccount has no privileges to your networkvia any Windows-secured mechanism, including the file system, namedpipes, DCOM, or secure RPC. It has, however, wide privileges locally.
Never grant any network privileges tothe LocalSystemaccount! If you need Apache to be ableto access network resources, create a separate account for Apache asnoted below.
  You may want to create a separate account for running Apacheservice(s). Especially, if you have to access network resourcesvia Apache, this is strongly recommended.

  • Create a normal domain user account, and be sure tomemorize its password.
  • Grant the newly-created user a privilege of Log onas a serviceand Act as part of the operatingsystem. On Windows NT 4.0 these privileges are granted viaUser Manager for Domains, but on Windows 2000 and XP you probablywant to use Group Policy for propagating these settings. You canalso manually set these via the Local Security Policy MMC snap-in.
  • Confirm that the created account is a member of the Usersgroup.
  • Grant the account read and execute (RX) rights to all documentand script folders (htdocsand cgi-binfor example).
  • Grant the account change (RWXD) rights to theApache logsdirectory.
  • Grant the account read and execute (RX) rights to thehttpd.exebinary executable.
It is usually a good practice to grant the user the Apacheservice runs as read and execute (RX) access to the whole Apache2directory, except the logssubdirectory, where theuser has to have at least change (RWXD) rights.
  If you allow the account to log in as a user and as a service,then you can log on with that account and test that the account has theprivileges to execute the scripts, read the web pages, and thatyou can start Apache in a console window. If this works, and youhave followed the steps above, Apache should execute as a servicewith no problems.
Error code 2186is a good indication thatyou need to review the "Log On As" configuration for the service,since Apache cannot access a required network resource. Also, payclose attention to the privileges of the user Apache isconfigured to run as.
  When starting Apache as a service you may encounter an errormessage from the Windows Service Control Manager. For example,if you try to start Apache by using the Services applet in theWindows Control Panel, you may get the following message:
  Could not start the Apache2 service on \\COMPUTER
Error 1067; The process terminated unexpectedly.

  You will get this generic error if there is any problem withstarting the Apache service. In order to see what is really causingthe problem you should follow the instructions for Running Apachefor Windows from the Command Prompt.
  There is some support for Apache on Windows 9x to behave in asimilar manner as a service on Windows NT. It is highlyexperimental. It is not of production-class reliability,and its future is not guaranteed. It can be mostly regarded asa risky thing to play with - proceed with caution!
  There are some differences between the two kinds of servicesyou should be aware of:

  •   Apache will attempt to start and if successful it will runin the background. If you run the command
      httpd.exe -n "MyServiceName" -k start

      via a shortcut on your desktop, for example, then if theservice starts successfully, a console window will flash up butit immediately disappears. If Apache detects any errors on startupsuch as incorrect entries in the httpd.conf configuration file,the console window will remain visible. This will display an errormessage which will be useful in tracking down the cause of theproblem.
  •   Windows 9x does not support NET STARTorNET STOPcommands. You must control the Apacheservice on the command prompt via the -kswitches.
  •   Apache and Windows 9x offer no support for running Apacheas a specific user with network privileges. In fact, Windows 9xoffers no security on the local machine, either. This is thesimple reason because of which the Apache Software Foundationnever endorses use of a Windows 9x -based system as a publicApache server. The primitive support for Windows 9x exists onlyto assist the user in developing web content and learning theApache server, and perhaps as an intranet server on a secured,private network.
  Once you have confirmed that Apache runs correctly as aconsole application you can install, control and uninstall thepseudo-service with the same commands as on Windows NT. You canalso use the Apache Service Monitor to manage Windows 9xpseudo-services.


Running Apache as a Console Application
  Running Apache as a service is usually the recommended way touse it, but it is sometimes easier to work from the command line(on Windows 9x running Apache from the command line is therecommended way due to the lack of reliable service support.)
  To run Apache from the command line as a console application,use the following command:
  httpd.exe

  Apache will execute, and will remain running until it is stoppedby pressing Control-C.
  You can also run Apache via the shortcut Start Apache in Consoleplaced to Start Menu --> Programs --> Apache HTTP Server2.0.xx --> Control Apache Serverduring the installation.This will open a console window and start Apache inside it. If youdon't have Apache installed as a service, the window will remainvisible until you stop Apache by pressing Control-C in the consolewindow where Apache is running in. The server will exit in a fewseconds. However, if you do have Apache installed as a service, theshortcut starts the service. If the Apache service is runningalready, the shortcut doesn't do anything.
  You can tell a running Apache to stop by opening another consolewindow and entering:
  httpd.exe -k shutdown

  This should be preferred over pressing Control-C because thislets Apache end any current operations and clean up gracefully.
  You can also tell Apache to restart. This forces it to rereadthe configuration file. Any operations in progress are allowed tocomplete without interruption. To restart Apache, use:
  httpd.exe -k restart

Note for people familiar with the Unix version of Apache:these commands provide a Windows equivalent to kill -TERMpidand kill -USR1 pid. Thecommand line option used, -k, was chosen as a reminderof the killcommand used on Unix.
  If the Apache console window closes immediately or unexpectedlyafter startup, open the Command Prompt from the Start Menu -->Programs. Change to the folder to which you installed Apache, typethe command httpd.exe, and read the error message. Thenchange to the logs folder, and review the error.logfile for configuration mistakes. If you accepted the defaults whenyou installed Apache, the commands would be:
  c:
cd "\Program Files\Apache Software Foundation\Apache2.2\bin"
httpd.exe

  Then wait for Apache to stop, or press Control-C. Then enter thefollowing:
  cd ..\logs
more < error.log

  When working with Apache it is important to know how it willfind the configuration file. You can specify a configuration fileon the command line in two ways:

  •   -fspecifies an absolute or relative path toa particular configuration file:
      httpd.exe -f "c:\my server files\anotherconfig.conf"

      or
      httpd.exe -f files\anotherconfig.conf
  •   -nspecifies the installed Apache servicewhose configuration file is to be used:
      httpd.exe -n "MyServiceName"
  In both of these cases, the properServerRootshould be set inthe configuration file.
  If you don't specify a configuration file with -for -n, Apache will use the file name compiled into theserver, such as conf\httpd.conf. This built-in pathis relative to the installation directory. You can verify the compiledfile name from a value labelled as SERVER_CONFIG_FILEwheninvoking Apache with the -Vswitch, like this:
  httpd.exe -V

  Apache will then try to determine its ServerRootby trying the following, in this order:

  • A ServerRootdirectivevia the -Ccommand line switch.
  • The -dswitch on the command line.
  • Current working directory.
  • A registry entry which was created if you did a binaryinstallation.
  • The server root compiled into the server. This is /apacheby default, you can verify it by using httpd.exe -Vand looking for a value labelled asHTTPD_ROOT.
  During the installation, a version-specific registry key iscreated in the Windows registry. The location of this key dependson the type of the installation. If you chose to install Apachefor all users, the key is located under theHKEY_LOCAL_MACHINEhive, like this (the versionnumbers will of course vary between different versions of Apache:
  HKEY_LOCAL_MACHINE\SOFTWARE\Apache Software Foundation\Apache\2.2.2

  Correspondingly, if you chose to install Apache for the currentuser only, the key is located under the HKEY_CURRENT_USERhive, the contents of which are dependent of the user currentlylogged on:
  HKEY_CURRENT_USER\SOFTWARE\Apache Software Foundation\Apache\2.2.2

  This key is compiled into the server and can enable you to testnew versions without affecting the current version. Of course, youmust take care not to install the new version in the samedirectory as another version.
  If you did not do a binary install, Apache will in somescenarios complain about the missing registry key. This warning canbe ignored if the server was otherwise able to find itsconfiguration file.
  The value of this key is theServerRootdirectory whichcontains the confsubdirectory. When Apache starts itreads the httpd.conffile from that directory. Ifthis file contains a ServerRootdirective which contains a different directory from the oneobtained from the registry key above, Apache will forget theregistry key and use the directory from the configuration file. Ifyou copy the Apache directory or configuration files to a newlocation it is vital that you update theServerRootdirective in thehttpd.conffile to reflect the new location.


Testing the Installation
  After starting Apache (either in a console window or as aservice) it will be listening on port 80 (unless you changed theListendirective in theconfiguration files or installed Apache only for the current user).To connect to the server and access the default page, launch abrowser and enter this URL:
  http://localhost/

  Apache should respond with a welcome page and you should see"It Works!". If nothing happens or you get an error, look in theerror.logfile in the logssubdirectory.If your host is not connected to the net, or if you have seriousproblems with your DNS (Domain Name Service) configuration, youmay have to use this URL:
  http://127.0.0.1/

  If you happen to be running Apache on an alternate port, youneed to explicitly put that in the URL:
  http://127.0.0.1:8080/

  Once your basic installation is working, you should configure itproperly by editing the files in the confsubdirectory.Again, if you change the configuration of the Windows NT servicefor Apache, first attempt to start it from the command line tomake sure that the service starts with no errors.
  Because Apache cannotshare the same port withanother TCP/IP application, you may need to stop, uninstall or reconfigurecertain other services before running Apache. These conflictingservices include other WWW servers and some firewall implementations.


  Available Languages:  en | ko 

Copyright 2008 The Apache Software Foundation.
Licensed under the Apache License, Version 2.0.

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-219629-1-1.html 上篇帖子: C#调用Windows API详解(上) 下篇帖子: Windows下的Qt环境安装
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表