原则错误:“无法打开所需的'/tmp/__CG__Source.php'” [英] Doctrine error: "Failed opening required '/tmp/__CG__Source.php' "

查看:64
本文介绍了原则错误:“无法打开所需的'/tmp/__CG__Source.php'”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将我的PHP应用程序迁移到Ubuntu服务器,但是没有成功。任何帮助将不胜感激。

I am trying to migrate my PHP application to an Ubuntu server, but without succes. Any help would be appreciated.

首先,按照Doctrine的入门手册(直到 Generate the Database Schema(生成数据库架构))。其次,我将PHP脚本(使用Doctrine)放置在/ jorrit / myapp文件夹中。

First I installed Doctrine successfully into /jorrit/myapp, following the first part of Doctrine's Getting Started manual (till "Generating the Database Schema"). Secondly I placed my PHP scripts (which use Doctrine) in folder /jorrit/myapp.

当我尝试在CLI中运行PHP脚本时,出现以下错误消息:

When I try to run my PHP script in the CLI, I get this error messages:


PHP警告:require(/ tmp / __ CG__Source.php):无法打开流:/ jorrit / myapp / vendor / doctrine / common /中没有此类文件或目录第200行上的lib / Doctrine / Common / Proxy / AbstractProxyFactory.php

PHP Warning: require(/tmp/__CG__Source.php): failed to open stream: No such file or directory in /jorrit/myapp/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php on line 200

PHP致命错误:require():无法打开所需的'/tmp/__CG__Source.php'(include_path ='.: / usr / share / php:/ usr / share / pear')在第200行的/jorrit/myapp/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php中

PHP Fatal error: require(): Failed opening required '/tmp/__CG__Source.php' (include_path='.:/usr/share/php:/usr/share/pear') in /jorrit/myapp/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php on line 200

Bootstrap.php看起来像这样:

Bootstrap.php looks like this:

<?php
// bootstrap.php
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;

require_once "vendor/autoload.php";

// Create a simple "default" Doctrine ORM configuration for Annotations
$isDevMode = false;
$config = Setup::createAnnotationMetadataConfiguration(array(__DIR__."/src"), $isDevMode);

// the connection configuration
$dbParams = array(
        'driver'   => 'pdo_mysql',
        'host'     => 'xx',
        'user'     => 'xx',
        'password' => 'xx',
        'dbname'   => 'xx',
        'profiler' => 'false'
);


// obtaining the entity manager
$entityManager = EntityManager::create($dbParams, $config);

?>

我的PHP脚本的第一行:

The first lines of my PHP script:

<?php

require_once "bootstrap.php";
require_once 'classes.php';

$connection = $entityManager->getConnection();

该应用程序在我的开发环境(Windows)中运行良好。 / tmp文件夹存在并且可以访问。数据库已成功迁移并存在。我没有更改vendor文件夹中的任何内容。

The application works fine in my development environment (Windows). The /tmp folder exists and is accessible. The database is migrated succesfully and exists. I did not change anything in the vendor folder.

有什么想法吗?预先感谢您的帮助。

Any ideas? Thanks in advance for your help.

推荐答案

TL; DR您只需要手动生成代理类

TL;DR You'll just need to generate your proxy classes manually

vendor/bin/doctrine orm:generate-proxies

Doctrine使用代理将数据库连接到数据库。代理是从Entity类生成的。

Doctrine uses Proxies to connect the to database. Proxies are generated from the the Entity classes.

在开发模式下,它可以在每个请求上生成一个代理,因为您可以更改Entity类。

In development mode, it generates a Proxies on every request because you could make changes to Entity classes.

在生产模式下,它不会每次都生成代理。出于性能原因,它假定代理存在并直接包含它们。

In production mode, it does not generate Proxies every time. For performance reason, it assumes the Proxies exist and include them directly.

有几种生成代理的模式:

There are a few mode for Proxies generation:


  1. 始终-始终生成代理,这是开发模式的默认设置

  2. 从不-从不生成代理,这是生产的默认设置模式

  3. ON_DEMAND-仅在代理文件不存在时才生成代理。此选项的缺点是它每次都必须调用file_exists(),这可能会导致性能问题。

现在该命令

vendor/bin/doctrine orm:generate-proxies

将代理类生成为/ tmp。我会说这可能仍然会引起麻烦,因为服务器上的其他应用程序
可能会意外删除这些文件。一种选择是,您可以将/ tmp目录访问权限更改为1777

generates Proxy classes to /tmp. I would say this might still cause trouble because other applications on your server might delete these files unexpectedlly. One option is you can change your /tmp directory access permission to 1777

sudo chmod 1777 /tmp

777前面的醒目的位 1表示,尽管每个人都可以读/写到/ tmp目录,但是您可以仅对您自己的文件进行操作。即您不能删除其他用户创建的文件。

The stricky bit '1' in front of 777 means that, although everyone can read/write to the /tmp directory, but you can only operate on your own files. i.e. You can't remove files created by other users.

要进一步阅读,请查看
http://docs.doctrine-project.org/en/latest /reference/advanced-configuration.html#auto-generating-proxy-classes-optional

For further reading, please have a look at http://docs.doctrine-project.org/en/latest/reference/advanced-configuration.html#auto-generating-proxy-classes-optional

您还可以将Proxies目录设置为其他位置应用程序可以对其进行修改。 http://docs.doctrine-project.org /en/latest/reference/advanced-configuration.html#autoloading-proxies

You can also set the Proxies directory to somewhere else so no other applications can modify them. http://docs.doctrine-project.org/en/latest/reference/advanced-configuration.html#autoloading-proxies

这篇关于原则错误:“无法打开所需的'/tmp/__CG__Source.php'”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