search
HomeBackend DevelopmentPHP TutorialWindows上Php开发环境搭建

Windows下Php开发环境搭建
开始学习PHP。
1.下载apache,php,mysql,先从最大众的开始,方便查资料问问题。
1.1安装apache,安装直接指定路径安装,安装后直接访问127.0.0.1,看到了It works。
1.2安装mysql,一路到底,顺便配置:
   配置前把Windows防火墙配置一下或者关闭。
   Detailed Configuration --> Developer Machine --> Multifunctional Database --> Installation Path --> Decision Support --> Enable TCP/IP Networking(勾选Add firewall) --> Manual Selected Default Character Set(选utf8) --> Install As Windows Service (勾选Include Bin Directory in Windows Path) --> 设置root密码 -->Execute
1.3安装php
   Web Server选Apache 2.2.x module-->选择Apache conf文件所在的目录(Program files\Apache Software Foundation\Apache2.2\conf)-->选择能安装的内容,能选的都选上,记得手册选上,方便后面查资料

1.4调整apache配置:
php安装后module以及PhpIni路径已经自动配置到了Apache的配置文件中,但需要重启Apache服务器才能生效,通过Apache控制图标重启Apache。

试试写个测试test.php放到apache的htdoc目录:

<?php echo "PHP test"; ?>

在浏览器输入127.0.0.1/test.php,可以看到php代码被执行了。

试试在index.html中增加一段php代码:
			<h1 id="It-works">It works!</h1>		<?php echo "PHP Running";		?>	

在浏览器输入127.0.0.1,发现php代码没有执行,这是因为html文件没有被php处理,所以要修改一下apache的配置,增加:
AddHandler application/x-httpd-php .html
这样.html扩展名的文件就会被php处理了,重启apache,php代码可以看到执行了。
另外可以修改:
DirectoryIndex index.html index.php
这样当index.html不存在时就回搜索index.php作为首页。

1.5连接mysql服务器:
$db = mysql_connect("127.0.0.1", "root", "root密码");
if(!$db) echo "Can't connect database.
";
else echo "Connected database.
";

可以看到成功连接了数据库,基本的环境就可以用了。

PS:
如果php模块没有成功加载,可能是因为apache的配置文件中php的路径有问题,反斜杠\要写成\\才行。
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
How do you modify data stored in a PHP session?How do you modify data stored in a PHP session?Apr 27, 2025 am 12:23 AM

TomodifydatainaPHPsession,startthesessionwithsession_start(),thenuse$_SESSIONtoset,modify,orremovevariables.1)Startthesession.2)Setormodifysessionvariablesusing$_SESSION.3)Removevariableswithunset().4)Clearallvariableswithsession_unset().5)Destroythe

Give an example of storing an array in a PHP session.Give an example of storing an array in a PHP session.Apr 27, 2025 am 12:20 AM

Arrays can be stored in PHP sessions. 1. Start the session and use session_start(). 2. Create an array and store it in $_SESSION. 3. Retrieve the array through $_SESSION. 4. Optimize session data to improve performance.

How does garbage collection work for PHP sessions?How does garbage collection work for PHP sessions?Apr 27, 2025 am 12:19 AM

PHP session garbage collection is triggered through a probability mechanism to clean up expired session data. 1) Set the trigger probability and session life cycle in the configuration file; 2) You can use cron tasks to optimize high-load applications; 3) You need to balance the garbage collection frequency and performance to avoid data loss.

How can you trace session activity in PHP?How can you trace session activity in PHP?Apr 27, 2025 am 12:10 AM

Tracking user session activities in PHP is implemented through session management. 1) Use session_start() to start the session. 2) Store and access data through the $_SESSION array. 3) Call session_destroy() to end the session. Session tracking is used for user behavior analysis, security monitoring, and performance optimization.

How can you use a database to store PHP session data?How can you use a database to store PHP session data?Apr 27, 2025 am 12:02 AM

Using databases to store PHP session data can improve performance and scalability. 1) Configure MySQL to store session data: Set up the session processor in php.ini or PHP code. 2) Implement custom session processor: define open, close, read, write and other functions to interact with the database. 3) Optimization and best practices: Use indexing, caching, data compression and distributed storage to improve performance.

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.

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

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software