search
HomeBackend DevelopmentPHP Tutorialwnmp (windows+nginx+mysql+php) environment construction and configuration

要求

    • 必备知识

      熟悉基本编程环境搭建。

    • 运行环境

      windows 7(64位);
      nginx-1.4.7;
      MySQL Server 5.5
      php-5.4.39-nts

    • 下载地址

      环境下载

Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行。由俄罗斯的程序设计师Igor Sysoev所开发,供俄国大型的入口网站及搜索引擎Rambler(俄文:Рамблер)使用。其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好,中国大陆使用nginx网站用户有:新浪、网易、腾讯等。

上面这段介绍,摘自百度! 看了介绍就知道nginx很有逼格了shi不shi啊!那么问题来了,这么有逼格的配置,在windows下如何搭建呢? 好吧,就让我给大家介绍一下,windows下如何搭建 nginx+mysql+php 环境吧。

官方下载地址

  • Nginx
  • MySql
  • PHP

至于我使用的版本已经上传到百度云提供大家下载了哦,请戳以下链接:

  • http://pan.baidu.com/s/1gdpLa6n

Nginx

这么有逼格的服务器,我就不多做介绍,前面也提到了一些。我就直接安装吧,把下载下来的nginx-1.4.7.zip文件,解压到指定的目录就OK了,下面贴一下我的目录结构哦

下面是nginx的一些基本操作指令,当然你也可以直接双击nginx.exe文件来启动服务器(^_^)

start nginx    <span>//</span><span>启动服务</span>
 nginx -s stop    <span>//</span><span> 停止nginx</span>
nginx -s reload    <span>//</span><span> 重新加载配置文件</span>
nginx -s quit    <span>//</span><span> 退出nginx</span>

在浏览器地址中输入localhost ,如出现下图说明安装成功了!

MySql

关于mysql的安装,请自行去解决(^_^),我不想多说了!好吧,可以参考我之前写一篇文章,里面有详细的介绍哦,你会明白的(^_^)

  • windows下搭建Apache+Mysql+PHP开发环境

PHP

关于PHP的安装,我也不想说了! 额,你其实也可以参考。。。你会懂的,哈哈!好吧,往下看吧!

php提供了两种版本可以选择,即线程安全和非线程安全

  • TS:Thread Safe 线程安全, 执行时会进行线程(Thread)安全检查,以防止有新要求就启动新线程的CGI执行方式而耗尽系统资源
  • NTS:Non Thread Safe 非线程安全, 在执行时不进行线程(Thread)安全检查

PHP的两种执行方式:ISAPI和FastCGI。

  • CGI(通用网关接口/Common Gateway Interface)一般是可执行程序,例如EXE文件,和WEB服务器各自占据着不同的进程,而且一般一个CGI程序只能处理一个用户请求。这样,当用 户请求数量非常多时,会大量占用系统的资源,如内存、CPU时间等,造成效能低下。
  • ISAPI(Internet Server Application Program Interface)是微软提供的一套面向WEB服务的API接口,它能实现CGI提供的全部功能,并在此基础上进行了扩展,如提供了过滤器应用程序接 口。ISAPI应用大多数以DLL动态库的形式使用,可以在被用户请求后执行,,在处理完一个用户请求后不会马上消失,而是继续驻留在内存中等待处理别的 用户输入。此外,ISAPI的DLL应用程序和WEB服务器处于同一个进程中,效率要显著高于CGI。所以如果是以ISAPI来执行PHP,建议选择Thread Safe版本
  • FastCGI是可伸缩架构的CGI开放扩展,其主要行为是将CGI解释器进程保持在内存中并因此获得较高的性能。传统的CGI解释器的反复加载是 CGI性能低下的主要原因,如果CGI解释器保持在内存中并接受FastCGI进程管理器调度,则可以提供良好的性能、伸缩性等。nginx下php是以FastCGI的方式运行,所以我们下载Non Thread Safe版本.

我知道你已经懂了,shi不shi呀! 不过网上有些人下的TS有的人下的NTS的,选择困难症有犯了,哈哈~~~!下非线程安全的吧,因为我就下的就是这个,待会自己去百度云下的时候别选错了哦~~

将压缩文件解压到指定的文件夹(这里你爱咋整就咋整,可以参考我上面的目录结构)。配置php.ini文件,php提供了两个模板,php.ini-development和php.ini-production,前者适合开发程式使用(测试用),后者拥有较高的安全性设定,则适合上线当产品使用。这里我们将php.ini-development文件改为php.ini做配置文件使用。

修改扩展dll文件目录:

//这里根据自己的实际情况而定
extension_dir = "E:\2015\wnmp\php\ext"

加入扩展:

选择需要运行哪些扩展,只需将extension前面的注释去掉,例如:

extension=php_mysql.dll
extension=php_mysqli.dll

CGI 设置

enable_dl =<span> On
cgi.force_redirect </span>= 0<span>
cgi.fix_pathinfo</span>=1<span>
fastcgi.impersonate </span>= 1<span>
cgi.rfc2616_headers </span>= 1

配置Nginx

这里所说的配置,主要是讲如何让Nginx对PHP提供支持!!打开nginx目录下conf文件夹里的nginx.conf(这就是我的配置文件了)

修改如下代码,位置如下

修改网站的根目录,添加index.php的默认页支持,修改后的代码如下。

