背景
作为一个开发,在linux下部署一哈环境还是没啥问题,毕竟天天都在用linux,前面我也记录了一篇linux系统下的PHP环境安装。最近公司遇到一个客户,拿了一个乞丐版配置的服务器,非要装Windows server,关键是老板还非要我在上面部署环境,没法啊,只能硬着头皮上了啊,下面边部署,边记录了(内心:这配置,随便点个啥子东西都要等几秒钟。。。)
IIS安装
IIS现在已经是内置在操作系统中一起发行的,所以安装起来还是很简单的
打开《服务器管理配置》---选择《添加角色和功能》

然后接下来的几步都是直接选择“下一步”就好,到《服务器角色》这一步为止

在《服务器角色》这一步中,我们需要选择《Web服务器(IIS)》,然后添加功能,再下一步

到了《功能》这一步,我也不知道选什么,所以直接‘下一步’了

《Web服务器角色(IIS)》这一步我也是直接‘下一步’跳过,然后《角色服务》选择要安装的角色服务,这里我直接全部选择了,免得后面有啥子不支持的还要重新整,选择好以后,继续‘下一步’

《确认》步骤直接点‘安装’,然后就是等待那个进度条慢慢加载的过程(去泡个茶。。。)

安装完成后,点击关闭,然后在下面就看到有这么一个东西了

最后在浏览器输入‘localhost’或者‘127.0.0.1’,出现下图界面,证明就安装成功了

PHP下载解压
我这里安装的是php7.2.16(版本自己在官网选择),下载地址
https://windows.php.net/downloads/releases/php-7.2.16-nts-Win32-VC15-x64.zip
下载好以后直接解压,我是直接放在C盘的根目录的

将这个目录下的“php.ini-development”复制一份成“php.ini”作为正式的配置文件,后面需要打开什么扩展,就直接在配置文件里面添加就好

配置IIS支持PHP
步骤:控制面板-----系统和安全-----管理工具-----Internet Information Services(IIS)管理器-----处理程序映射-----添加木块映射




在Linux下编译安装以及配置PHP环境下我也介绍了,web服务器是不能直接解析php,需要借助FastCGI。所以上图就是在做这个操作,复制粘贴就完了,还是解释一哈上面这些选项的意思
请求路径: 也就是我们访问服务器要访问的文件,既然是php,那肯定就是.php结尾的文件,*.php就是统配所有的php文件
模块: 上面也说了,解析php要借助FastCGI,那肯定就要选择对应的模块
可执行文件: php-cgi执行文件的路径,上面我把php直接放C盘根目录的
名称: 随便写一个名字就是了
然后需要配置一个默认文档---index.php
步骤: 回到刚刚IIS管理器的主页-----默认文档-----添加-----输入对应的默认文档



下面是修改网站的具体配置的,这里只修改网站的根目录到自定义的位置,我直接改成了E:\www这个目录下

测试是否成功
然后在刚刚指定的目录建立一个index.php保存,然后浏览器输入localhost

如果你成功了,那么恭喜,运气不错,如果失败了,比如下面这种情况,也莫慌,继续看下去

错误解决
打开cmd-----进入php目录----运行‘.\php.exe -v’

错误提示就出来了,原来在windows下要运行php,需要一些vc系列的依赖包,所以网上去下载安装就是了
感谢这大兄弟提供的各种vc包,点击进去下载一个vc14,然后下一步下一步安装就行

安装好了,在继续执行“.\php.exe -v”

如果还是出现上面那种问题,就继续安装vc对应版本,不出现问题了的话,浏览器输入localhost

综上就把php+IIS配置成功了,来修改两个php.ini的配置文件试一试生效不
配置前 php -m 查看已经开启的扩展

修改配置文件,随便打开几个常用的扩展,保存后

继续 php -m可以看到对应的模块也就有了

MySQL安装
下载并解压MySQL5.7
下载地址: https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.25-winx64.zip

解压发现尽然没有配置文件,那就建一个“my.ini”配置文件,然后简单配置一下端口,mysql存放的目录和对应的数据目录

配置环境变量
在上面解压的目录的bin目录下面有很多执行文件,每次要使用mysql命令都要先进入这个目录,麻烦。所以还是先配置一个全局变量吧
计算机-----属性-----高级系统设置-----环境变量-----在系统变量的path中新建一条(有的电脑是在后面分好然后添加)

开始安装
运行cmd命令工具,最好是用管理员的身份运行下面命令
mysqld install mysql --default-file="C:\mysql\my.ini"

结局报错了,还是莫怕,和上面php安装的时候一样,他还是要依赖vc裤,所以网上下一个安装就好了,下载这个vc13安装在运行就莫问题了

上面的--default-file那个参数跟的就是第一步中自定义的配置文件
修改注册表路径
运行-----输入‘regedit’-----然后按照下面路径操作

初始化data目录
data目录就是上面配置文件中配置的,执行下面命令会自动生成
mysqld --initialize-insecure

启动mysql
net start mysql

连接数据库
初始化data目录的时候会自动生成无密码的root用户,所以直接连接就是,然后我下面连接好以后来修改密码。当然也可以在上面直接执行“mysqld --initialize”这个命令,然后在data目录下有一个****.err结尾的的日志文件,他里面会记录一个随机密码。(反正随机密码都记不住,都是要修改的,何不直接用不带密码的呢。。。。)

修改root密码
set password for 账号=password('密码');

验证密码

ps: mysql配置还是很多的,你可以直接set global的方式配置,也可以直接在一开始自定义的配置文件中加
补充一下:
1. mysql的配置文件最好把数据库默认字符集编码加上,免得乱码

2. 把iis的rewrite模块也装上
网友评论