Home php教程 php手册 Windows Apache2.2.11及Php5.2.9-1的安装与配置方法

Windows Apache2.2.11及Php5.2.9-1的安装与配置方法

Jun 13, 2016 pm 12:23 PM
windows and Install method use of Configuration

因为pharmar用的是Mcafee的杀毒软件,要求所有程序均要安装于Program Files,所以这些文件均放于D:\Program Files下便于管理。Mcafee写防护规则时好运用。
 Apache的安装与配置

打开apache官方网站 http://archive.apache.org/dist/httpd/binaries/win32/ 或者镜像网站 http://apache.mirror.phpchina.com/httpd/binaries/win32/,下载里面的apache_2.2.11-win32-x86-no_ssl.msi安装文件。其中,同一版本有两种类型:no_ssl和openssl,openssl多了个ssl安全认证模式,它的协议是HTTPS而不是HTTP,这就是带有SSL的服务器与一般网页服务器的区别了。一般情况下,我们下载no_ssl版本的就ok了。

下载好apache安装文件后,点击安装,在连续3次next后,将进入server information配置界面,要求输入network domain、server domain和网站管理员的邮箱地址,普通用户可以随便按照格式填一下就行了。再次按Next后,出现选择安装路径的界面,默认的路径比较长,pharmar把安装路径修改为:“D:\Program Files\Apache\”,继续安装,直到完成。

安装完毕,apache就自动启动,可以测试apache是否成功启动。在浏览器地址栏里输入:http://localhost/或http://127.0.0.1/,如果出现“It works.”,那么恭喜你,apache已经成功安装了;同时在电脑右下角的任务栏里有一个绿色的apache服务器运行图标。

apache还有一个配置文件:httpd:conf 需要配置,以便php运行。位置为:D:\Program Files\Apache\conf目录里。打开httpd:conf:
1)、查找“DocumentRoot”,这里是指定主页放置的目录。默认是:“D:\Program Files\Apache\htdocs”,你可以使用默认的目录,也可以自己定义一个,如:“D:/PHP”。注意:目录末尾不要加“/”。
2)、查找“DirectoryIndex”,这里是默认首页文件名,可以在index.html 的后面加入index.php等。每种类型之间都要留一个空格。
3)、查找

Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all

修改为:

Options FollowSymLinks
AllowOverride None
Order deny,allow
allow from all

如果不改这里的话,可能会出现 You don't have permission to access / on this server. 这样的错误提示,尤其在改变了默认主页的路径后。

注意:每次修改httpd:conf文件后,都要重启apache服务器。另外,如果你的win32系统上同时也运行iis服务器,那么就要先停止iis服务器的运行,然后再启动apache,否则apache服务器无法启动。

Php的安装与配置方法

首先从php的官方网站http://www.php.net/downloads.php 下载windows版本的,有两种版本:PHP 5.2.9 zip package和PHP 5.2.9 installer,目前最新版本就是5.3.0,pharmar使用的是5.2.9版本。PHP 5.2.9 installer为自动安装方式,虽然比较自动化,但在很多方面受到限制,因此pharmar不推荐使用这种方式,下面介绍PHP 5.2.9 zip package压缩包方式下的手动安装。

1)、将PHP的压缩包zip解压到一个目录下,推荐:“C:/PHP”,pharmar的是D:\Program Files\Php。
2)、将PHP目录(D:\Program Files\Php)下的 php.ini-dist 文件重命名为 php.ini,PHP的配置文件就是它,修改以下几个地方,修改好后把 php.ini 文件复制到 C:\WINDOWS\ 目录里:
extension_dir="D:\Program Files\Php\ext" ,指向php文件夹下放置“php_*.dll”文件的路径。PHP4和PHP5的路径在这里有所区别。
doc_root="D:\PHP" ,指向前面apache设置的首页位置;
default_charset="gb2312" ,修改默认字符集,这里,如果前面有分号“;”,去掉这个分号;
register_globals=Off 改为 register_globals=On ,使传递全局变量有效;
extension=php_dba.dll 如果前面有分号,取消分号,以下同;
extension=php_dbase.dll
extension=php_gd2.dll GD库做图,一般用于图形验证码;
extension=php_mysql.dll 用于连接MYSQL数据库;
3)、将PHP目录下的 php5ts.dll 文件拷贝到 C:\WINDOWS\system32 目录。
4)、最后修改 Apache 的 httpd.conf 文件。在该文件的末尾添加如下2行,表示以模块方式安装PHP进入Apache:
LoadModule php5_module D:/Program Files/Php/php5apache2_2.dll
AddType application/x-httpd-php .php