location /<span> {
            root   E:</span>/2015/wnmp/nginx/<span>html;
            index  index.html index.htm index.php;
}</span>

让nginx支持PHP的设置,代码位置如下

先将前面的“#”去掉,同样将root  html;改为root  E:/2015/wnmp/nginx/html;。再把“/scripts”改为“$document_root”,这里的“$document_root”就是指前面“root”所指的站点路径,改完后的代码如下:

location ~<span> \.php$ {
            root           E:</span>/2015/wnmp/nginx/<span>html;
            fastcgi_pass   </span>127.0.0.1:9000<span>;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
}</span>

上述配置改为后,别玩了要重启nginx哦,操作指令我已经到上面给出了啊!

测试

启动php内置的cgi程序,在9000端口监听nginx发过来的请求:

E:\2015\wnmp\php>php-cgi.exe -b 127.0.0.1:9000-c E:\wnmp\php\php.ini

PS:上一步操作中如果没有重启nginx的话,现在重启一遍吧!!

在网站更目录(上步操作中root所指向的路径我这里是 E:/2015/wnmp/nginx/html)下创建phpinfo.php文件,代码如下

<?php <span>phpinfo(); ?>

在浏览器地址栏中输入http://localhost/phpinfo.php,一次性点亮,是不是很Happy!!

RunHiddenConsole配置

首先把下载好的RunHiddenConsole.zip包解压到nginx目录内,RunHiddenConsole.exe的作用是在执行完命令行脚本后可以自动关闭脚本,而从脚本中开启的进程不被关闭。

创建start_nginx.bat文件

<span>@echo off
REM Windows 下无效
REM set PHP_FCGI_CHILDREN</span>=5<span>

REM 每个进程处理的最大请求数,或设置为 Windows 环境变量
set PHP_FCGI_MAX_REQUESTS</span>=1000<span>
 
echo Starting PHP FastCGI...
RunHiddenConsole E:</span>/2015/wnmp/php/php-cgi.exe -b 127.0.0.1:9000 -c E:/2015/wnmp/php/<span>php.ini
 
echo Starting nginx...
RunHiddenConsole E:</span>/2015/wnmp/nginx/nginx.exe -p E:/2015/wnmp/nginx

创建stop_nginx.bat脚本,对应的是用来关闭nginx服务

<span>@echo off
echo Stopping nginx...  
taskkill </span>/F /IM nginx.exe ><span> nul
echo Stopping PHP FastCGI...
taskkill </span>/F /IM php-cgi.exe ><span> nul
exit</span>

文件目录结构如下

好吧,整个就弄好了!!是不是比较复杂,没关系! 请问你有到linux下交叉编译安装过服务器环境吗?(^_^)hahah~~~。关于linux下服务器环境的“一揽子安装计划”,将到后续的文章中介绍!!点关注就对了(^_^)

如以上文章或链接对你有帮助的话,别忘了在文章结尾处轻轻点击一下 “还不错”按钮或到页面右下角点击 “赞一个” 按钮哦。你也可以点击页面右边“分享”悬浮按钮哦,让更多的人阅读这篇文章。

作者:Li-Cheng

微博:http://weibo.com/licheng0426

出处: http://www.cnblogs.com/Li-Cheng/p/4399149.html

由于本人水平有限,文章在表述和代码方面如有不妥之处,欢迎批评指正。留下你的脚印,欢迎评论哦。你也可以关注我,一起学习哦!

(^_^)如果您觉得此文对您有帮助的话,打个赏喝个咖啡吧,么么哒(^_^)

以上就介绍了wnmp(windows+nginx+mysql+php)环境搭建和配置,包括了方面的内容,希望对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
PHP in Action: Real-World Examples and ApplicationsPHP in Action: Real-World Examples and ApplicationsApr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: Creating Interactive Web Content with EasePHP: Creating Interactive Web Content with EaseApr 14, 2025 am 12:15 AM

PHP makes it easy to create interactive web content. 1) Dynamically generate content by embedding HTML and display it in real time based on user input or database data. 2) Process form submission and generate dynamic output to ensure that htmlspecialchars is used to prevent XSS. 3) Use MySQL to create a user registration system, and use password_hash and preprocessing statements to enhance security. Mastering these techniques will improve the efficiency of web development.

PHP and Python: Comparing Two Popular Programming LanguagesPHP and Python: Comparing Two Popular Programming LanguagesApr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

The Enduring Relevance of PHP: Is It Still Alive?The Enduring Relevance of PHP: Is It Still Alive?Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP's Current Status: A Look at Web Development TrendsPHP's Current Status: A Look at Web Development TrendsApr 13, 2025 am 12:20 AM

PHP remains important in modern web development, especially in content management and e-commerce platforms. 1) PHP has a rich ecosystem and strong framework support, such as Laravel and Symfony. 2) Performance optimization can be achieved through OPcache and Nginx. 3) PHP8.0 introduces JIT compiler to improve performance. 4) Cloud-native applications are deployed through Docker and Kubernetes to improve flexibility and scalability.

PHP vs. Other Languages: A ComparisonPHP vs. Other Languages: A ComparisonApr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP vs. Python: Core Features and FunctionalityPHP vs. Python: Core Features and FunctionalityApr 13, 2025 am 12:16 AM

PHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.

PHP: A Key Language for Web DevelopmentPHP: A Key Language for Web DevelopmentApr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

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

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)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

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