php - 项目位于“htdocs”文件夹中时未捕获的错误
问题描述
我创建了一个作曲家项目,目的是测试 MongoDB 和 PHP(所有扩展都已加载到项目中)
这是我的示例composer.json
项目:
{
"name": "user/project-name",
"type": "project",
"require": {
"mongodb/mongodb": "^1.4"
}
}
在根目录中,我创建了一个index.php
包含以下内容的文件:
<?php
require_once './vendor/autoload.php';
$manager = new \MongoDB\Driver\Manager('mongodb://localhost:27017');
// Rest of the project comes here. Doesn't matter because this is the point of failure
如果我将项目放置在htdocs
文件夹中(使用 XAMPP),我会收到以下错误:
Uncaught Error: Class 'MongoDB\Driver\Manager' not found in
/Applications/XAMPP/xamppfiles/htdocs/project-name/index.php:4 Stack trace: #0 {main} thrown in
/Applications/XAMPP/xamppfiles/htdocs/project-name/index.php on line 4
但是,如果我使用 PHP 服务器 ( php -S localhost:8000
) 运行它,它可以正常工作:
发生这种情况可能有原因吗?
解决方案
从ku-chan发现 MacOS High Sierra 带有一个 PHP 版本,当您php
从终端运行命令时会使用该版本。这安装了正确的扩展,而 XAMPP 附带的 PHP 版本没有。
推荐阅读
- javascript - 如果满足条件,如何更改 div 中每个 p 的颜色?
- php - 从表单输入中获取值并保存到二维数组
- sql - 如何在 Amazon Athena 中通过 SQL 获取键值对 Json 的值?
- html - 表单未在本地主机或远程提交
- apache - CentOS 8 与 vhost suexec 、 PHP 和 HTTP2
- mysql - pgloader 无错误退出(MySQL 5.7 到 PostgreSQL 11.6)
- java - 使用 Selenium 在 Firefox 和 Chrome 中打开新标签页不起作用
- c# - 为什么 C# Xunit Mock 在 IQueryable 上返回空枚举
- linux - 在 bash 脚本的变量中捕获 SSH 输出
- c - 为什么 pthread_join() 执行后的代码没有?