search
HomeBackend DevelopmentPHP Tutorial Windows 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
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.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

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

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools