windows下配置nginx+php环境,Windows下安装Nginx+php+mysql环境

系统:Windows 7 64位系统

安装之前,首先下载软件:

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

PHP Stable PHP 5.6.26: http://php.net/downloads.php

mysql: http://dev.mysql.com/downloads/utilities/

第一步:在D盘建立文件夹Nginx+php+Mysql,路径为:D:\Nginx+php+Mysql

第二步:安装Nginx,安装目录为:D:\Nginx+php+Mysql\nginx

1.打开D:\Nginx+php+Mysql\nginx目录,运行该文件夹下的nginx.exe

2.测试是否启动nginx。打开浏览器访问http://localhost 或 http://127.0.0.1,看看是否出现“Welcome to nginx!”,出现的证明已经启动成功了。

若启动不成功,查看是否端口被占用。

安装PHP,安装目录为:D:\Nginx+php+Mysql\php

安装mySQL,安装目录为: D:\Nginx+php+Mysql\mysql

第三步:修改Nginx的conf文件:目录为D:\Nginx+php+Mysql\nginx\conf

文件名为:nginx.conf

1. 去掉worker_processes前的#号,开启一个进程

2. 添加events

3. 设置http->设置server->支持php

#user nobody;

worker_processes1;

#error_log logs/error.log;

#error_log logs/error.log notice;

#error_log logs/error.log info;

#pid logs/nginx.pid;

events {

worker_connections1024;

}

http {

include mime.types;

default_type application/octet-stream;

#log_format main'$remote_addr - $remote_user [$time_local] "$request"'#'$status $body_bytes_sent "$http_referer"'#'"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;

sendfile on;

#tcp_nopush on;

#keepalive_timeout0;

keepalive_timeout65;

#gzip on;

server {

listen80;

server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location/{

root d:/Nginx+php+Mysql/nginx/html;

index index.html index.htm;

}error_page500 502 503 504 /50x.html;

location= /50x.html {

root html;

}# pass the PHP scripts to FastCGI server listening on127.0.0.1:9000#

location~\.php$ {

root html;

fastcgi_pass127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}}

}

测试nginx是否安装成功

3c09b9efb15a1b67943a5848360eb978.png

第四步:修改php下php.ini-development文件,将文件名修改为php.ini,找开php.ini:

搜索“extension_dir”,找到extension_dir = "ext" 先去前面的分号再改为 extension_dir = "./ext"

搜索“php_mysql”,找到:”extension=php_mysql.dll和extension=php_mysqli.dll 去掉前面的“;”extension=php_mysql.dll和extension=php_mysqli.dll (支持MYSQL数据库)

查看php是否安装成功:

facea868249feac92e54e0dc0384a6c1.png

第四步:在php目录下新建文件php-cgi.vbs,用php-cgi.vbs文件启动php-cgi:

打开php-cgi.vbs,写入启动编码:

set wscriptObj = CreateObject("Wscript.Shell")

wscriptObj.run"php-cgi -b 127.0.0.1:9000",0

第五步:在D:\Nginx+php+Mysql目录下新建启动项:runServer.bat和停止项stopServer.bat

在启动项runServer.bat中输入:

@echo off

echo Starting nginx...

cd%~dp0nginx

start"" "./nginx.exe"echo Starting mysql...

net start mysql

echo Starting PHP FastCGI...

cd%~dp0PHP

start"" "php-cgi.vbs"pause

Exit

在停止项中输入:

@echo off

echo Stopping nginx...

taskkill/F /IM nginx.exe >nul

echo Stopping PHP FastCGI...

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

echo Stopping mysql...

net stop mysql

pause

exit

最后,查看是否启动成功:

在nginx的html目录下D:\Nginx+php+Mysql\nginx\html,新建phpinfo.php

写入:

php

phpinfo();?>

在浏览器中输入phpinfo.php的路径,查看是否配置成功:

951162861e0e4028397c578305352669.png

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
配置 PHP 环境NginxMySQL 和 Redis,你按照以下步骤进行操作: 1. 首,安装 Docker 和 Docker Compose(如果尚未安)。 2. 创建一个新的目录,用于存放你的文件和配置文件。 在该目录下一个 `docker-compose.yml` 文件将以下内容复制到文件中: yaml version: '3' services: nginx: image: nginx:latest : - 80:80 volumes - ./nginx.conf://nginx/nginx.conf ./public:/var/www/html depends_on: - php php: image: php:latest volumes: - ./php.ini:/usr/local/etc/php/php.ini - ./public:/var/www/html mysql: image: mysql:latest ports: - 3306:3306 environment: - MYSQL_ROOT_PASSWORD=your_mysql_root_password - MYSQL_DATABASE=your_mysql_database - MYSQL_USER=your_mysql_user - MYSQL_PASSWORD=your_mysql_password volumes: - ./mysql:/var/lib/mysql redis: image: redis:latest ports: - 6379:6379 volumes: - ./redis:/data ``` 4. 创建一个 `nginx.conf` 文件,并将以下内容复制到文件中。你可以根据需要进行修改。 ```nginx events {} http { server { listen 80; server_name localhost; root /var/www/html; index index.php index.html; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { fastcgi_pass php:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } } ``` 5. 创建一个 `php.ini` 文件,并根据需要进行修改。 6. 创建一个 `public` 文件夹用于存放你的 PHP 项目文件。 7. 运行以下命令启动 Docker 容器: ```shell docker-compose up -d ``` 这将会启动 NginxPHPMySQL 和 Redis 容器。 现在,你已经成功配置PHP 环境NginxMySQL 和 Redis。你可以将你的 PHP 项目文件放在 `public` 文件夹中,然后通过访问 `http://localhost` 来访问你的应用程序。请确保修改 `mysql` 服务中的环境变量,设置你自己的 MySQL 根密码、数据库名称、用户名和密码。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值