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 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)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

See all articles