您的位置 首页 php

Windows+php7+nginx1.14+apache+mysql配置

Windows+php7+nginx1.14+mysql配置

一、下载软件

1、php-7.3.4-nts-Win32-VC15-x64

2、nginx-1.14.2

3、mysql-5.7.23-winx64

二、配置

1、php. ini 配置

extension_dir = "D:\php-7.3.4-nts-Win32-VC15-x64\ext"
cgi.fix_pathinfo=1
extension=mysqli
extension=pdo_mysql
date.timezone = Asia/Shanghai
enable_dl = On
cgi.force_redirect = 0
fastcgi.impersonate = 1
cgi.rfc2616_headers = 1
 

2、 nginx .conf配置

location ~ \.php$ { 
 root D:/nginx-1.14.2/html; 
 fastcgi_pass 127.0.0.1:9000; 
 fastcgi_index index.php; 
 # 这里$document_root指的是上面定义好的nginx根
 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 include fastcgi_params; 
 } 
 

3、mysql安装

1.)下载免安装的压缩包mysql-5.7.21-winx64.zip

< 
 
  1. )解压到相应的目录(此处解压到F:\mysql-5.7.21-winx64)
  2. )配置环境变量,将MySQL的启动目录(F:\mysql-5.7.21-winx64\bin)添加到Path中

4.)在MySQL目录下(D:\mysql-5.7.23-winx64)创建my.ini文件,内容如下:

[mysql] 
# 设置mysql客户端默认字符集 
default-character-set=utf8 
[mysqld] 
#设置3306端口 
port = 3306 
# 设置mysql的安装目录 
basedir=D:\mysql-5.7.23-winx64 
# 设置mysql数据库的数据的存放目录 
datadir=D:\mysql-5.7.23-winx64\data 
# 允许最大连接数 
max_connections=200 
# 服务端使用的字符集默认为8比特编码的latin1字符集 
character-set-server=utf8 
# 创建新表时将使用的默认存储引擎 
default-storage-engine=INNODB 
#解决报错
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
 

出现msvcr120.dll错误,下载,安装vcredist

  1. )管理员身份运行 CMD
  2. 切换目录:
C:\Windows\ system32 >cd D:\mysql-5.7.23-winx64\bin
 

生成MySQL服务:

D:\mysql-5.7.23-winx64\bin>mysqld -install
​
Service successfully installed.
 

生成data目录,时间较长:

D:\mysql-5.7.23-winx64\bin>mysqld --initialize-insecure --user=mysql
 

启动MySQL服务:

C:\Windows\system32>net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。
 
  1. )登录数据库,修改密码(默认密码为空)

登录数据库:

C:\Windows\system32>mysql -uroot -p
 

修改密码:

mysql> use mysql;
Database changed
mysql> update user set authentication_string=password("新密码") where User="root";
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql>FLUSH PRIVILEGES;
 

7.)配置root远程登录

mysql>use mysql;
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
 

三、启动

开启nginx:

打开cmd命令提示符输入命令start nginx或者进入到nginx目录下,输入命令 nginx.exe,开启nginx
nginx.exe -s reload 重启
nginx.exe -s quit 关闭
 

建议使用RunHiddenConsole(用来隐藏CMD命令窗),下载后把RunHiddenConsole.exe和批处理文件放在同一级目录,

编写批处理文件(start.bat就是批处理文件)

@echo off
set php_home=D:/php-7.3.4-nts-Win32-VC15-x64
set nginx_home=D:/nginx-1.14.2
set PHP_FCGI_MAX_REQUESTS = 1000
echo Starting PHP FastCGI...
RunHiddenConsole %php_home%/php-cgi.exe -b 127.0.0.1:9000 -c %php_home%/php.ini
echo Starting nginx...
RunHiddenConsole %nginx_home%/nginx.exe -p %nginx_home%
 

stop.bat批处理如下:

@echo off
echo Stopping nginx... 
taskkill /F /IM nginx.exe > nul
echo Stopping PHP FastCGI...
taskkill /F /IM php-cgi.exe > nul
exit
 

开机启动的设置:

在C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup这个位置粘贴start.bat批处理文件
 

Windows+Apache24+PHP7+Mysql5.7的FASTCGI方式安装过程

一、APACHE24配置conf/ httpd .conf

ServerName localhost:8080
Listen 8080
 

FastCGI安装

将mod_fcgid.so复制到apache的module目录下面。
 

配置httpd.conf在后面添加如下

LoadModule fcgid_module modules/mod_fcgid.so
<IfModule fcgid_module>
 Options ExecCGI
 FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 1000
 FcgidMaxRequestsPerProcess 1000
 FcgidMaxProcesses 15
 FcgidIOTimeout 120
 FcgidIdleTimeout 120
 AddType application/x-httpd-php .php
 # 全局默认使用的PHP版本配置
 FcgidInitialEnv PHPRC "D:/php-7.3.4-nts-Win32-VC15-x64"
 # 上传文件的最大尺寸 100MB
 FcgidMaxRequestLen 104857600
 <Files ~ "\.php$>"
 AddHandler fcgid-script .fcgi .php
 FcgidWrapper "D:/php-7.3.4-nts-Win32-VC15-x64/php-cgi.exe" .php
 </Files>
</IfModule>
<Directory "D:/Apache24/htdocs">
 AllowOverride All
 Options -Indexes +ExecCGI
</Directory>
注意了,这里的 FcgidMaxRequestLen 很重要也很坑爹。
当你上传文件的时候发现总是出现500错误,而程序其实没有错误。 
# 实际上是因为上传内容体积过大,即便修改了php.ini 中配置的上传参数也没有用的,必须修改这里才行,nginx下也会有类似的问题
 

extra/httpd-vhosts.conf配置,解决外部访问问题

<VirtualHost _default_:80>
 DocumentRoot "${SRVROOT}/htdocs"
 Allow from all
 Require all granted
 #ServerName www.example.com:80
 #Options Indexes FollowSymLinks Includes ExecCGI
 AllowOverride All
</VirtualHost>
以管理员身份运行CMD,进入Apache24\bin 目录(httpd.exe所在目录)
输入 httpd.exe -k install -n "Apache24" 安装服务(注:Apache24为安装服务名称)
安装基本完成。到安装目录下的bin目录中找到 ApacheMonitor.exe ,双击运行,启动apache服务
 

二、php配置文件php.ini

extension_dir = "D:\php-7.3.4-nts-Win32-VC15-x64\ext"
cgi.fix_pathinfo=1
extension=mysqli
extension=pdo_mysql
date.timezone = Asia/Shanghai
enable_dl = On
cgi.force_redirect = 0
fastcgi.impersonate = 1
cgi.rfc2616_headers = 1
 

文章来源:智云一二三科技

文章标题:Windows+php7+nginx1.14+apache+mysql配置

文章地址:https://www.zhihuclub.com/77961.shtml

关于作者: 智云科技

热门文章

网站地图