下载windows版本的php
下载MSSQL 扩展(按需选下,对应php v.x版本号)
-
pecl地址下载通用PDO语法
PECL :: Package :: pdo_sqlsrv -
pecl地址下载MSSQL方言
https://pecl.php.net/package/sqlsrv
php启用扩展目录
注意这里一定要用绝对地址,否则你将会无法在Apache环境下加载php扩展
; On windows:
extension_dir = "E:/jxcphp/php849/ext"
php启用sqlsrv,可选语法
extension=pdo_sqlsrv
extension=sqlsrv
下载Windows版本的Apache
定义root目录
Define SRVROOT "E:/jxcphp/web"
ServerRoot "${SRVROOT}"
Apache导入php模块
LoadModule php_module "E:/jxcphp/php849/php8apache2_4.dll"
<IfModule php_module>
AddType application/x-httpd-php .php
PHPIniDir "E:/jxcphp/php849"
</IfModule>
文档路径等配置
DocumentRoot "${SRVROOT}/jxcsoft"
<Directory "${SRVROOT}/jxcsoft">
# 不允许目录浏览,允许跟随符号链接
Options -Indexes +FollowSymLinks
# 禁止 .htaccess 文件覆盖配置
AllowOverride All
# 允许所有用户访问此目录
Require all granted
</Directory>
cd到Apache目录安装Apache服务
httpd -k install
# 如果是pwoershell
# .\httpd -k install
Apache运维语法
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)
可能的未知问题
如果遇到类似这种警告
PHP Warning: 'C:\WINDOWS\SYSTEM32\VCRUNTIME140.dll' 14.12 is not compatible with this PHP build linked with 14.43
- 这个警告说明你的 PHP 构建版本依赖的是 Visual C++ Redistributable 版本 14.43(即 VC143),但系统当前加载了旧版本 14.12(VC141)。
- 这可能导致 PHP 模块在 Apache 中加载失败。
这时候可以安装最新的 Visual C++ Redistributable 包(x86/x64)试试
- x64版本下载:https://aka.ms/vs/17/release/vc_redist.x64.exe
- 或 x86 版本:https://aka.ms/vs/17/release/vc_redist.x86.exe
- 安装完成后重启 Apache。