Home Backend Development PHP Tutorial Windows平台上PHP环境配置之PHP安装篇

Windows平台上PHP环境配置之PHP安装篇

Jun 13, 2016 am 10:55 AM
apache cgi mysql php

Windows平台下PHP环境配置之PHP安装篇

原文:http://www.phpiask.com/?p=43 入门很不错

在本系列的上两篇文章:Mysql的安装和配置,Apache的安装中我们安装了数据库和Web服务器,转眼间我们就说到了我们的重点PHP。
至于PHP为什么叫做PHP,战地至少听说过两种说法,但是这个不重要了。就像谢逊有时候被人叫做金毛狮王一样,我们知道他就是他就行了。

第一步当然还是下载,下载地址在这里:http://www.php.net
记住这个是net域名不是com它们完全不是一回事儿。

点击页面上的download链接,进入下载页面,找到Windows Binaries 标题,并找到 PHP 5.0.4 zip package 的链接,下载它。不要想当然,我们不下载那个Installer文件,因为它不包含Mysql扩展,如果下载他来安装的会有一些麻烦——其实也可以解决。不过我们还是下载那么个zip包吧。

下载完成后,当然是解压缩——解压到D:\php下吧;
找到一个叫php.ini-recommended 的文件,复制这个文件到Apache的目录,改个名字——。这个名字应该修改为:php.ini。

注意:Apache查找php.ini文件的顺序是这样的:

先是apache的目录,然后系统目录,再到path指定的目录,所以放在Apache的目录下最容易被找到,呵呵……

就这样了PHP安装完成了,虽然他还不能和Apache一起工作,但是他已经完成安装了。真的!

不能工作安装它有个鸟用啊?——不要愤怒兄弟,战地还没有说完,下边咱们就把Apache和PHP糅合到一起,让他们一起上路。

还记得咱们安装Apache目录不?我记得!在D:\apache
打开这个目录找到conf文件夹打开,找到一个叫httpd.conf的文件,这个就是Apache的设置文件,一定要记住哦,以后用的地方多着呢。用记事本打开这个文件。

搜索 ScriptAlias,应该看到类似如下的内容:

#
# ScriptAlias: This controls which directories contain server scripts.
# ScriptAliases are essentially the same as Aliases, except that
# documents in the realname directory are treated as applications and
# run by the server when requested rather than as documents sent to the client.
# The same rules about trailing “/” apply to ScriptAlias directives as to
# Alias.
#
ScriptAlias /cgi-bin/ “D:/apache/cgi-bin/”

对于 /cgi-bin/来说,此条目告诉 Apache 如何处理任何包含 cgi-bin 目录的 URL。例如,如果您请求了 http://www.phpiask.com/cgi-bin/mail-me,Apache 不会在 cgi-bin 目录中查找一个名为 mail-me 的文件。相反,ScriptAlias 命令会告诉 Apache 查看另一个目录 —— 在本例中,这个目录是”D:/apache/cgi-bin/”。这是至关重要的,因为您不会希望将脚本存储在可通过 Web 访问的目录中。因此,您需要为 PHP 脚本添加一个条目。如下所示:

ScriptAlias /php/ “D:/php/”

接下来,您需要告诉 Apache 以 .php 结尾的文件必须作为应用程序处理;尤其是,您希望为 PHP 文件分配一个类型,然后您就能够指示 Apache 以特定方式处理它们。在 ScriptAlias 条目下,添加以下条目:

AddType application/x-httpd-php .php
仅仅这些还不够,回头看看吧,我们只告诉了Apache一个目录映射和遇到以php为扩展名的文件当作什么处理,我们还没有告诉他,这个处理到底有谁来做是不是?就像 死啦死啦(《我的团长我的团》的团长)说“我们遇到一只兔子,应该吃掉”,他没有说应该被谁吃掉——这会很麻烦。
现在我们来指定,遇到php扩展名的文件到底应该由谁来处理:

Action application/x-httpd-php “/php/php-cgi.exe”

看到了吧?我们直接.php类型的扩展名文件交给我php/目录下的php-cgi.exe文件来处理了,你可能会问是哪个php目录,看到了我们第一个设置没有:

ScriptAlias /php/ “D:/php/”
这个就是目录映射文件,Apache会知道/php/目录就是指D:/php/,Apache很聪明是不是?呵呵呵……

设置索引文件名称,就是默认的首页文件,搜索DirectoryIndex,并做如下设置:

DirectoryIndex index.html index.html.var index.php

重新启动Apache,控制面板->服务->找到Apache,重新启动
到此为止,你的Web服务器基本完成了,Apache也能运行.php程序了,咱们来看看吧。编写第一个PHP文件phpinfo.php,内容是:
phpinfo();
?>
放到apache目录的htdocs文件夹下,输入http://localhost/phpinfo.php执行他,你就会看到一个页面,这个页面包含了所有的PHP设置信息,包括所使用的php.ini的位置等。

还有一个问题,就是PHP如何连接到Mysql的问题,我们也在这里解决了吧。

找到PHP的设置文件D:/apache/php.ini,这个刚才说了在apache的安装目录下,打开搜索extension_dir,设置为
extension_dir = “D:/php/ext/” 扩展文件的存储路径,
搜索extension=php_mysql.dll
去掉前面的“;”,启用Mysql扩展

再次重新启动Apache,重新http://localhost/phpinfo.php 如果还算顺利的话,你会在这个页面上看到Mysql的一个模块,仔细看看吧,一定会有的。

好了到此为止,Apache、Mysql、PHP我们都安装了,也整合了,可以动手编程了!
这个安装过程只是诸多安装方法的一种,一种就够了其实。当然关于PHP和Apache的设置其实还有很多话要说,请关注本站随后推出的php.ini设置全攻略 和 httpd.conf设置全攻略。

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

Video Face Swap

Video Face Swap

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

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)

PHP's Purpose: Building Dynamic Websites PHP's Purpose: Building Dynamic Websites Apr 15, 2025 am 12:18 AM

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP: Handling Databases and Server-Side Logic PHP: Handling Databases and Server-Side Logic Apr 15, 2025 am 12:15 AM

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP: An Introduction to the Server-Side Scripting Language PHP: An Introduction to the Server-Side Scripting Language Apr 16, 2025 am 12:18 AM

PHP is a server-side scripting language used for dynamic web development and server-side applications. 1.PHP is an interpreted language that does not require compilation and is suitable for rapid development. 2. PHP code is embedded in HTML, making it easy to develop web pages. 3. PHP processes server-side logic, generates HTML output, and supports user interaction and data processing. 4. PHP can interact with the database, process form submission, and execute server-side tasks.

Choosing Between PHP and Python: A Guide Choosing Between PHP and Python: A Guide Apr 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 Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 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.

How to start mysql by docker How to start mysql by docker Apr 15, 2025 pm 12:09 PM

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

PHP vs. Python: Use Cases and Applications PHP vs. Python: Use Cases and Applications Apr 17, 2025 am 12:23 AM

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

See all articles