search
HomeBackend DevelopmentPHP Tutorial Windows XP平台上搭建PHP环境

Windows XP平台下搭建PHP环境

刚接触PHP那会儿,觉得搭建PHP的运行环境实在是太难,后来发现有现成的套装软件可用,高兴的不得了。最开始因为想建站,所以接触到了DedeCMS,织梦公司还蛮体贴,提供了一个和DedeCMS配套使用的PHP环境搭建套装软件。后来,又接触过像XAMPP,AppServ等软件,AppServ现在还在用。虽然这类套装软件十分好用,但是也存在明显的不足。套装软件里面包含软件的版本都是固定的,而且套装软件升级速度相当的慢,反观PHP的开发又是相当快速的,所以使用套装软件会造成新加入的PHP特性无法在当前环境下使用的问题。

?

随着对PHP的越来越熟悉,大致也知道了PHP脚本被解析的过程,所以有信心一步一步来搭建PHP运行环境。事先认为这事不会有什么难度,但在搭建过程中,还是碰到了一些问题,花费了一些时间。鉴于此,将搭建过程整理出来,贴在这里,以备日后参考。

?

第一步:准备工具

  1. 文本编辑器,如:EditPlus等。
  2. Web服务器,选择常用的Apache,如:httpd-2.0.64。
  3. DB服务器,如:MySQL-5.5.28。
  4. 已编译PHP,如:PHP-5.3.1。因为使用ISAPI的模式运行PHP,所以选择VC6线程安全版本。

第二步:开始安装

1,安装Apache

这个没什么好说的,一路next下去。有一点需要注意,最好选择custom的方式进行安装,这样可以将Apache安装目录存放在指定目录。完成后,进行简单测试。可以将一个网页文件(扩展名为html)或任何其它文件放在安装目录下的htdocs下,这是Web服务器默认的文档根目录。打开浏览器,在地址栏中输入:127.0.0.1或localhost,回车。如果能看到刚才创建的文件,说明Web服务器已正常启动。


2,安装PHP

为了将PHP纳入Apache的控制之下,需要完成如下工作。首先,将编译过的PHP目录文件放在与Apache安装目录同级的目录下,这时候Apache还不知道PHP的存在。接着,进入Apache安装目录下,在目录conf下找到httpd.conf文件,这是Apache的配置文件。用Editplus打开该文件,在LoadModule部分最后,加入两行内容。大致形式为:

LoadModule php5_module D:/localhost/php5/php5apache2.dll	
PHPIniDir "D:/localhost/php5/php.ini"

第一行表示PHP作为Apache的一个模块被使用,第二行表示PHP配置文件的绝对路径。需要说明两点:一是,第一行中php5apache2.dll文件由Apache的版本决定,这里因为Apache的版本是2.0.*,所以加载php5apache2.dll文件。如果使用2.2.*系列,则应该加载php5apache2_2.dll文件。二是,第二行中的php.ini文件在PHP目录中是没有的,只有php.ini-development和php.ini-production这两个文件,需要将其中之一重命名为php.ini,建议选择production版本,保证线上线下一致性。接着,为了告诉Apache应该将何种类型的文件交给Zend Engine解析,需要为这类文件指定一个特定扩展名。在文件最后,加入如下命令:

<IfModule mod_php5.c>
  AddType application/x-httpd-php .php
</IfModule>

然后打开php.ini,需要修改几处配置。找到“; extension_dir = "ext"”这一行配置,这里是PHP扩展的路径,去掉注释符号“;”,然后填写正确路径就好了,如:extension_dir = "D:/localhost/php5/ext"。接着,找到如下两行命令:

;extension=php_mysql.dll
;extension=php_mysqli.dll

去掉前面的分号,保存文件,重启Apache。不出意外,这时PHP就能用了。为了测试,这时可以在htdocs目录下创建扩展名为php的文件,通过浏览器访问该文件,看文件是否被成功解析。


