如何修复 Symfony2 部署问题?
How to fix Symfony2 deployment issues?
我在不同的环境、不同的项目中遇到这个问题有一段时间了,有时我确实修复了一些其他的问题,现在我找不到失败的地方,所以这是我最近的尝试。
我想部署一个应用程序,所以要遵循 docs 说的第一个规则:
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 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)"} []
我该如何解决这个问题?这是什么原因?我手动清除了缓存,运行ning Symfony 命令,我已经多次重新启动 Web 服务器 (Apache),但似乎没有任何帮助。有什么建议吗?
它看起来像一个权限问题(无法打开...)所以从项目目录中执行
chmod 777 -R app/cache
我在不同的环境、不同的项目中遇到这个问题有一段时间了,有时我确实修复了一些其他的问题,现在我找不到失败的地方,所以这是我最近的尝试。
我想部署一个应用程序,所以要遵循 docs 说的第一个规则:
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 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)"} []
我该如何解决这个问题?这是什么原因?我手动清除了缓存,运行ning Symfony 命令,我已经多次重新启动 Web 服务器 (Apache),但似乎没有任何帮助。有什么建议吗?
它看起来像一个权限问题(无法打开...)所以从项目目录中执行
chmod 777 -R app/cache