`
- 浏览:
23039 次
- 性别:
- 来自:
广州
-
Nginx + PHP + MySQL on Windows in 6 minutes
come from
http://eksith.wordpress.com/2010/11/07/nginx-php-mysql-windows/3/
The last time I posted a tutorial on Nginx, there wasn’t a native port of the server available. Riez Opuz posted a link to his Xenstack project on that post that prompted me to write the rest of what I’ve been putting off. It’s a good way to tweak the stack to your own needs.
I tried to leave this as “in 5 minutes”, but then I remembered how long it would take to download MySQL… Even on broadband.
Kevin Worthington had very kindly provided a Cygwin build that ran on Windows, however Nginx now has a Windows build that we can use and this time, we can add MySQL to the list as well. To keep everything compatible, we’ll be using the 32 bit versions for all downloads.
Once you’ve also downloaded Nginx (0.8.53 at the time of this post), head on to the PHP libraries and remember to download the Windows Libraries only (5.3.3 as of today) and select the thread safe version. The first steps are the same with the exception of the download link to MySQL and we need the no-install download.
Make sure to follow this directory structure!
Extract the Nginx files to C:\nginx
Extract PHP to C:\nginx\php
Extract MySQL to C:\nginx\mysql
First, let’s configure MySQL
MySQL no-install is a freakin’ huge download so feel free to delete mysql-test, Embedded, sql-bench and folders named debug once unzipped. If you want to minimize the folder even more, you can optionally delete any .pdb files. This would come in handy if you want to deploy the whole ensamble on a thumb drive or package it for a demo application and are really penny-pinching the available storage space.
Once the cleanup is complete, copy my-medium.ini in C:\nginx\mysql\ into my.ini. I think the medium configuration takes care of most uses and, for a moderately busy site, it fares pretty well.
Always try to copy exising files before making changes instead of outright renaming them. This way, if something goes wrong with the new configuration, we still have the original handy to start over..
Open up the newly copied my.ini file and change the [client] block to match the following.
[client]
#password = your_password
port = 3306
socket = c:/nginx/mysql/tmp/mysql.sock
Note the Unix style forward-slashes.
Now in the [mysqld] block in the same file, change to match the following :
[mysqld]
port = 3306
socket = c:/nginx/mysql/tmp/mysql.sock
basedir = c:/nginx/mysql
datadir = c:/nginx/mysql/data
bind-address = localhost
enable-named-pipe
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
Now let’s try and run our MySQL server
Start a new command line window…
Note: If you’re running Windows Vista or above with UAC enabled, you need to right click on the command line link and select “Run as administrator”.. If you get a message saying “Install/Remove of the Service Denied!” when trying to start MySQL later on, then you probably have UAC running, so this step is very important.
Navigate to C:\nginx\mysql\bin\ and run :
mysqld --install-manual
There should be a slight delay followed by a “Service successfully installed”. We then must run :
net start mysql
…And if there are no errors noted, then Congratulations!
Before we proceed, we need to run some housekeeping operations. In the same command line window, run :
mysqladmin -u root password newpassword
Where newpassword is your new MySQL root password. This is an important step toward securing your installation.
Now that we’ve changed our root password enter the following :
mysql -u root -p
Which will give you a password prompt. Enter your newpassword created before. Once you’re logged in, you’re at the MySQL console.
If you need to change your root password at a future date, run mysql as above type the following :
update mysql.user set password=PASSWORD('new-newpassword') where user='root';
Note that passwords are encoded before storage in the database, so we need to run the PASSWORD function on our new-newpassword. Once that’s done, be sure to run :
flush privileges;
Now we need to remove all the junk that came with the server.
Delete the test databases and anonymous users (Always remember the semicolon at the end!) :
delete from mysql.user where user='root' and host!='localhost';
drop database test;
delete from mysql.db where db='test' or db='test\_%';
And finally flush privileges and quit :
flush privileges; quit;
Now if we need to, we can stop MySQL by running the following (in C:\nginx\mysql\bin\ as an Administrator of course):
net stop mysql
And if we need to remove it from our services entirely, run the following :
mysqld --remove
Setting up PHP with Nginx
In our previous example, we setup PHP with Nginx’s fast-cgi capability.
This example is essentially the same with some minor alterations…
Navigate to C:\nginx\php, copy and rename php.ini-production to php.ini.
In this php.ini file, scroll down to (or hit Ctrl + F to find in Notepad) extension_dir = “ext”. Remove the semicolon in front uncomment this line.
Now scroll down to the “Windows Extensions” section and uncomment the following lines :
extension=php_bz2.dll
extension=php_gd2.dll
extension=php_imap.dll
extension=php_mbstring.dll
extension=php_mysql.dll
extension=php_mysqli.dll
Also change the include path location :
include_path = "c:\php\PEAR"
This is in case you want to install any PEAR modules (which can be frankly annoying at times), you just need to download, extract and copy to the PEAR folder.
I think these extensions would be required for functional content management which, I imagine, is the reason you’re reading a post on installing MySQL with Nginx and PHP in the first place.
And finally, uncomment the following line :
log_errors = On
After these changes are done, we can finally get into the the Nginx configuration…
Setup Nginx
In C:\nginx\conf\ copy nginx.conf as a backup and edit the original. Find the following lines, uncomment them and change the fastcgi_param :
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
I modified this bit from an absolute path of the html folder to $document_root, which is a better way to do things.
Update Feb 26, 2012 for HaKi’s concern about uploaded executions
If you have an upload directory on your server, it’s best to avoid any PHP executions on any uploaded files.
E.G :
location /uploads {
if $request_uri ~ \.php$ {return 403;}
}
And that should be it for the configuration…
Starting your server
In the last post, there were two bat files included in Kevin’s distribution for starting and stopping the server. We’ll need to create both of these in notepad this time, since this is from the original developers, and enter some startup and shutdown code.
Create a start-server.vbs file and enter the following :
Dim sh, fcgiPort, PHPini
fcgiPort = "127.0.0.1:9000"
PHPini = "c:\nginx\php\php.ini"
Set sh = WScript.CreateObject("WScript.Shell")
' Navigate to the the nginx folder and run the server
sh.run "cmd /K CD C:\nginx\ & start nginx", 0
' Navigate to the PHP folder and start the FastCGI executable
sh.run "cmd /K CD C:\nginx\php\ & php-cgi.exe -b "& fcgiPort &" -c "& PHPini, 0
' Navigate to MySQL and start
sh.run "cmd /k CD C:\nginx\mysql\bin\ & mysqld", 0
Set sh = Nothing
(It’s times like this, I realise how much I’ve been away from VB)
Now that we can start our services, we also need a way to stop them. Create a stop-server.vbs and enter the following :
Dim sh, fcgiPort, PHPini
Set sh = WScript.CreateObject("WScript.Shell")
' Navigate to the the nginx folder and shut it down
sh.run "cmd /K CD C:\nginx\ & nginx -s quit", 0
' Shutdown PHP FastCGI
sh.run "cmd taskkill /f /IM php-cgi.exe", 0
' Navigate to MySQL and shutdown the server
sh.run "cmd /k CD C:\nginx\mysql\bin\ & mysqladmin -u root shutdown", 0
Set sh = Nothing
And that should be it!
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
CentOS7 自动化搭建Nginx+PHP7+Mysql+Docker+Docker-Compose Shell脚本,Docker version 18.06.1-ce,docker-compose version 1.22.0
### Web环境搭建:Linux+Nginx+PHP+MySQL+Redis #### 一、环境概述与推荐版本 在构建一个高效且稳定的商城系统时,选择合适的Web环境至关重要。本指南将介绍一套广泛应用于电商平台的技术栈——**Ubuntu + PHP + ...
"Linux+Nginx+PHP+MySQL环境配置指南" 本指南将指导您如何安装和配置 Linux+Nginx+PHP+MySQL 环境,以便于构建一个功能完善的 Web 服务器。 安装 Red Hat Linux 在开始安装 Linux 之前,需要选择语言和键盘布局。...
Win+Nginx+PHP+MySQL 环境搭建是指在 Windows 操作系统上安装和配置 Nginx、PHP、MySQL 等组件,以便搭建一个完整的 Web 服务器环境。该环境搭建主要涉及到 Nginx、PHP、MySQL 三个组件的安装和配置。 一、Nginx ...
1、基于vue+python+flask+uwsgi+nginx+mysql的外包项目网站项目源码.zip 2、该资源包括项目的全部源码,下载可以直接使用! 3、本项目适合作为计算机、数学、电子信息等专业的课程设计、期末大作业和毕设项目,作为...
详细说明了windows服务器nginx+tomcat+mysql部署及配置(配置阿里云后台安全组,配置域名)很适合新手学习 附件中包含: 1.操作说明文档 2.操作录屏 3.安装所用到的软件安装包 1)Windows Server 2019 数据中心版 ...
docker-compose php7.3.4-fpm+nginx+mysql配置
这是nginx+php+mysql的本地windows测试环境 在u盘运行的web环境有usbwebserver,但是apache配置https没有nginx方便, 使用方式: start.bat启动 stop.bat停止 restart.bat重启
nginx+php+mysql资源集 包含: php-7.1.8.tar.gz mysql-5.6.42.tar.gz nginx-1.8.1.tar.gz libxml2-2.9.1.tar.gz openssl-1.1.0e.tar.gz zlib-1.2.7.tar.gz 有没有一种痛苦的经历,为了配置nginx+php+mysql环境 在...
Nginx+PHP+MySQL是构建高性能Web应用的典型组合,尤其在Windows环境下,这个配置提供了灵活且高效的服务器环境。让我们深入探讨这三个组件以及如何在Windows系统上搭建和使用它们。 **Nginx(发音为“engine x”)*...
alpine创建lnmp环境alpine安装nginx+php5.6+mysql
该压缩包文件“Nginx+php+mysql+phpmyadmin引擎管理器C++源码.rar”包含了构建一个基于C++的服务器管理工具,用于自动化安装、卸载、启用和停用Nginx、PHP、MySQL和phpMyAdmin这四个关键的Web开发组件。这个工具的...
这个压缩包包含了"keepalived+nginx+tomcat+redis+mysql"所需的基础组件,特别是Java Development Kit(JDK)。下面我们将详细探讨这些组件及其在IT领域的应用。 首先,JDK是Java编程语言的基石,它提供了编译、...
LNMP(Linux + Nginx + PHP + MySQL)是一套常用的服务器组合,广泛应用于Web开发领域,特别是对于处理高并发和动态内容展示有着卓越的性能。这个组合将Linux操作系统作为基础,结合Nginx作为Web服务器,PHP作为后端...
【Nginx+PHP+MySQL详细配置】 Nginx是一个高效、稳定的HTTP和反向代理服务器,由俄罗斯的Rambler.ru站点开发。由于其出色的性能和低资源消耗,Nginx在中国的互联网行业中得到了广泛应用,如腾讯、网易等大型网站都...
免费下载 密码tszb
### Nginx+Apache+MySQL+PHP+Memcached+Squid 搭建门户网站 #### 一、前言与架构概述 随着互联网技术的发展,如何构建一个高效、稳定且能够应对高并发访问的Web服务器成为了许多企业和开发者关注的重点。本文将...