search
HomeBackend DevelopmentPHP TutorialWindows 7 上PHP环境搭建

Windows 7 下PHP环境搭建

??? 有一段时间没有写东西了,这几天弄了点PHP的东西,现在给大家分享个PHP的运行环境搭建,

虽然网上有很多LMAP和WMAP一类的一键安装工具,但是我认为,还是自己动手,才能理解这门语言的运行环境,在以后的开发中更游刃有余。

因为在Linux中开发用得比较少,我下面就本机的Windows 7 系统下安装PHP运行环境给大家做个介绍,分享一下我的成果。

?首先,我们要准备好相关的运行环境安装包,我用的是PHP5.3 + Apache2.2+ MySQL5.5

下载地址分别是:

?

?PHP:http://windows.php.net/downloads/releases/php-5.4.7-Win32-VC9-x86.zip

Apache:http://mirror.bjtu.edu.cn/apache//httpd/binaries/win32/httpd-2.2.22-win32-x86-no_ssl.msi

MySQL:http://cdn.mysql.com/Downloads/MySQL-5.5/mysql-5.5.28-win32.msi

?

这里我仅拿本人PC进行配置,路径是我自己的本机路径,各位可以按照自己实际安装路径进行配置。

?

?

一、我们先来配置Apache(安装步骤就省略了,这个不难)

?

?1、找到Apache安装目录下的conf文件夹,我这里是C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf,找到httpd.conf文件。这个是Apache的核心配置文件,我们需要增加以下几行:

?

#加载PHP处理模块
LoadModule php5_module "C:/php/php5apache2_2.dll"?
#添加PHP后缀的处理
AddType application/x-httpd-php .php???
PHPIniDir "C:/php"

?

看#号我写的注释大家应该也明白了,先是要加载PHP的处理模块,这样访问Apache的时候它才会调用PHP进行请求处理。

如果在PHP安装包中找不到php5apache2_2.dll,那么说明你下的PHP版本不对

我们在PHP官网看到,PHP分两个版本,一个是VC9 x86 Non Thread Safe ,一个是VC9 x86 Thread Safe ,就是说一个带Apache模块,一个不带Apache模块,这里一定要注意选择带Apache的ZIP包。

?

然后第二句是添加PHP后缀的处理,表示当Apache接收到内容头为application/x-httpd-php 或后缀为.php的文件时,将交给PHPIniDir 下的相关进行处理,这样我们的PHP文件就能通过Apache然后让PHP进行编译了。

?

2、将DocumentRoot 与 Directory 目录均改为网页目录所在路径,其实就是自定义一个工作空间,以后开发PHP都把项目放到这个工作空间下,浏览器访问本地IP就可以浏览所有的PHP项目了,非常方便。

我这里改为

?? DocumentRoot "D:/PHPWorkspace"?

??

??

?

? 大家按自己实际情况改。

?

OK,Apache方面配置完成。

?

二、然后来配置PHP:

?

1、 php.ini

?

将下载好的PHP源包解压到C盘PHP下(这个可以自己放位置,但建议不要放到太深层的目录以及目录名不能包含中文和空格,这可能会让你郁闷到抓狂)。

?

然后找到PHP目录下的php.ini-development文件,这里有两个相似的文件,一个是php.ini-development,一个是php.ini-production,从文件名我们也可以看出来,一个是适合开发用的,一个适合项目发布用的,所以,我们修改php.ini-development这个文件,直接把文件名php.ini后面的删掉(最好先备份),这样就变成了php.ini,嘿嘿,是不是很熟悉呢,对的,我们要的就是这个配置文件。接着打开它,我们要修改的一个是

?

;extension_dir="ext"

?

查找到这句,然后改成

;extension_dir = "C:/php/ext"

?

并且把前面作注释用的? ;?? 号 去掉,就变成了这样

?extension_dir = "C:/php/ext"

?

即ext的本地绝对路径,这个按照自己的实际情况改。

然后还有一个就是让PHP支持MYSQL,很简单,找到??

;extension=php_mysql.dll?

这句,把 ;? 号去掉就OK了。这个不用解释了吧。

?

?

?三、MYSQL(安装步骤省略)

?

前面在PHP.ini 中我们已经配置好了允许PHP使用MYSQL,这里就不需要任何配置了

?,只要保证MYSQL是能正常使用的就OK了

?

四、调试

?

我们在之前定义的工作空间下新建个PHP文件,内容是:

?

$link=mysql_connect('localhost','root','admin');
if(!$link) echo "失败!";
else echo "成功!";
mysql_close();
?>

