Table of Contents
安装Apache:
安装PHP环境
安装MySQL
安装PHPMyAdmin数据库操作工具
附:
Home Backend Development PHP Tutorial windows下PHP环境的搭建

windows下PHP环境的搭建

Jun 23, 2016 pm 01:28 PM

windows下PHP环境的搭建

初学PHP,环境配置各种蛋疼。首先,我要表示对度娘搜索结果的失望,以及,墙实在是高,有三层楼那么高。如果可能的话尽可能上google搜索相关技术文档。
接下来,步入正题。windows下的PHP环境简称WAMP(windows+Apache+MySQL+PHP)。那么我们环境的搭建就是安装Apache+MySQL+PHP并配置相关变量。
首先,贴出下载方式:
Apache:http://httpd.apache.org/docs/current/platform/windows.html#down;
MySQL:http://dev.mysql.com/downloads/mysql/5.0.html#win32
PHP:http://windows.php.net/download#php-5.6

安装顺序按照Apache--->PHP--->MySQL进行。

安装Apache:

下载Apache,上面给出的地址是免安装版,用命令行配置可以更加清晰地看到错误信息,方便于调试。

进入下载链接之后有如上的几个下载地址,我们选择第一个。点击进入,就可以看到最终的下载位置,按你的操作系统选择下载32位或64位:

D盘下新建文件夹D:\Program Files\wamp ,将下载文件解压到上述位置。将安装文件放到D盘的好处在于要是你重装系统,相关文件不会丢失。
win+x打开命令提示符(管理员),定位到bin文件目录下,输入命令:httpd -k install,出现如下图错误信息:

不要慌,此时,我们打开conf文件夹,找到httpd.conf,修改如下内容,让serverroot指向你的安装位置:

Define SRVROOT "D:/Program Files/wamp/Apache24" ServerRoot "${SRVROOT}"
Copy after login

然后执行命令:httpd -k uninstall 卸载服务,并再次执行安装命令,出现如图的提示表示安装成功,启动Apache:httpd -k -start

这时候你可以在浏览器中输入http://localhost来测试时候成功,如果不成功,说明本地80端口被占用,你可以到 httpd.conf中将所有80的端口改成8080,再次输入,如果出现如图提示,表示安装成功。

接下来向httpd.conf中写入PHP支持模块,有人在安装的时候会遇到 LoadModule takes two arguments, a module name and the name of a shared object file to load it from错误,原因就是在下面模块配置的时候路径没有加引号:

# 如下为PHP环境添加模块LoadModule php5_module "D:/Program Files/wamp/php-5.6.12/php5apache2_4.dll"PHPIniDir "D:/Program Files/wamp/php-5.6.12/php.ini"# 添加PHP支持AddType application/x-httpd-php .php
Copy after login

然后修改首页文件类型支持:

<IfModule dir_module>    DirectoryIndex index.html index.htm index.php</IfModule>
Copy after login

修改完毕之后先不用管Apache,接下来进行PHP环境的安装。

安装PHP环境

点开上面的下载链接,进入下载页面,建议下载线程安全版本的PHP环境。

同样,将其解压到D:\Program Files\wamp文件夹中,方便配置管理。你可以看到php根目录下就有上面在Apache中配置的两个文件之一:php5phpdbg.dll。接下来将php.ini-production文件重命名为php.ini,用写字板打开(用记事本打开之后乱的一逼,根本找不到相关的配置信息...),全局搜索,将

; extension_dir = "./"
Copy after login

修改为

extension_dir = "D:/Program Files/wamp/php-5.6.12/ext"
Copy after login

记得要去掉前面的分号和空格。然后修改如下内容:

;extension=php_bz2.dllextension=php_curl.dll;extension=php_fileinfo.dllextension=php_gd2.dll;extension=php_gettext.dll;extension=php_gmp.dll;extension=php_intl.dllextension=php_imap.dll;extension=php_interbase.dll;extension=php_ldap.dllextension=php_mbstring.dll;extension=php_exif.dll      ; Must be after mbstring as it depends on itextension=php_mysql.dllextension=php_mysqli.dll;extension=php_oci8_12c.dll  ; Use with Oracle Database 12c Instant Client;extension=php_openssl.dll;extension=php_pdo_firebird.dllextension=php_pdo_mysql.dll;extension=php_pdo_oci.dll;extension=php_pdo_odbc.dll;extension=php_pdo_pgsql.dll;extension=php_pdo_sqlite.dll;extension=php_pgsql.dll;extension=php_shmop.dll; The MIBS data available in the PHP distribution must be installed. ; See http://www.php.net/manual/en/snmp.installation.php extension=php_snmp.dllextension=php_soap.dllextension=php_sockets.dll;extension=php_sqlite3.dll;extension=php_sybase_ct.dll;extension=php_tidy.dll;extension=php_xmlrpc.dll;extension=php_xsl.dll
Copy after login

上面的代码其实就是去掉了下图中框起来部分前面的分号,来支持数据库,socket等。

这部分的内容参考自http://www.phperhome.com/php/233.html,感谢这位哥们。如果各位下载的是安装版的Apache,可以按照他的教程来进行配置,另外,接下来的MySQL安装各位还有什么不懂的话,可以参考这篇文章。
接下来,我们来验证PHP是否安装完毕,在命令行输入:httpd -k restart,重新启动服务。在D:\Program Files\wamp\Apache24\htdocs路径下新建一个文件phpinfo.php,内容添加,然后在浏览器输入http://localhost:8080/phpinfo.php,如果出现如图页面,则表示PHP环境安装成功。

安装MySQL

MySQL为安装版,按照提示走就可以了。选择custom自定义安装,将安装位置放到D:\Program Files\wamp下,方便管理。

安装PHPMyAdmin数据库操作工具

下载地址:http://www.phpmyadmin.net/
下载完成后,解压到D:\Program Files\wamp\Apache24\htdocs下,不需做其他的配置。在浏览器输入:http://localhost:8080/pma/index.php,打开控制台,输入你安装MySQL时设置的账号密码,账号默认为root。

你登陆之后,下面会有一个红色的提示:配置文件现在需要一个短语密码。新版本的PhpMyAdmin 增强了安全性,需要在配置文件设置一个短语密码, 这个密码用于Cookies的加密,以免多个PhpMyAdmin或者和其他程序共用Cookies时搞混。那么我们来添加这个密码:

1、修改phpMyAdmin/libraries/config.default.php    $cfg['blowfish_secret'] = ''; 改成 $cfg['blowfish_secret'] = '123456'; (注:其中的’123456′为随意的字符)2、修改phpMyAdmin/config.sample.inc.php    $cfg['blowfish_secret'] = ''; 改成 $cfg['blowfish_secret'] = '123456'; (注:其中的’123456′为随意的字符)
Copy after login

浏览器刷新页面,ok,红色提示消失。

至此,本地环境的搭建就完成了。

附:

上面我用到的安装软件,百度网盘,链接:http://pan.baidu.com/s/1dDBB63f 密码:lrkz

编辑器推荐:sublime。下载地址:http://www.sublimetext.com/

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)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks 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)

11 Best PHP URL Shortener Scripts (Free and Premium) 11 Best PHP URL Shortener Scripts (Free and Premium) Mar 03, 2025 am 10:49 AM

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Working with Flash Session Data in Laravel Working with Flash Session Data in Laravel Mar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

Build a React App With a Laravel Back End: Part 2, React Build a React App With a Laravel Back End: Part 2, React Mar 04, 2025 am 09:33 AM

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Simplified HTTP Response Mocking in Laravel Tests Simplified HTTP Response Mocking in Laravel Tests Mar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

cURL in PHP: How to Use the PHP cURL Extension in REST APIs cURL in PHP: How to Use the PHP cURL Extension in REST APIs Mar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

12 Best PHP Chat Scripts on CodeCanyon 12 Best PHP Chat Scripts on CodeCanyon Mar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Announcement of 2025 PHP Situation Survey Announcement of 2025 PHP Situation Survey Mar 03, 2025 pm 04:20 PM

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

Notifications in Laravel Notifications in Laravel Mar 04, 2025 am 09:22 AM

In this article, we're going to explore the notification system in the Laravel web framework. The notification system in Laravel allows you to send notifications to users over different channels. Today, we'll discuss how you can send notifications ov

See all articles