简体   繁体   中英

Forced to execute assetic dump on development mode in Symfony2 with virtual hosts

I'm trying to find a way to solve my problem but I don't find any solution. I'll try to explain the better I can.

I'm developing my website in a local environment, on a MAMP server. The home URL is http://localhost:8888/mysite/web/app_dev.php . I wanted to change it to http://site.dev for the dev mode (later, I will use http://site.prod for the prod mode). Some of you will ask me "why ?". The answer is that we want (the other developers and I) to have the same kind of URL than in my production like http://example.com

So, I looked on the side of the Apache's virtual hosts and the host file on my computer. I changed the Apache port to 80 and the MySQL port to 3306 (Nginx is 80 by default too).

Here is the httpd-vhosts.conf file :

NameVirtualHost *:80

<VirtualHost *:80>
    DocumentRoot /Applications/MAMP/htdocs
    ServerName localhost
</VirtualHost>

<VirtualHost *:80>
    ServerName site.dev
    ServerAlias www.site.dev

    DocumentRoot /Applications/MAMP/htdocs/site/web
    <Directory /Applications/MAMP/htdocs/site/web>
        AllowOverride All
        Order Allow,Deny
        Allow from All
    </Directory>
</VirtualHost>

The hosts file :

127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost 
fe80::1%lo0     localhost

127.0.0.1       site.dev

Obviously, I activate the vhosts in my apache httpd.conf file :

# Virtual hosts
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf

Here is my new web/.htaccess file :

DirectoryIndex app_dev.php

<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]

    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]

    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^app_dev\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]

    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule .? - [L]

    RewriteRule .? %{ENV:BASE}/app_dev.php [L]
</IfModule>

<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>
        RedirectMatch 302 ^/$ /app_dev.php/
    </IfModule>
</IfModule>

Now, I go on http://site.dev , everything works fine. I make a changement in my script.js file (for example), then, I refresh my home page. Nothing changed... I try to execute php app/console assetic:dump , I refresh one more time, and, miracle, everything works.

So, my question is the following one : How can I use my http://site.dev virtual host WITHOUT the need of executing the assetic:dump console function.

Thank you

EDIT : I didn't find a solution to my problem, so, I will give you more details : - When I go on http://localhost/site/ , I see all the directories and files of the root directory. - When I go on http://localhost/site/web/ , all the website is displayed but there are missing images (bad path in twig or less files) and I have to execute assetic:dump . - When I go on http://localhost/site/web/app_dev.php , everything is refreshed instantly...

php app/console assets:install web --symlink

This should symlink your assets, so you wont need to re-run the asset command each time .

Also, check out http://symfony.com/blog/new-in-symfony-2-6-smarter-assets-install-command

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