简体   繁体   English

使用php / silex“找不到类”

[英]“Class not found” using php/silex

I set up a Silex-project local using a XAMPP on Mac. 我在Mac上使用XAMPP设置了一个本地Silex项目。 Everything works fine. 一切正常。 Now I uploaded the files to my Amazon ec2 server and tried to run it. 现在我将文件上传到我的Amazon ec2服务器并尝试运行它。 I always get the php errormessage: 我总是得到php errormessage:

"Fatal error: Class 'Silex\Application' not found in /opt/bitnami/apps/..."

I'm using Composer to handle the dependencies. 我正在使用Composer处理依赖关系。 The first lines of my file look like this: 我文件的第一行如下所示:

<?php
require_once __DIR__.'/../vendor/autoload.php';

$app = new Silex\Application();
$app['debug'] = true;

Anyone has a clue how to solve that? 有人知道如何解决吗? Where could there be a problem? 哪里有问题?

Thanks a lot! 非常感谢! Cheers 干杯

As suspected, you are using some sort of git-based deployment process. 怀疑,您正在使用某种基于git的部署过程。

Currently there is no tagged stable release of silex (EDIT: as of now, there is). 目前没有标记稳定版本的silex(编辑:截至目前,有)。 As a result, composer will install it from source, resulting in the silex github repository being cloned into vendor/silex/silex . 结果,composer将从源代码安装它,从而将silex github存储库克隆到vendor/silex/silex Since that folder is a git repo itself, those files cannot be added to your main repo. 由于该文件夹本身就是一个git repo,因此无法将这些文件添加到主仓库中。 Which means that on your server the vendor/silex/silex directory simply will not exist. 这意味着在您的服务器上, vendor/silex/silex目录根本不存在。

If you really want to, you can apply the fix of running composer install with the --prefer-dist flag, which will force to install silex from a zip archive, allowing the directory to be added to your git repo. 如果确实需要,可以使用--prefer-dist标志应用运行composer install的修复程序,该标志将强制从zip归档文件安装silex,从而允许将目录添加到git repo中。

But I would say that you should not be committing your vendors into version control. 但我会说你不应该让你的供应商进入版本控制。 This is also covered by this entry in the composer FAQ: 作曲家常见问题解答中的以下条目也涵盖了这一点:

I suggest adding vendor to your .gitignore and running composer install as part of your CI and deployment process. 我建议在您的.gitignore添加vendor ,并在CI和部署过程中运行composer install

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM