记录下Windows Server 2016 X64下手动部署Apache 2.4.29+MySQL5.7+PHP7+phpMyAdmin4.7.6

环境:

Windows Server2016 DataCenter x64
Apache2.4.9
PHP7.2
MySQL5.7.2
phpMyAdmin4.7.6

系统需要安装VC常用环境,文末提供下载。


Apache下载&配置

下载

Apache官网下载http://httpd.apache.org/
下载最新的Apache

由于Apache没有编译好的可执行文件因此只能下载别的平台编译好的

这里我们第一个ApacheHaus为例。

这里以VC14为例

下载,注意64位和32位以及OpenSSL模块版本

下载完是个压缩包

移动到想放的地方并解压(D盘为例)
然后把解压后的Apache24目录移动到D盘根目录
最后效果如下

安装

CMD进入Apachebin目录
CMD执行httpd -?可以看到httpd所有可用参数

D:\Apache24\bin>httpd -?
Usage: httpd [-D name] [-d directory] [-f file]
[-C "directive"] [-c "directive"]
[-w] [-k start|restart|stop|shutdown] [-n service_name]
[-k install|config|uninstall] [-n service_name]
[-v] [-V] [-h] [-l] [-L] [-t] [-T] [-S] [-X]
Options:
-D name : define a name for use in <IfDefine name> directives
-d directory : specify an alternate initial ServerRoot
-f file : specify an alternate ServerConfigFile
-C "directive" : process directive before reading config files
-c "directive" : process directive after reading config files
-n name : set service name and use its ServerConfigFile and ServerRoot
-k start : tell Apache to start
-k restart : tell running Apache to do a graceful restart
-k stop|shutdown : tell running Apache to shutdown
-k install : install an Apache service
-k config : change startup Options of an Apache service
-k uninstall : uninstall an Apache service
-w : hold open the console window on error
-e level : show startup errors of level (see LogLevel)
-E file : log startup errors to file
-v : show version number
-V : show compile settings
-h : list available command line options (this page)
-l : list compiled in modules
-L : list available configuration directives
-t -D DUMP_VHOSTS : show parsed vhost settings
-t -D DUMP_RUN_CFG : show parsed run settings
-S : a synonym for -t -D DUMP_VHOSTS -D DUMP_RUN_CFG
-t -D DUMP_MODULES : show all loaded modules
-M : a synonym for -t -D DUMP_MODULES
-t -D DUMP_INCLUDES: show all included configuration files
-t : run syntax check for config files
-T : start without DocumentRoot(s) check
-X : debug mode (only one worker, do not detach)

这里因为要安装为服务且不用默认名,所以执行
httpd -n Apache24_test -k install
执行完会报错,因为#httpd.conf第38行左右没有设置正确路径(默认是/Apache24

找到第38行,然后改为正确的Apache24根路径

Define SRVROOT “D:\Apache24”
ServerRoot “${SRVROOT}”

默认网站路径是${SRVROOT}\htdocs,在httpd.conf251行左右可以修改,我修改为${SRVROOT}\WWW

然后进入服务中启动Apache24进程即可,或者用ApacheMonitor.exe【推荐】进行控制

浏览器访问localhost,见到如下图界面即为配置且启动成功


PHP下载+安装

下载

PHP官网下载网址http://www.php.net/downloads.php

这里我选择线程安全X64版本

下载后

安装【解压】

解压到D盘,目录重命名为PHP7

然后进入D:\PHP7修改php.ini-developmentphp.ini

development为开发环境,production为产品环境,如果要上线,更改productionphp.ini
然后设置环境变量

测试是否成功
cmd执行php –v

整合进Apache

进入D:\Apache24\conf目录对httpd.conf文件进行编辑
181行后添加PHP支持【httpd.conf文件注释语法为#

LoadModule php7_module D:/php7/php7apache2_4.dll
AddType application/x-httpd-php .php
PhpIniDir D:/php7

文件改后如下图所示

配置PHP支持MySQL

进入D:/php7,编辑php.ini898行和902行左右,使PHP对MySQL支持【PHP中注释为;】

设置拓展目录

编辑732行,设置PHP拓展目录

设置时区

编辑932date.timezone = PRC

Apache设置PHP首页文件

编辑httpd.conf284

测试PHP+Apache

D:\Apache24\WWW下新建index.php文件,内容是

<?php
phpinfo();
?>

保存,本地访问localhost,出现如下图表示配置成功


