搭建Windows平台PHP、MySQL、Apache环境

本文详细介绍了如何在Windows环境下搭建Apache Web服务器、安装PHP并配置其与Apache的关联,以及安装MySQL和PHPMyAdmin进行数据库管理。通过本教程,读者可以学会创建一个完整的本地PHP开发环境。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Apache

软件下载

进入 官网 ,点击 Downloada number of third party vendorsApacheHaus ,我选择下载的版本:

Apache 2.4.29 x64 ,文件名为:httpd-2.4.29-o102m-x64-vc14.zip

软件安装

conf 目录下找到 httpd.conf ,修改:

Define SRVROOT "C:/Users/SY/Desktop/GIT/Software/Apache/httpd-2.4.29-o102m-x64-vc14/Apache24"

解压到任意目录后,以管理员身份打开 cmd ,进入目录

C:\WINDOWS\system32>cd C:\Users\SY\Desktop\GIT\Software\Apache\httpd-2.4.29-o102m-x64-vc14\Apache24\bin

C:\Users\SY\Desktop\GIT\Software\Apache\httpd-2.4.29-o102m-x64-vc14\Apache24\bin>httpd -k install

安装成功后,关闭命令行。

在当前目录下找到 ApacheMonitor.exe ,双击打开。

点击 Start ,然后在浏览器输入 http://localhost ,正常情况下可以看到 It Works!

配置

此步骤在安装 PHP 后执行,打开 httpd.conf ,对比源文件,修改为以下内容:

#LoadModule watchdog_module modules/mod_watchdog.so
#LoadModule xml2enc_module modules/mod_xml2enc.so

LoadModule php7_module "C:/Users/SY/Desktop/GIT/Software/PHP/php-7.1.12-Win32-VC14-x64/php7apache2_4.dll"
PHPIniDir "C:/Users/SY/Desktop/GIT/Software/PHP/php-7.1.12-Win32-VC14-x64/"
AddType application/x-httpd-php .php .html .htm

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "C:/Users/SY/Desktop/GIT/Software/PHP/Apache_Workspace/PHP/HOME"
<Directory "C:/Users/SY/Desktop/GIT/Software/PHP/Apache_Workspace/PHP/HOME">

PHP

软件下载

进入 官网 ,点击 Downloads ,找到标题:VC14 x64 Thread Safe (2017-Nov-23 18:29:12) 下载的文件名:

php-7.1.12-Win32-VC14-x64.zip

软件安装

解压压缩文件,修改 php.ini-developmentphp.ini ,修改 php.ini 为以下内容:

; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
; extension_dir = "ext"
extension_dir = "C:/Users/SY/Desktop/GIT/Software/PHP/php-7.1.12-Win32-VC14-x64/ext"

extension=php_curl.dll
extension=php_gd2.dll
extension=php_mbstring.dll
extension=php_mysqli.dll
extension=php_pdo_mysql.dll
extension=php_xmlrpc.dll

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
;date.timezone =
date.timezone = Asia/Shanghai

; where MODE is the octal representation of the mode. Note that this
; does not overwrite the process's umask.
; http://php.net/session.save-path
;session.save_path = "/tmp"
session.save_path = "C:/Users/SY/Desktop/GIT/Software/PHP/Apache_Workspace/PHP/PHPSessionTmp"

; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
; http://php.net/upload-tmp-dir
;upload_tmp_dir =
upload_tmp_dir ="C:/Users/SY/Desktop/GIT/Software/PHP/Apache_Workspace/PHP/PHPFileUploadTmp"

重启 Apache ,进入 http://localhost ,在目录C:\Users\SY\Desktop\GIT\Software\PHP\Apache_Workspace\PHP\HOME 放置一个文件 index.php ,输入内容:

<?php
    phpinfo();
?>

刷新网页,如果能够看到以下画面,说明 Apache 已经关联了 PHP

这里写图片描述

修改内容:

<?php  
    $connect=mysqli_connect("127.0.0.1","root","10929131");  
    if (!$connect)
        echo "Mysql Connect Error!";  
    else 
        echo "MySQL OK!";  
    mysqli_close($connect);  
?>

看到打印:MySQL OK! ,说明连接数据库成功!注意 PHP7 以后使用 mysqli 代替 mysql

MySQL

软件下载

进入 官网 ,点击 下载CommunityMySQL on WindowsMySQL Installer ,选择 Windows (x86, 32-bit), MSI Installer ,下载的文件名:mysql-installer-community-5.7.20.0.msi

软件安装

直接一路 Next...

PHPMyAdmin

软件下载

进入官网 ,点击 download ,下载的文件名为:phpMyAdmin-4.7.5-all-languages.zip

软件安装

将解压后的文件夹重命名为 phpMyAdmin ,放到目录:C:\Users\SY\Desktop\GIT\Software\PHP\Apache_Workspace\PHP\HOME ,在浏览器输入:链接 即可访问。

参考教程

Windows 10搭建PHP开发环境

PHP7连接MySql错误”Fatal error: Uncaught Error: Call to undefined function mysql_connect()”

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值