注意:第一行的目录路径要更新为当前版本的apache动态链接库,比如这里我使用的是apache2.2.11版本和php5.2.9,那这个文件必须是php5apache2_2.dll,而不能是php5apache.dll、php5apache2.dll等。第二行为php脚步的后缀。
php4版中,需要添加一行 AddType mod_php4.c,而在php5中,就不需要这样的一行 AddType mod_php5.c了,php5已经集成,否则 apache 启动不了。

以上就完成了apache和php的配置过程了,重启apache。在服务器的默认目录“D:\Program Files\Apache\htdocs”里新建文件index.php,写上如下代码:
phpinfo();
?>
在浏览器地址栏里输入 http://127.0.0.1/ 或 http://localhost/ ,你就会看到php版本信息了。到此为止,php和apache就已经成功的安装了。

这里有个细节:apache的配置文件 httpd.conf 中的目录分割符号是“/”,而 PHP 的配置文件 php.ini 里的目录则要求是反斜线 “ \”,不要搞混了哦。

MYSQL的安装就简单了。到官方网站 http://dev.mysql.com/downloads/mysql/5.0.html,下载windows平台下的 mysql ,选择 Windows ZIP/Setup.EXE (x86) 最新版本是 5.0.77 ,下载即可。直接安装,安装完成后,可以进入配置向导,设置mysql数据库密码。一切OK。
关于mysql的安装与配置见:phpMyAdmin安装配置方法和问题解决

pharmar安装过程中遇到的错误:
在 Windows 下安装 PHP 后 Apache 出现 LoadModule takes two arguments 的错误,这个主要原因就是httpd.conf中的这句:
LoadModule php5_module D:\Program Files\PHP\php5apache2_2.dll
解释程序把Program Files中的空格当成了两个参数的分隔符号,因此语句中不能出现空格。在网上找了半天也没找到解决方法,最后用一级目录符号才解决问题,改成如下:
LoadModule php5_module ../php/php5apache2_2.dll
因为apache安装在D:\Program Files\Apache\目录下,PHP安装在D:\Program Files\php\,因此../就表示D:\Program Files\目录,这个终于搞定了,希望大家在安装与配置过程中多动动脑筋总会有办法的。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Four ways to implement multithreading in C language Four ways to implement multithreading in C language Apr 03, 2025 pm 03:00 PM

Multithreading in the language can greatly improve program efficiency. There are four main ways to implement multithreading in C language: Create independent processes: Create multiple independently running processes, each process has its own memory space. Pseudo-multithreading: Create multiple execution streams in a process that share the same memory space and execute alternately. Multi-threaded library: Use multi-threaded libraries such as pthreads to create and manage threads, providing rich thread operation functions. Coroutine: A lightweight multi-threaded implementation that divides tasks into small subtasks and executes them in turn.

Can I install mysql on Windows 7 Can I install mysql on Windows 7 Apr 08, 2025 pm 03:21 PM

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

Where to download Python .whl files under Windows? Where to download Python .whl files under Windows? Apr 01, 2025 pm 08:18 PM

Python binary library (.whl) download method explores the difficulties many Python developers encounter when installing certain libraries on Windows systems. A common solution...

How to speed up the loading speed of PS? How to speed up the loading speed of PS? Apr 06, 2025 pm 06:27 PM

Solving the problem of slow Photoshop startup requires a multi-pronged approach, including: upgrading hardware (memory, solid-state drive, CPU); uninstalling outdated or incompatible plug-ins; cleaning up system garbage and excessive background programs regularly; closing irrelevant programs with caution; avoiding opening a large number of files during startup.

How to efficiently read Windows system logs and get only information from the last few days? How to efficiently read Windows system logs and get only information from the last few days? Apr 01, 2025 pm 11:21 PM

Efficient reading of Windows system logs: Reversely traverse Evtx files When using Python to process Windows system log files (.evtx), direct reading will be from the earliest...

Why can't my code get the data returned by the API? How to solve this problem? Why can't my code get the data returned by the API? How to solve this problem? Apr 01, 2025 pm 08:09 PM

Why can't my code get the data returned by the API? In programming, we often encounter the problem of returning null values ​​when API calls, which is not only confusing...

c What are the differences between the three implementation methods of multithreading c What are the differences between the three implementation methods of multithreading Apr 03, 2025 pm 03:03 PM

Multithreading is an important technology in computer programming and is used to improve program execution efficiency. In the C language, there are many ways to implement multithreading, including thread libraries, POSIX threads, and Windows API.

See all articles