Php 如何解决Symfony2部署问题?

Php 如何解决Symfony2部署问题?,php,symfony,deployment,doctrine-orm,symfony-2.7,Php,Symfony,Deployment,Doctrine Orm,Symfony 2.7,我在不同的环境、不同的项目中有一段时间存在这个问题,有时我确实修复了一些其他问题,比如现在我找不到失败的地方,所以这是我最近的一次尝试 我想部署一个应用程序,以便遵循以下规则,比如我第一次部署的是: composer install --optimize-autoloader Loading composer repositories with package information Installing dependencies (including require-dev) from loc

我在不同的环境、不同的项目中有一段时间存在这个问题,有时我确实修复了一些其他问题,比如现在我找不到失败的地方,所以这是我最近的一次尝试

我想部署一个应用程序,以便遵循以下规则,比如我第一次部署的是:

composer install --optimize-autoloader
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.
Nothing to install or update
Generating optimized autoload files
Updating the "app/config/parameters.yml" file
Clearing the cache for the dev environment with debug true
Trying to install assets as symbolic links.
Installing assets for Symfony\Bundle\FrameworkBundle into web/bundles/framework
The assets were installed using symbolic links.
Installing assets for Sonata\CoreBundle into web/bundles/sonatacore
The assets were installed using symbolic links.
Installing assets for Sonata\AdminBundle into web/bundles/sonataadmin
The assets were installed using symbolic links.
Installing assets for Nelmio\ApiDocBundle into web/bundles/nelmioapidoc
The assets were installed using symbolic links.
Installing assets for PDI\TemplateBundle into web/bundles/template
The assets were installed using symbolic links.
Installing assets for Sensio\Bundle\DistributionBundle into web/bundles/sensiodistribution
The assets were installed using symbolic links.
其次,由于未能更新composer库,我重新运行composer update命令:

composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Removing symfony/symfony (v2.6.9)
  - Installing symfony/symfony (v2.7.0)
    Downloading: 100%

  - Removing sensio/distribution-bundle (v3.0.25)
  - Installing sensio/distribution-bundle (v3.0.28)
    Downloading: 100%

  - Installing yriveiro/php-fslock (0.1)
    Downloading: 100%

  - Installing jordillonch/deploy-bundle (dev-master 3f8e679)
    Cloning 3f8e679eb2ac87d0cef9ea9dd4765afd24c6a266

Writing lock file
Generating autoload files
Updating the "app/config/parameters.yml" file
PHP Deprecated:  Symfony\Component\DependencyInjection\Definition::setFactoryMethod(getEntityManager) is deprecated since version 2.6 and will be removed in 3.0. Use Definition::setFactory() instead. in /var/www/html/pdone_backend/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Definition.php on line 137
PHP Stack trace:
PHP   1. {main}() /var/www/html/pdone_backend/app/console:0
PHP   2. Symfony\Component\Console\Application->run() /var/www/html/pdone_backend/app/console:27
PHP   3. Symfony\Bundle\FrameworkBundle\Console\Application->doRun() /var/www/html/pdone_backend/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:126
PHP   4. Symfony\Component\HttpKernel\Kernel->boot() /var/www/html/pdone_backend/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:70
PHP   5. Symfony\Component\HttpKernel\Kernel->initializeContainer() /var/www/html/pdone_backend/app/bootstrap.php.cache:2396
PHP   6. Symfony\Component\DependencyInjection\ContainerBuilder->compile() /var/www/html/pdone_backend/app/bootstrap.php.cache:2618
PHP   7. Symfony\Component\DependencyInjection\Compiler\Compiler->compile() /var/www/html/pdone_backend/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:614
PHP   8. Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass->process() /var/www/html/pdone_backend/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php:117
PHP   9. Symfony\Component\DependencyInjection\Compiler\MergeExtensionConfigurationPass->process() /var/www/html/pdone_backend/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/DependencyInjection/MergeExtensionConfigurationPass.php:39
PHP  10. Sonata\DoctrineORMAdminBundle\DependencyInjection\SonataDoctrineORMAdminExtension->load() /var/www/html/pdone_backend/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/MergeExtensionConfigurationPass.php:55
PHP  11. Symfony\Component\DependencyInjection\Loader\XmlFileLoader->load() /var/www/html/pdone_backend/vendor/sonata-project/doctrine-orm-admin-bundle/DependencyInjection/SonataDoctrineORMAdminExtension.php:44
PHP  12. Symfony\Component\DependencyInjection\Loader\XmlFileLoader->parseDefinitions() /var/www/html/pdone_backend/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php:58
PHP  13. Symfony\Component\DependencyInjection\Loader\XmlFileLoader->parseDefinition() /var/www/html/pdone_backend/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php:119
PHP  14. Symfony\Component\DependencyInjection\Definition->setFactoryMethod() /var/www/html/pdone_backend/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php:153
PHP  15. trigger_error() /var/www/html/pdone_backend/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Definition.php:137
PHP Deprecated:  Symfony\Component\DependencyInjection\Definition::setFactoryService(doctrine) is deprecated since version 2.6 and will be removed in 3.0. Use Definition::setFactory() instead. in /var/www/html/pdone_backend/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Definition.php on line 208
我收到了很多警告,但请转到下一步。尝试调用prod URL(不带
app_dev.php
),得到以下结果:

[2015-06-02 09:43:11] request.INFO: Matched route "api_1_post_emails". {"route_parameters":{"_controller":"PDI\\PDOneRestBundle\\Controller\\TargetRestController::postEmailsAction","_format":"json","_route":"api_1_post_emails"},"request_uri":"http://api.dev.pdone.com/api/v1/emails?_format=json"} []
[2015-06-02 09:43:11] security.INFO: Populated the TokenStorage with an anonymous Token. [] []
[2015-06-02 09:43:11] security.INFO: No expression found; abstaining from voting. [] []
[2015-06-02 09:43:11] php.CRITICAL: Fatal Compile Error: require(): Failed opening required '/var/www/html/pdone_backend/app/cache/prod/doctrine/orm/Proxies/__CG__PDIPDOneBundleEntityTerritory.php' (include_path='.:/usr/share/pear:/usr/share/php') {"type":64,"file":"/var/www/html/pdone_backend/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php","line":209,"level":6143,"stack":[{"function":"getProxyDefinition","type":"->","class":"Doctrine\\Common\\Proxy\\AbstractProxyFactory","file":"/var/www/html/pdone_backend/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php","line":119,"args":[]},{"function":"getProxy","type":"->","class":"Doctrine\\Common\\Proxy\\AbstractProxyFactory","file":"/var/www/html/pdone_backend/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php","line":2677,"args":[]},{"function":"createEntity","type":"->","class":"Doctrine\\ORM\\UnitOfWork","file":"/var/www/html/pdone_backend/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php","line":138,"args":[]},{"function":"hydrateRowData","type":"->","class":"Doctrine\\ORM\\Internal\\Hydration\\SimpleObjectHydrator","file":"/var/www/html/pdone_backend/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php","line":48,"args":[]},{"function":"hydrateAllData","type":"->","class":"Doctrine\\ORM\\Internal\\Hydration\\SimpleObjectHydrator","file":"/var/www/html/pdone_backend/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php","line":140,"args":[]},{"function":"hydrateAll","type":"->","class":"Doctrine\\ORM\\Internal\\Hydration\\AbstractHydrator","file":"/var/www/html/pdone_backend/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php","line":756,"args":[]},{"function":"load","type":"->","class":"Doctrine\\ORM\\Persisters\\BasicEntityPersister","file":"/var/www/html/pdone_backend/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php","line":411,"args":[]},{"function":"find","type":"->","class":"Doctrine\\ORM\\EntityManager","file":"/var/www/html/pdone_backend/vendor/doctrine/orm/lib/Doctrine/ORM/EntityRepository.php","line":154,"args":[]},{"function":"find","type":"->","class":"Doctrine\\ORM\\EntityRepository","file":"/var/www/html/pdone_backend/src/PDI/PDOneRestBundle/Controller/TargetRestController.php","line":224,"args":[]},{"function":"postEmailsAction","type":"->","class":"PDI\\PDOneRestBundle\\Controller\\TargetRestController","file":"/var/www/html/pdone_backend/app/bootstrap.php.cache","line":3094,"args":[]},{"function":"call_user_func_array:{/var/www/html/pdone_backend/app/bootstrap.php.cache:3094}","file":"/var/www/html/pdone_backend/app/bootstrap.php.cache","line":3094,"args":[]},{"function":"handleRaw","type":"->","class":"Symfony\\Component\\HttpKernel\\HttpKernel","file":"/var/www/html/pdone_backend/app/bootstrap.php.cache","line":3056,"args":[]},{"function":"handle","type":"->","class":"Symfony\\Component\\HttpKernel\\HttpKernel","file":"/var/www/html/pdone_backend/app/bootstrap.php.cache","line":3207,"args":[]},{"function":"handle","type":"->","class":"Symfony\\Component\\HttpKernel\\DependencyInjection\\ContainerAwareHttpKernel","file":"/var/www/html/pdone_backend/app/bootstrap.php.cache","line":2429,"args":[]},{"function":"handle","type":"->","class":"Symfony\\Component\\HttpKernel\\Kernel","file":"/var/www/html/pdone_backend/web/app.php","line":27,"args":[]},{"function":"{main}","file":"/var/www/html/pdone_backend/web/app.php","line":0,"args":[]}]} []
[2015-06-02 09:43:11] request.CRITICAL: Uncaught PHP Exception Symfony\Component\Debug\Exception\FatalErrorException: "Compile Error: require(): Failed opening required '/var/www/html/pdone_backend/app/cache/prod/doctrine/orm/Proxies/__CG__PDIPDOneBundleEntityTerritory.php' (include_path='.:/usr/share/pear:/usr/share/php')" at /var/www/html/pdone_backend/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php line 209 {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalErrorException(code: 0): Compile Error: require(): Failed opening required '/var/www/html/pdone_backend/app/cache/prod/doctrine/orm/Proxies/__CG__PDIPDOneBundleEntityTerritory.php' (include_path='.:/usr/share/pear:/usr/share/php') at /var/www/html/pdone_backend/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php:209)"} []

我如何解决这个问题?这是什么原因?我手动清除缓存,运行Symfony命令,多次重启web服务器(Apache),但似乎没有任何帮助。有什么建议吗?

这看起来像是权限问题(打开失败…),所以请从项目目录中执行

chmod 777 -R app/cache

Random anwser,您是否尝试过
composer安装--没有开发--优化autoloader
?@smarber是的,但是如果我想保留开发库呢?