简体   繁体   中英

symfony2 assets targets the /www server folder, not the /web symfony folder when deploy in production

I have some problems with Symfony 2 application deployment. I have import all files I need on my OVH shared server, but some errors occured like css and js files not found (internal server error for example) or error like Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://my-server/css/458dafd_bootstrap-theme.min_1.css" .

Notice that I have installed the CoresphereBundle in order to have a console in my browser when my application is iploaded on my server, I have access to the console only on dev environment.

This is step by step what I did in order to deploy my application:

1 I updated my application and vendors with composer (because I have no ways to install composer on my server)

composer.phar update

2 I clear the dev cache php app/console cache:clear

3 I clear the prod cache php app/console cache:clear --env=prod --no-debug

4 I install assets php app/console assets:install web

5 I dump the assets php app/console assetic:dump web

6 I uploaded my symfony application on my server.

7 Once the files are uploaded in web/app.php II authorize the prod debug

$kernel = new AppKernel('prod', true);

8 Then in web/config.php I remove this block

// …

if (!in_array(@$_SERVER['REMOTE_ADDR'], array(
  '127.0.0.1',
  '::1',
))) {
  header('HTTP/1.0 403 Forbidden');
  exit('This script is only accessible from localhost.');
}

So, on my server, if I would like to go to http://my-server/web/config.php it works well, so I see if my server is compatible with symfony. the only thing that appears is Set short_open_tag to off in php.ini*.

9 I set the access rights for the app/cache and app/log folders to 777 on my server, it allows the applications to write in these folders.

10 In web/app_dev.php I write this code, in order to allow the dev mode for my IP adress and so have access to the console bundle

// …

if (!in_array(@$_SERVER['REMOTE_ADDR'], array(
  '127.0.0.1',
  '::1',
  '121.457.719.2' //a random ip adress it's just for you to understand
))) {
  header('HTTP/1.0 403 Forbidden');
  exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}

11 So I have access to the dev environment on my server, all works well, and no errors occured here. To access to the console bundle, following to the bundle documentation, I have to wrote http://my-server/web/app_dev.php/_console (see the routing code here):

_console:
    resource: "@CoreSphereConsoleBundle/Resources/config/routing.yml"
    prefix: /_console

But this routes does not exist, If I wrote this url, nothing appear in my browser: 在此处输入图片说明

However, by the config.php , I have access to app_dev.php by following the Bypass configuration and go to the Welcome page link:

在此处输入图片说明

I click on the link and I arrived on app_dev.php . Like I said before, no errors occured in this environment, except for the console route. But I could have access to the console by clicking on the console logo under the symfony debug toolbar: 在此处输入图片说明

This is the url for the console when I click on the logo under symfony debug toolbar: http://my-server/web/app_dev.php//_console/_console , I would like to understand why?

Then when I would like to make some commands another error occured: [error] Internal Server Error in the console: 在此处输入图片说明

If I try to use the router debug php app/console debug:router , I have this: 在此处输入图片说明

and with the php app/console debug:router | grep _console php app/console debug:router | grep _console : 在此处输入图片说明

So, there are the problems I have with my symfony application.


UPDATE

I resolved the problem of the console bundle. In fact my server does not use the same php version of my symfony application, I have to set this in the .ovhconfig at the root of my /www folder. /www/.ovhconfig :

app.engine=php
app.engine.version=5.5
http.firewall=none
environment=production

Now when I would like to access to the production environment I have these errors concerning all my assets files ( css/js/images , a 404 not found):

Failed to load resource: the server responded with a status of 404 (Not Found) -> http://my-server.com/bundles/fosjsrouting/js/router.js

Uncaught ReferenceError: fos is not defined -> routing:1

Failed to load resource: the server responded with a status of 404 (Not Found) -> http://my-server.com/css/45898d_dataTables.min_7.css

I don't really understand, the files are indeed at the root of the app, eg I have no folder css or js or etc in http://my-server.com/ . These folders are in http://my-server.com/web/ . Where is the problem?

When I access to the console, this is the command I made:

1 cache:clear

2 assets:install web

3 assetic:dump web


EDIT: solution works

I understand that the assets target a /css /js /images etc folder at the root of my server, so I replace the css and js files to the root of the /www server folder, eg in the /www folder of my server I have this:

//my server
  /.ssh
  /www /*http://my-server.com/...*/
    /app/
    /bin/
    /css/
    /fonts/
    /images/
    /js/
    /src/
    /vendor/
    /web/
    /.htaccess
    /.ovhconfig
    /composer.json
    /composer.lock
    /composer.phar

Why my symfony application tagets the assets here?

Have you tried to use the Symfony command line routing debugger?

php app/console debug:router

That will output all the routes the symfony app knows about and you could try piping it into grep to see if you're trying to use the wrong path to hit the _console route.

php app/console debug:router | grep _console

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM