How to deploy symfony2 application in localhost with apache2 - php

I have gone through many questions related to this in SO, but couldn't find a solution to my problem.
I have copied the demo symfony application to /var/www/html/myproject folder. I can only access the localhost/myproject/web/app_dev.php but not localhost/myproject/web/app.php . Basically I want to switch from development environment to prodution environment.
I just get a blank page when I access app.php. How do I solve this issue?
Following is my routing.yml file
app:
resource: "#AppBundle/Controller/"
type: annotation
EDIT
Error log (app/logs/prod.log)
[2015-04-06 22:54:53] request.ERROR: Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "No route found for "GET /"" at /home/fazlan/ppp/myproject/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/EventListener/RouterListener.php line 144 {"exception":"[object] (Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException(code: 0): No route found for \"GET /\" at /home/fazlan/ppp/myproject/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/EventListener/RouterListener.php:144, Symfony\\Component\\Routing\\Exception\\ResourceNotFoundException(code: 0): at /home/fazlan/ppp/myproject/app/cache/prod/appProdUrlMatcher.php:35)"} []

You need to create your bundle and configure routes for it. After this prod environment will be work. It is possible that the acme isnt work in prod.
#Cedric: Acme Demo Bundle is only configured on app_dev.php you have to create another bundle first with proper routes, you can see the list of routes for your bundle in app/config/routing.yml or whatever you set as a the extension of your configs.
More info here.

After going through different tutorials and manuals, I finally was able to solve this issue by the following changes.
routing.yml
app:
resource: "#AppBundle/Controller/"
type: annotation
_acme_demo:
resource: "#AcmeDemoBundle/Resources/config/routing.yml"
AppKernel.php (The whole file is not shown here)
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new AppBundle\AppBundle(),
new Acme\DemoBundle\AcmeDemoBundle(),
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
//$bundles[] = new Acme\DemoBundle\AcmeDemoBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
}
return $bundles;
}
in the above file AcmeDemoBundle is registered. You have to comment out //$bundles[] = new Acme\DemoBundle\AcmeDemoBundle(); to prevent the bundle being registered twice in dev and test environments.
After editing those two files go to the project folder and do
php app/console --env=prod cache:clear
and then in the browser localhost/myproject/web/app.php would load the same bundle as in app_dev.php

Related

AppKernel bundles not registring

given is my appKernel class while registering the bundles it is sing to generate the classes
new FOS\RestBundle\FOSRestBundle(),
new JMS\SerializerBundle\JMSSerializerBundle(),
new Nelmio\CorsBundle\NelmioCorsBundle(),
but i used following commands to generate them from composer
composer require friendsofsymfony/rest-bundle
composer require jms/serializer-bundle
composer require nelmio/cors-bundle
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = [
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new AppBundle\AppBundle(),
new FOS\RestBundle\FOSRestBundle(),
new JMS\SerializerBundle\JMSSerializerBundle(),
new Nelmio\CorsBundle\NelmioCorsBundle(),
];
if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
}
return $bundles;
}
while running my php code it is giving exceptions because given bundles are not register
run the command and clear cache:
php bin/console cache:clear
also add the use classes at top AppKernel.php
There will also be some configuration for them all in a config file. Often in app/config/config.yml. Even if it will all be the default, they need to be fully enabled by that entry in the configuration (yml, or xml).
You can see the sample (and complete, with all defaults) with the command bin/console debug:config JMSSerializerBundle, replacing the bundle-name as appropriate.
There is a page of details for JMSSerializer and similar exist for the others.

Symfony2 annotation routing causes cache:clear to fail

I'm having a bunch of problems with routing in Symfony2 and I'm at my wits end searching for an answer.
I'm currently trying to use the #Route annotation. In the dev environment with debug enabled, everything works. In prod with debug enabled, everything works. If I disabled debug, only the index route responds, everything else returns a 404.
I initially thought it was the cache, so I followed the usual process of clearing it. That led to my next problem:
[Doctrine\Common\Annotations\AnnotationException]
[Semantical Error] The annotation "#Sensio\Bundle\FrameworkExtraBundle\Configuration\Route" in method LeagueOfData\Controller\DefaultController::indexAction() does not exist, or could not be auto-loaded.
This error appears when you run bin/console cache:clear --env=prod or bin/console cache:clear --env=dev.
So I checked everything was set up correctly (bare in mind, this works completely fine in the browser with debug enabled no matter the environment).
routing.yml
parser:
resource: "#LeagueOfData/Controller/"
type: annotation
This is included in config.yml and routing_dev.yml (due to the dev override).
AppKernal.php
public function registerBundles()
{
$bundles = [
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new LeagueOfData\LeagueOfData()
];
if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
}
return $bundles;
}
SensioFrameworkExtraBundle is registered correctly. (Full source: https://github.com/Acaeris/lol-parser/blob/broken-routing/app/AppKernel.php)
app.php
<?php
use Symfony\Component\HttpFoundation\Request;
/** #var \Composer\Autoload\ClassLoader $loader */
$loader = require __DIR__ . '/../app/autoload.php';
include_once __DIR__ . '/../app/bootstrap.php.cache';
$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
app_dev.php
<?php
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Debug\Debug;
/** #var \Composer\Autoload\ClassLoader $loader */
$loader = require __DIR__.'/../app/autoload.php';
Debug::enable();
$kernel = new AppKernel('dev', true);
$kernel->loadClassCache();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
As you can see, not much difference. The key seems to be in enabling debug... but why?
Full source is on GitHub if it'll help anyone: https://github.com/Acaeris/lol-parser/tree/broken-routing
You need to import it with an use statement, as example:
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
Hope this help

Symfony 3.1.2 "The service 'profiler' has a dependency on a non-existent service 'debug.security.access.decision_manager'."

After updating to the latest version of Symfony from 3.0.2 to 3.1.2 when I run the command.
php bin/console cache:clear --env=prod
I now get the following error:
[Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException]
The service "profiler" has a dependency on a non-existent service
"debug.security.access.decision_manager".
Does anyone know why this would happen, or what I could do to resolve this? I can add any additional information as needed. Thanks in advance!!!
The issue had to do with the fact I was including debugging resources in the production environment. I was performing tests on the caching mechanisms and forgot to remove the inclusion from the config.yml and AppKernel.php files.
if (in_array($this->getEnvironment(), ['dev','test','prod'], true)) {
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
//... Extensions From Base
$bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle();
}
as such the AppKernel instantiation needed the debug parameter to be set to true.
$kernel = new AppKernel('prod', true);
Otherwise it would cause the initial issue I asked this question to fix.

Symfony - ClassNotFoundException in AppKernel.php

while putting my app in production, i had to FTP-transfer the JMS Serializer as i can't use composer on the production server.
It worked, i see it in the vendor.
My AppKernel is the same as in local (where it works, as tested in both production and dev environment) :
<?php
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),
new FOS\JsRoutingBundle\FOSJsRoutingBundle(),
new Hager\TransformationBundle\TransformationBundle(),
new JMS\SerializerBundle\JMSSerializerBundle()
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Acme\DemoBundle\AcmeDemoBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
}
return $bundles;
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
}
}
but i recieve a very strange
ClassNotFoundException in AppKernel.php line 22:
Attempted to load class "JMSSerializerBundle" from namespace "JMS\SerializerBundle".
Did you forget a "use" statement for another namespace?
As the console isn't available on production server either, i did rm -RF /app/cache/* but still got the error.
Help very wlecome.
Also upload the vendor/composer directory again.
and upload your web directory too since there might be new assets.
Then go to app/cache and delete everything inside.
Another approach:
download and install the CoreSphere ConsoleBundle
add your ip address in app_dev.php:
if (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !(in_array(#$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1', '100.200.300.400')) || php_sapi_name() === 'cli-server')
)
(replace 100.200.300.400 for your own ip) and upload this file to the server . Then visit your website in app_dev.php/_console and you can execute your console commands from there.
You said you cannot run Composer in your prod server (why?!). In that case, even if you copy your JMS Serializer files to the vendor dir, they will not be autoloaded by the autoloader that composer generates. You will need to edit the autoload_namespaces.php file in your vendor/composer dir and add this line:
'JMS\\SerializerBundle' => array ($vendorDir . '/jms/serializer-bundle'),
DO not rename or replace Comoser.lock andcomposer.json files.
Installnew project symfony new project and replace folders from broken project to new one : app,src,web.

Not able to install Sonata Project

I recently came across Sanota Project and wanted to give it a try. I am trying to install all the bundles of sanota project following the quick installation steps mentioned here
and when I run the website php app/console server:run all i see is the white screen. I dont see any error in app_dev.log
I cross checked if the bundles are enabled in Appkernel.php and they seem to be.
public function registerBundles()
{
$bundles = array(
// SYMFONY STANDARD EDITION
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new JMS\AopBundle\JMSAopBundle(),
new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
// DOCTRINE
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(),
// KNP HELPER BUNDLES
new Knp\Bundle\MenuBundle\KnpMenuBundle(),
new Knp\Bundle\MarkdownBundle\KnpMarkdownBundle(),
new Knp\Bundle\PaginatorBundle\KnpPaginatorBundle(),
// USER
new FOS\UserBundle\FOSUserBundle(),
new Sonata\UserBundle\SonataUserBundle('FOSUserBundle'),
new Application\Sonata\UserBundle\ApplicationSonataUserBundle(),
// PAGE
new Sonata\PageBundle\SonataPageBundle(),
new Application\Sonata\PageBundle\ApplicationSonataPageBundle(),
// NEWS
new Sonata\NewsBundle\SonataNewsBundle(),
new Application\Sonata\NewsBundle\ApplicationSonataNewsBundle(),
// MEDIA
new Sonata\MediaBundle\SonataMediaBundle(),
new Application\Sonata\MediaBundle\ApplicationSonataMediaBundle(),
// new Liip\ImagineBundle\LiipImagineBundle(),
new Ivory\CKEditorBundle\IvoryCKEditorBundle(),
new Sonata\AdminBundle\SonataAdminBundle(),
new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
// Disable this if you don't want the audit on entities
new SimpleThings\EntityAudit\SimpleThingsEntityAuditBundle(),
// API
new FOS\RestBundle\FOSRestBundle(),
new Nelmio\ApiDocBundle\NelmioApiDocBundle(),
// E-COMMERCE
new Sonata\BasketBundle\SonataBasketBundle(),
new Application\Sonata\BasketBundle\ApplicationSonataBasketBundle(),
new Sonata\CustomerBundle\SonataCustomerBundle(),
new Application\Sonata\CustomerBundle\ApplicationSonataCustomerBundle(),
new Sonata\DeliveryBundle\SonataDeliveryBundle(),
new Application\Sonata\DeliveryBundle\ApplicationSonataDeliveryBundle(),
new Sonata\InvoiceBundle\SonataInvoiceBundle(),
new Application\Sonata\InvoiceBundle\ApplicationSonataInvoiceBundle(),
new Sonata\OrderBundle\SonataOrderBundle(),
new Application\Sonata\OrderBundle\ApplicationSonataOrderBundle(),
new Sonata\PaymentBundle\SonataPaymentBundle(),
new Application\Sonata\PaymentBundle\ApplicationSonataPaymentBundle(),
new Sonata\ProductBundle\SonataProductBundle(),
new Application\Sonata\ProductBundle\ApplicationSonataProductBundle(),
new Sonata\PriceBundle\SonataPriceBundle(),
new JMS\SerializerBundle\JMSSerializerBundle($this),
new FOS\CommentBundle\FOSCommentBundle(),
new Sonata\CommentBundle\SonataCommentBundle(),
new Application\Sonata\CommentBundle\ApplicationSonataCommentBundle(),
// SONATA CORE & HELPER BUNDLES
new Sonata\EasyExtendsBundle\SonataEasyExtendsBundle(),
new Sonata\CoreBundle\SonataCoreBundle(),
new Sonata\IntlBundle\SonataIntlBundle(),
new Sonata\FormatterBundle\SonataFormatterBundle(),
new Sonata\CacheBundle\SonataCacheBundle(),
new Sonata\BlockBundle\SonataBlockBundle(),
new Sonata\SeoBundle\SonataSeoBundle(),
new Sonata\ClassificationBundle\SonataClassificationBundle(),
new Application\Sonata\ClassificationBundle\ApplicationSonataClassificationBundle(),
new Sonata\NotificationBundle\SonataNotificationBundle(),
new Application\Sonata\NotificationBundle\ApplicationSonataNotificationBundle(),
new Application\Sonata\SeoBundle\ApplicationSonataSeoBundle(),
new Sonata\DatagridBundle\SonataDatagridBundle(),
// Search Integration
//new FOS\ElasticaBundle\FOSElasticaBundle(),
// CMF Integration
new Symfony\Cmf\Bundle\RoutingBundle\CmfRoutingBundle(),
// DEMO and QA - Can be deleted
new Sonata\Bundle\DemoBundle\SonataDemoBundle(),
new Sonata\Bundle\QABundle\SonataQABundle(),
// Disable this if you don't want the timeline in the admin
new Spy\TimelineBundle\SpyTimelineBundle(),
new Sonata\TimelineBundle\SonataTimelineBundle(),
new Application\Sonata\TimelineBundle\ApplicationSonataTimelineBundle(), // easy extends integration
new Mopa\Bundle\BootstrapBundle\MopaBootstrapBundle()
);
No matter what route i access
/blog
/page
/media
/admin
All i see is white screen and no error in app_dev.log.
I am using Ubuntu with xampp, all other symfony projects are working fine, except this Sonata Project. My xampp logs also do not mention any error that could be causing this. In fact i cleared my log files so only Sonata related errors are logged if any and at the moments all log files are empty too.
While trying to install using composer
composer create-project sonata-project/sandbox:dev-2.4-develop
or
composer create-project sonata-project/sandbox:dev-2.3-develop
or
composer create-project sonata-project/sandbox:2.3.x-dev
I get the following error
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for doctrine/doctrine-migrations-bundle ~2.0#dev -> satisfiable by doctrine/doctrine-migrations-bundle[2.0.x-dev].
- doctrine/doctrine-migrations-bundle 2.0.x-dev requires symfony/symfony >=2.0,<2.1 -> no matching package found.
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting
see for more details.
Read for further common problems.
I followed these instructions as well but no luck.
Since this is my first time with Sonata so I might be doing something wrong. I will really appreciate any help on this.
You have to change in file composer.json, line 34 to:
"doctrine/doctrine-migrations-bundle": "1.0.*",
After that enter this command in sandbox folder:
composer update
The minimum-stability of the project you try to install is set to a option higher than dev. So composer will not be able to install this project.
First try to install a stable version of the project, and try to upgrade to a dev version afterwards by changing the minimum-stability to dev.
composer create-project sonata-project/sandbox
I'd advise you to also set prefer-stable to true, so the other packages will not all switch to the dev-master branch.

Categories