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.
Related
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.
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
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.
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
My appKernel.php looks like this:
<?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\DoctrineBundle\DoctrineBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
new Blogger\BlogBundle\BloggerBlogBundle(),
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$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');
}
}
My autoload.php looks like:
<?php
use Symfony\Component\ClassLoader\UniversalClassLoader;
use Doctrine\Common\Annotations\AnnotationRegistry;
$loader = new UniversalClassLoader();
$loader->registerNamespaces(array(
'Symfony' => array(__DIR__.'/../vendor/symfony/src', __DIR__.'/../vendor/bundles'),
'Sensio' => __DIR__.'/../vendor/bundles',
'JMS' => __DIR__.'/../vendor/bundles',
'Doctrine\\Common' => __DIR__.'/../vendor/doctrine-common/lib',
'Doctrine\\DBAL' => __DIR__.'/../vendor/doctrine-dbal/lib',
'Doctrine' => __DIR__.'/../vendor/doctrine/lib',
'Monolog' => __DIR__.'/../vendor/monolog/src',
'Assetic' => __DIR__.'/../vendor/assetic/src',
'Metadata' => __DIR__.'/../vendor/metadata/src',
));
$loader->registerPrefixes(array(
'Twig_Extensions_' => __DIR__.'/../vendor/twig-extensions/lib',
'Twig_' => __DIR__.'/../vendor/twig/lib',
));
// intl
if (!function_exists('intl_get_error_code')) {
require_once __DIR__.'/../vendor/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';
$loader->registerPrefixFallbacks(array(__DIR__.'/../vendor/symfony/src/Symfony/Component/Locale/Resources/stubs'));
}
$loader->registerNamespaceFallbacks(array(
__DIR__.'/../src',
));
$loader->register();
AnnotationRegistry::registerLoader(function($class) use ($loader) {
$loader->loadClass($class);
return class_exists($class, false);
});
AnnotationRegistry::registerFile(__DIR__.'/../vendor/doctrine/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
// Swiftmailer needs a special autoloader to allow
// the lazy loading of the init file (which is expensive)
require_once __DIR__.'/../vendor/swiftmailer/lib/classes/Swift.php';
Swift::registerAutoload(__DIR__.'/../vendor/swiftmailer/lib/swift_init.php');
When I do:
php app/console assets:install web
I get the following:
Installing assets for Symfony\Bundle\FrameworkBundle into web/bundles/framework
Installing assets for Acme\DemoBundle into web/bundles/acmedemo
Installing assets for Symfony\Bundle\WebProfilerBundle into web/bundles/webprofiler
Installing assets for Sensio\Bundle\DistributionBundle into web/bundles/sensiodistribution
Why is my BloggerBlogBundle not getting copied over?
Note: As OP's answer is short and doesn't really go into too much detail, here's a more in-depth answer for future readers, so hopefully you don't have to do as much digging as I did! :)
It seems that we're following the exact same tutorial and have the exact same issue, and as the answer above isn't very descriptive and I had to do a little digging myself, here's exactly what's wrong.
Step 1
Your src/Blogger/BlogBundle needs to have, in the /resources folder, a public/css folder. So you need to place your CSS files as follows:
src/Blogger/BlogBundle/resources/public/css/<stylesheet>.css
Create the /public/css folder if it doesn't exist (it didn't exist for me).
Step 2
You need to run the assetic management tool to have a symlink created in /web automatically for you so these can be accessed.
php app/console assets:install web
You now will notice that if you open (using windows explorer / nautilus on linux) your dev directory and find the /web folder, that /web/bundles/bloggerblog/css/<stylesheet>.css has been created automatically for you!
You can now access your CSS files in your code using:
<link href="{{ asset('/bundles/bloggerblog/css/<stylesheet>.css') }}" type="text/css" rel="stylesheet" />
Note: '.css' is replaced with screen 'screen.css' for this tutorial
...and that should be it!
I have the the exact same problem with the original question, where assets are not copied over from Resources folder of bundles to web/bundles after running 'php app/console assets:install web' so what i did was running this command 'php app/console cache:clear --env=prod' and that fixed it. As you can see that you are dealing with prod assets or installing assets to prod environment in web directory, so clear cach for prod is reasonable. So do this:
1) $ php app/console cache:clear --env=prod
2) $ php app/console assets:install web
OR $ php app/console assets:install web --symlink
3) $ php app/console assetic:dump --env=prod (If you use built in Assetic, it will dump/combine css to one big one in /web/css as opposed to /web/bundles)
everything goes in place after that. you get all assets in your /web/bundles and assetic dump in /web/css and all of these are for prod env.
Just had this problem, ensure that the BlahBundle.php is located in the same directory as the Resources directory
I've had this issue today with Symfony3.3.13 and the problem was the public directory was actually capitalised Public, which seems to break the install script. Changing the name and it worked immediately.