在windows上配置Apache和PHP

来源:互联网 发布:南京大学网络教育安徽 编辑:程序博客网 时间:2024/05/05 17:31

此篇文章转自:http://www.phpbuilder.com/board/showthread.php?s=7d54007d5da1985b127fc4bb54d1fb8b&t=10341740
因为是自己看,就不翻译了。 

This guide is for any user that is running Windows (any version) and wants to run the Apache Web Server with php5.
  1. Download Required Files
    • Apache
      Go to Apache Download Section and download Apache. I'm using Apache version 2.2.8 for this tutorial.
    • PHP Files
      Go to PHP.net and download the Windows zip package 5.2.x (or whatever the current release is). Do NOT download the executable files.
  2. Install Apache
    • Run the Apache Install program [Image]
    • Input "localhost" for the network domain, "localhost" for the servername, and "root@localhost", or any email address you want, for the administrator's email address. Also keep the default selection of running apache for all users on port 80. [Image]
    • Choose a "Custom Install" option [Image]
    • Customize the settings as you feel fit. Most of them can be left as default though.
    • Install the Apache Webserver on your system
    • Make sure Apache is Running. You should see the feather logo in the system tray if you are running the ApacheMonitor program (which is the default) [Image]
  3. Set Up PHP
    • Unzip the PHP files to a directory [Image]
    • Rename php.ini-recommended to php.ini
    • Edit php.ini file as needed
      Run through the php.ini file and change any items you want. I use the error level E_ALL & E_STRICT in php5. You can change them to what you want. I also load a bunch of modules. There is no "master" setting, so fiddle with it until you get what you need / want.

      NOTE: You should set a default timezone in your php.ini file. For a listing of default timezones, please refer to the PHP manual's Timezones Page
    • Copy php5 folder to its permanent spot [Image]
      You can put this anywhere you please. Most people tend to put it at the root of C: "C:/php". You can put it wherever you like. Since PHP is a program, I'm going to stick it in "C:/Program Files (x86)".

      NOTE: I have an x86_64 system so I have both C:/Program Files and C:/Program Files (x86). There is no special difference between the directories in this case.
  4. Create httpd-php.conf file
    • Create a new file in <Apache Root>/conf/extra/ called "httpd-php.conf"
    • Inside the new file, put either block for running PHP as a CGI or running it as a Module:
      Code:
      # PHP 5 as CGI<Directory "C:/your/path/to/php5/">Options +ExecCGIOrder allow,denyAllow from all</Directory>ScriptAlias /php5/ "C:/Program Files (x86)/Web Server/php5/"AddHandler application/x-httpd-php5 .php5Action application/x-httpd-php5 "/php5/php-cgi.exe"## PHP 5 as ModuleLoadModule php5_module "C:/Program Files (x86)/Web Server/php5/php5apache2_2.dll"<IfModule php5_module>AddType application/x-httpd-php .php .php3 .php5AddType application/x-httpd-php-source .phpsPHPIniDir "C:/Program Files (x86)/Web Server/php5"</IfModule>
    • Edit the spots in red to reflect the proper path to php5
      NOTE: If you're running Apache 2.0.x, then use php5_apache2.dll. If you're running Apache 2.2.x, then use php5_apache2_2.dll
    • Save the file
    • Edit httpd.conf and add this line (includes previously created file):
      Code:
      Include conf/extra/httpd-php.conf
  5. Add PHP to path of Windows
    • Right click on "My Computer" and select "Properties" [Image]
    • Vista Users:
      Click on the link in the left that says "Advanced System Settings" [Image]
    • Open the "Advanced" tab in the System Properties box
    • Click on the button which says "Environment Variables..." in the lower right hand corner [Image]
    • Edit the "Path" variable in the "System Variables" section [Image]
      You need to add the paths to your PHP folder separated by a semi-colon ";". For example, my addition looked like:
      ;C:/Program Files (x86)/Web Server/php5
  6. Restart the Computer
    It's best to restart the computer because windows needs to update it's Path variable since we edited it. It's optional, but until you do, some extensions may not load properly.

That's it. By this time you should have a working copy of php5 on your system for testing. To test this, you can simply create a new document called info.php and in it put the following contents:
PHP Code:
<?php phpinfo(); ?>
Now save this file to the DocumentRoot which you defined in your httpd.conf file above (by default it's "<Apache Root>/htdocs") and then browse to http://localhost/info.php and you should see a slew of information about PHP and your system spit out at you [Image]


[ NOTE ] I removed the part about php4 concurrency because php4 is reaching EOL (End of Life) and as such, you should not be running it. You should be running php5 from now on. If you still need help running php4 concurrently, feel free to ask me; however, I won't support php4 past it's life.

原创粉丝点击