3,安装MySQL

一路next,使用自定义安装(即:custom),将MySQL安装目录放在与Apache和PHP同级目录。有一个地方需注意,如果本地在之前安装过MySQL,那么会有一些数据被写入注册表,即使卸载MySQL时,这些信息也不会被删除,这样当重新安装MySQL时,就会出错。因此,在安装MySQL前,首先确保注册表里没有残留的MySQL信息,这些信息大致在以下三处:

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Eventlog\Application\MySQL
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet002\Services\Eventlog\Application\MySQL
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application\MySQL

如果存在,将它们删除即可。


第三步:使Apache和MySQL全局可用

为了方便在DOS下使用Apache和MySQL,可以将Apache和MySQL安装目录下的二进制目录路径加入到系统变量Path中。具体操作为:我的电脑->属性->高级->环境变量->选中系统变量Path->编辑->加入Apache和MySQL下二进制目录的绝对路径(注意用分号隔开)->保存。完成后(不需重启电脑),即可在DOS下直接运行Apache和MySQL安装目录下二进制目录下的可执行文件了。


第四步:修改配置文件

为了使PHP程序的性能最优,常常需要根据具体的项目要求,对开发环境做一些配置层面的优化。PHP环境中有两个最重要的配置文件,一个是php.ini,另一个是httpd.conf。前者是PHP的全局配置文件,用来控制PHP的行为,后者是Apache的配置文件,控制服务器的表现。例如:Web服务器默认文档根目录位于Apache安装目录下htdocs目录下,为了便于开发和维护,常常需要将此配置成和Apache,MySQL及PHP同级目录中的某一目录,如www目录。为了完成这个工作,需要修改httpd.conf文件,找到“DocumentRoot "C:/AppServ/Apache2/htdocs"”这一行命令,将其修改为“DocumentRoot "C:/AppServ/www"”,保存文件,重启服务器即可。


(完)

?

Statement
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
How do you set the session cookie parameters in PHP?How do you set the session cookie parameters in PHP?Apr 22, 2025 pm 05:33 PM

Setting session cookie parameters in PHP can be achieved through the session_set_cookie_params() function. 1) Use this function to set parameters, such as expiration time, path, domain name, security flag, etc.; 2) Call session_start() to make the parameters take effect; 3) Dynamically adjust parameters according to needs, such as user login status; 4) Pay attention to setting secure and httponly flags to improve security.

What is the main purpose of using sessions in PHP?What is the main purpose of using sessions in PHP?Apr 22, 2025 pm 05:25 PM

The main purpose of using sessions in PHP is to maintain the status of the user between different pages. 1) The session is started through the session_start() function, creating a unique session ID and storing it in the user cookie. 2) Session data is saved on the server, allowing data to be passed between different requests, such as login status and shopping cart content.

How can you share sessions across subdomains?How can you share sessions across subdomains?Apr 22, 2025 pm 05:21 PM

How to share a session between subdomains? Implemented by setting session cookies for common domain names. 1. Set the domain of the session cookie to .example.com on the server side. 2. Choose the appropriate session storage method, such as memory, database or distributed cache. 3. Pass the session ID through cookies, and the server retrieves and updates the session data based on the ID.

How does using HTTPS affect session security?How does using HTTPS affect session security?Apr 22, 2025 pm 05:13 PM

HTTPS significantly improves the security of sessions by encrypting data transmission, preventing man-in-the-middle attacks and providing authentication. 1) Encrypted data transmission: HTTPS uses SSL/TLS protocol to encrypt data to ensure that the data is not stolen or tampered during transmission. 2) Prevent man-in-the-middle attacks: Through the SSL/TLS handshake process, the client verifies the server certificate to ensure the connection legitimacy. 3) Provide authentication: HTTPS ensures that the connection is a legitimate server and protects data integrity and confidentiality.

The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

See all articles

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.