window停配置搭建 nginx+ php + mysql开发环境
window下配置搭建 nginx+ php + mysql开发环境 ? ? Nginx是一个高性能的HTTP和反向代理服务器,同时还是IMAP/POP3/SMTP代理服务器,该程序由俄罗斯Rambler.ru 站点开发,Nginx因为性能稳定、低系统资源消耗而闻名。近几年Nginx在国内已经成炙热化状态,比如像
window下配置搭建 nginx+ php + mysql开发环境? ? 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,部分修改如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 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文件,内容为:
$link = mysql_connect("localhost","root","123456");
if($link){
echo "数据库连接成功!";
}else{
echo "数据库连接失败!";
}
?>
输出“数据库连接成功!”,nginx的PHP环境配置成功(如图19)。
图19
?

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

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 is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

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.

Apache connects to a database requires the following steps: Install the database driver. Configure the web.xml file to create a connection pool. Create a JDBC data source and specify the connection settings. Use the JDBC API to access the database from Java code, including getting connections, creating statements, binding parameters, executing queries or updates, and processing results.

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 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 is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.
