Table of Contents
安装php
安装MySQL5.5
MySQL安装:双击安装包进入安装环境界面,选择“Install MySQL Products”
 
安装nginx
服务的启动与关闭
环境测试
Home Backend Development PHP Tutorial windows下配置nginx+php+mysql

windows下配置nginx+php+mysql

Jun 23, 2016 pm 01:44 PM

  Nginx是一个高性能的HTTP和反向代理服务器,同时还是IMAP/POP3/SMTP代理服务器,该程序由俄罗斯Rambler.ru 站点开发,Nginx因为性能稳定、低系统资源消耗而闻名。近几年Nginx在国内已经成炙热化状态,比如像腾讯、网易、51CTO、迅雷、当当网、51、人人网等诸多大型网站都已经使用Nginx来做Web服务器,所以学习Nginx还是非常有必要的。

 

1.准备安装包

下载Nginx、MySQL和PHP的程序包,相关资源地址列表如下:

Nginx
http://nginx.org/en/download.html

MySQL
http://www.mysql.com/downloads/

PHP
http://windows.php.net/download/

 

2.安装部署

 

安装php

解压php-5.4.8-nts-Win32-VC9-x86.zip 到D:\server\php

        Windows下 隐藏DOS命令行窗口的程序。RunHiddenConsole.exe 是一个用来隐藏 DOS 窗口的小程序

解压RunHiddenConsole.zip ,复制RunHiddenConsole.exe到D:\server\php

        重命名php目录下的php.ini-development 为php.ini,用编辑器打开此文件(最好不要用记事本打开),此文件为PHP配置文件。

  查找定位至:; extension_dir = "./" ,将前面的分号去掉并修改为:extension_dir = "E:/DedeCMS/PHP5/ext"

  查找定位至:;extension=php_gd2.dll,将前面的分号去掉为:extension=php_gd2.dll

  查找定位至:;extension=php_mbstring.dll,将前面的分号去掉为:extension=php_mbstring.dll

  查找定位至:;extension=php_mysql.dll,将前面的分号去掉为:extension=php_mysql.dll

  查找定位至:;extension=php_mysqli.dll,将前面的分号去掉为:extension=php_mysqli.dll

  查找定位至:;extension=php_pdo_mysql.dll,将前面的分号去掉为:extension=php_pdo_mysql.dll

  查找定位至:;cgi.force_redirect = 1,将前面的分号去掉为:cgi.force_redirect = 1

  查找定位至:;cgi.fix_pathinfo=1,将前面的分号去掉为:cgi.fix_pathinfo=1

  查找定位至:;cgi.rfc2616_headers = 0,将前面的分号去掉为:cgi.rfc2616_headers = 1

启动php-cgi

D:\server\php>RunHiddenConsole.exe  php-cgi.exe -b 127.0.0.1:9000 -c D:\server\php\php.ini  

使用命令

D:\server\php>netstat -a  

出现

TCP    127.0.0.1:9000         HongJunWen-PC:0        LISTENING

说明php-cgi启动成功。

安装MySQL5.5

MySQL安装:双击安装包进入安装环境界面,选择“Install MySQL Products”

 

选择“I accept the license terms”,再选择“Next”按钮继续安装(如图9)。

 

 

选择“Skip the check for updates(not recommanded)”,再选择“Next”按钮继续安装(如图10)。

 

选择“Custom”,更改安装路径为之前创建的目录。再选择“Next”继续安装(如图11)。

图11

  选择“MySQL Server 5.5.13”与“MySQL Workbench 5.2.34”, “MySQL Workbench 5.2.34”是可视数据库设计工具。这个工具是设计MySql数据库的专用工具。也可根据需要选择是否安装。选择“Next”按钮继续安装(如图12)。

图12

  选择“Next”按钮继续安装(如图13)。

图13

  稍等片刻。程序安装完成,选择“Next”按钮进行产品配置(如图14)。

图14

  选择“Server Machine”,再选择“Next”按钮继续(如图15)。

图15

  默认3306端口,默认MySQL55 Windows服务进程名称。输入密码与重复密码。选择“Next”按钮继续(如图16)。

图16

  程序会自动安装,安装完成选择“Next”出现安装完成界面(如图17)。

图17

 

安装nginx

在D盘下建立名为server的目录 D:\server

解压nginx-1.2.5.zip至D:\server\nginx-1.2.5

找到下面的nginx.exe,在命令行下运行nginx.exe (注意目录中不能出现中文字符)

启动nginx.

打开任务管理器,切换到进程选项卡,出现如下进程,证明nginx已经启动。

在浏览中键入:http://127.0.0.1,看到下图所示证明nginx正常工作。

 

 

配置Nginx
打开Nginx的配置文件nginx.conf,部分修改如下:

12345678910111213
Copy after login
location / {    root   D:/wwwroot;    index  index.php index.html index.htm;}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000#location ~ \.php$ {#   root           html;    fastcgi_pass   127.0.0.1:9000;    fastcgi_index  index.php;    fastcgi_param  SCRIPT_FILENAME  D:/wwwroot$fastcgi_script_name;    include        fastcgi_params;}
Copy after login

 

服务的启动与关闭

  建立两个文件分别启动、关闭服务进程。

  在DedeCMS中建立文件start_nginx.bat

  @echo off

  echo Starting PHP FastCGI...

  RunHiddenConsole e:/DedeCMS/PHP5/php-cgi.exe -b 127.0.0.1:9000 -c e:/DedeCMS/PHP5/php.ini

  echo Starting nginx...

  RunHiddenConsole e:/DedeCMS/nginx.exe

  Exit

  在DedeCMS中建立文件stop_nginx.bat

  @echo off

  echo Stopping nginx...

  taskkill /F /IM nginx.exe > nul

  echo Stopping PHP FastCGI...

  taskkill /F /IM php-cgi.exe > nul

  exit

  下载软件:http://www.haoboweb.com/uploads/allimg/110613/RunHiddenConsole.zip。(只能上传图片,传不了软件)

  解压至DedeCMS目录,双击start_nginx.bat启动服务进程(如图18)。由此可见,stop_nginx.bat 文件为关闭服务进程。

 

环境测试

  在网站根目录中建立index.php文件,内容为:

  

  

  

Welcome to nginx!

  

  

  

  $link = mysql_connect("localhost","root","123456");

  if($link){

  echo "数据库连接成功!";

  }else{

  echo "数据库连接失败!";

  }

  ?>

  

  

  输出“数据库连接成功!”,nginx的PHP环境配置成功(如图19)。

图19

 

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 Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 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)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1253
24
Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Apr 17, 2025 am 12:06 AM

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values ​​to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 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.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 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

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 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.

How does PHP type hinting work, including scalar types, return types, union types, and nullable types? How does PHP type hinting work, including scalar types, return types, union types, and nullable types? Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

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 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 vs. Other Languages: A Comparison PHP vs. Other Languages: A Comparison Apr 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.

See all articles