相信懂PHP的人都看得懂这句话,一句数据库接连代码,然后我们保存,浏览器输入127.0.0.1访问一下,

就可以看到我们刚才新建的PHP文件,点击链接进去如果输出成功, 那么我们的环境就配置成功了。

?

五、常见问题:

?

1,如果运行PHP文件时没有看到网页而是出现下载提示框 ,那么就说明你的PHP文件没有被Apache识别并交给PHP进行处理,这个问题出在Apache的httpd.conf文件中的那三句代码。

2、如果PHP文件能看到网页内容但是显示

????? Fatal error: Call to undefined function mysql_connect() in D:\PHPWorkspace\test.php on line 2

????

???? 那么就表示你的PHP文件已经能被编译,Apache方面已经正常了,问题出在php.ini,没有允许使用MYSQL数据库或是ext目录没有被定位到,即?extension_dir = "C:/php/ext"的问题。

3、记得修改一般修改配置文件的时候都要重启Apache让更改生效。

?

?

?

由于本人也是正在学习的过程中,写的文章技术含量不高,但能记录我学习旅途上的点点滴滴,这些东西仅适合于新手,高手见笑了。??????????????????????????????????????????????

???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????By 小敏

?

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
Explain the concept of a PHP session in simple terms.Explain the concept of a PHP session in simple terms.Apr 26, 2025 am 12:09 AM

PHPsessionstrackuserdataacrossmultiplepagerequestsusingauniqueIDstoredinacookie.Here'showtomanagethemeffectively:1)Startasessionwithsession_start()andstoredatain$_SESSION.2)RegeneratethesessionIDafterloginwithsession_regenerate_id(true)topreventsessi

How do you loop through all the values stored in a PHP session?How do you loop through all the values stored in a PHP session?Apr 26, 2025 am 12:06 AM

In PHP, iterating through session data can be achieved through the following steps: 1. Start the session using session_start(). 2. Iterate through foreach loop through all key-value pairs in the $_SESSION array. 3. When processing complex data structures, use is_array() or is_object() functions and use print_r() to output detailed information. 4. When optimizing traversal, paging can be used to avoid processing large amounts of data at one time. This will help you manage and use PHP session data more efficiently in your actual project.

Explain how to use sessions for user authentication.Explain how to use sessions for user authentication.Apr 26, 2025 am 12:04 AM

The session realizes user authentication through the server-side state management mechanism. 1) Session creation and generation of unique IDs, 2) IDs are passed through cookies, 3) Server stores and accesses session data through IDs, 4) User authentication and status management are realized, improving application security and user experience.

Give an example of how to store a user's name in a PHP session.Give an example of how to store a user's name in a PHP session.Apr 26, 2025 am 12:03 AM

Tostoreauser'snameinaPHPsession,startthesessionwithsession_start(),thenassignthenameto$_SESSION['username'].1)Usesession_start()toinitializethesession.2)Assigntheuser'snameto$_SESSION['username'].Thisallowsyoutoaccessthenameacrossmultiplepages,enhanc

What are some common problems that can cause PHP sessions to fail?What are some common problems that can cause PHP sessions to fail?Apr 25, 2025 am 12:16 AM

Reasons for PHPSession failure include configuration errors, cookie issues, and session expiration. 1. Configuration error: Check and set the correct session.save_path. 2.Cookie problem: Make sure the cookie is set correctly. 3.Session expires: Adjust session.gc_maxlifetime value to extend session time.

How do you debug session-related issues in PHP?How do you debug session-related issues in PHP?Apr 25, 2025 am 12:12 AM

Methods to debug session problems in PHP include: 1. Check whether the session is started correctly; 2. Verify the delivery of the session ID; 3. Check the storage and reading of session data; 4. Check the server configuration. By outputting session ID and data, viewing session file content, etc., you can effectively diagnose and solve session-related problems.

What happens if session_start() is called multiple times?What happens if session_start() is called multiple times?Apr 25, 2025 am 12:06 AM

Multiple calls to session_start() will result in warning messages and possible data overwrites. 1) PHP will issue a warning, prompting that the session has been started. 2) It may cause unexpected overwriting of session data. 3) Use session_status() to check the session status to avoid repeated calls.

How do you configure the session lifetime in PHP?How do you configure the session lifetime in PHP?Apr 25, 2025 am 12:05 AM

Configuring the session lifecycle in PHP can be achieved by setting session.gc_maxlifetime and session.cookie_lifetime. 1) session.gc_maxlifetime controls the survival time of server-side session data, 2) session.cookie_lifetime controls the life cycle of client cookies. When set to 0, the cookie expires when the browser is closed.

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

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.