下载&配置MySQL

下载

下载地址https://dev.mysql.com/downloads/mysql/
进入后往下拉

选择X64版本的Zip是因为方便【好吧,我承认我懒】,图片中下面那个是用于开发测试的版本
这一步会提示登录帐号,不用管,直接下载

配置

下载后解压重命名为mysql57并移动到D盘根目录,这时D盘目录如下图

然后进入mysql根目录,新建data空文件夹my.ini
my.ini代码如下

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

保存后cmd进入mysql57/bin
执行mysqld --verbose --help会提示帮助

D:\mysql57\bin>mysqld --verbose --help
mysqld Ver 5.7.20 for Win64 on x86_64 (MySQL Community Server (GPL))
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Starts the MySQL database server.

Usage: mysqld [OPTIONS]
NT and Win32 specific options:
--install Install the default service (NT).
--install-manual Install the default service started manually (NT).
--install service_name Install an optional service (NT).
--install-manual service_name Install an optional service started manually (NT).
--remove Remove the default service from the service list (NT).
--remove service_name Remove the service_name from the service list (NT).
--enable-named-pipe Only to be used for the default server (NT).
--standalone Dummy option to start as a standalone server (NT).
以下省略

执行mysqld --initialize-insecure --user=mysql,文档表明,MySQL5.7.6后自带数据库,使用-initialize生成随机密码,使用-initialize-insecure生成空密码。默认帐号root,后面的-user=mysql不更改

然后bin目录下执行mysqld install mysql57

由于默认是空密码,所以执行mysqladmin -u root -p password设置密码

然后执行net start mysql57

方便以后使用,新建环境变量D:\mysql57\bin

测试连接数据库

代码如下
test.php

<?php

$link = mysqli_connect('localhost','root','123456789');//如果连接成功,会返回一个连接的标识,PHP7中去除了mysql_connect,改用mysqli_connect;

if($link){ //如果有数据库连接标识,则为连接成功

echo "连接数据库成功"; //echo是输出的意思

}else{ //没有返回标识,则连接数据库失败

echo "连接数据库失败";

}

?>

配置phpMyAdmin

下载连接:https://www.phpmyadmin.net/

配置

解压,改名为phpMyAdmin扔进web目录【D:\Apache24\WWW】

config.inc.php

然后修改phpMyAdmin目录下的config.sample.inc.phpconfig.inc.php然后打开,编辑17行左右的$cfg['blowfish_secret']='';$cfg['blowfish_secret']='AbCdEfGhIjKlMn';【任意字符串】

config.default.php

文件路径:D:\Apache24\WWW\phpMyAdmin\libraries\config.default.php
修改以下项目:

a.访问网址

$cfg['pmaabsoluteuri'] = '';这里填写phpmyadmin的访问网址

b.mysql主机信息

$cfg['servers'][$i]['host'] = 'localhost'; // mysql hostname or ip address 填写localhost或mysql所在服务器的ip地址,如果mysql和该phpmyadmin在同一服务器,则按默认localhost $cfg['servers'][$i]['port'] = ''; // mysql port - leave blank for default port mysql端口,如果是默认3306,保留为空即可

c.mysql用户名和密码

$cfg['servers'][$i]['user'] = 'root'; // mysql user访问phpmyadmin使用的mysql用户名
fg['servers'][$i]['password'] = ''; // mysql password (only needed对应上述mysql用户名的密码

d.认证方法

$cfg['servers'][$i]['auth_type'] = 'cookie';

在此有四种模式可供选择,cookie,http,http,config
config方式即输入phpmyadmin的访问网址即可直接进入,无需输入用户名和密码,是不安全的不推荐使用
当该项设置为cookie,httphttp时,登录phpmyadmin需要数据用户名和密码进行验证,,具体如下:

  1. php安装模式为Apache,可以使用httpcookie;
  2. php安装模式为cgi,可以使用cookie

e.短语密码(blowfish_secret)的设置

$cfg['blowfish_secret'] = '';

如果认证方法设置为cookie,就需要设置短语密码,置于设置为什么密码,由您自己决定 ,但是不能留空,否则会在登录phpmyadmin时提示错误

不出意外的话访问localhost/phpmyadmin会出现以下界面

输入数据库帐号密码即可登录


至此,WAMP环境配置完毕,可正常使用了。

测试时区代码

<?php  

echo "现在时间为: "date('Y-m-d H:i:s');

?>

VC常用库下载

点击下载