Skip to content

Magento 2 Installation: css/js/images not loading in php-fpm + nginx server #802

Closed
@MagePsycho

Description

@MagePsycho

I am trying to install Magento2(0.1.0-alpha107 ) in my localhost powered by OSX 10.10 + brew installed php-fpm + mysql + nginx.
Steps that I followed for installation:

 $ mkdir /path/to/magento2 && cd /path/to/magento2
 $ git clone [email protected]:magento/magento2.git .
 $ composer install
 $ cd setup
 $ composer install
 $ php -f index.php install --base_url=http://magento2alpha.dev/ --backend_frontname=admin --db_host=localhost --db_name=magento2alpha --db_user=root --db_pass=root --admin_firstname=Raj --admin_lastname=KB [email protected] --admin_username=admin --admin_password=pass123 --language=en_US --currency=USD --timezone=America/Chicago

So far everything worked great. But when you load the frontend: http://magento2alpha.dev/ it's showing plain text only (i.e. css/images/js are missing).

View source gives you the path like http://magento2alpha.dev/pub/static/frontend/Magento/blank/en_US/[css/images]/[css/images file] which led to the 404 page
My nginx conf file looks like:

server {
    listen 80;
    server_name magento2alpha.dev;
    root /Users/Raj/Sites/magento/magento2alpha;

    location /setup {
        try_files $uri $uri/ @setuphandler;
    }

    # Rewrite Setup's Internal Requests
    location @setuphandler {
        rewrite /setup /magento/magento2alpha/setup/index.php;
    }

    location / {
        index index.php index.html;
        try_files $uri $uri/ @handler;
    }

     # Rewrite Internal Requests
     location @handler {
        rewrite / /magento/magento2alpha/index.php;
     }

     # Rewrite magento2 static files
     #location /pub/static {
     #   rewrite ^/pub/static/(.*)$ /magento/magento2alpha/pub/static.php?resource=$1? last;
     #}

     location /pub/static {
          try_files $uri $uri/ @static;
     }

     location @static {
           rewrite ^/pub/static/(.*)$ /magento/magento2alpha/pub/static.php?resource=$1? last;
     }

     #location ~ .php/ {
     #    rewrite ^(.*.php)/ $1 last;
     #}

    location ~ \.php$ { ## Execute PHP scripts
        try_files $uri =404;
        expires        off;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_read_timeout 900s;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;

        ## Magento 2 Developer mode
        fastcgi_param MAGE_MODE "developer";
    }
}

I guess the issue lies in the static files rewrite. But this is what I followed from the github which is not working. Is there any workaround?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions