1

I have been trying to install Magento on Centos 7 with Nginx and Maria Db for the past 2-3 days now but each time I got errors. I have tried several ways and changed Nginx configuration file and tried many possible solutions available on stackoverflow and Magento docs.

I was only able to install it correctly once, but that was giving me server level error i.e. php-fpm security.limit_extensions. Therefore, I made the necessary changes to Nginx and I am not getting this error anymore. However, now my installation has 404 error on all the CSS and other files. As shown in the image below.

Store Home Page:

enter image description here

Store Admin Panel enter image description here

Nginx logs are full of errors like:

> 2020/07/05 08:23:45 [error] 8864#8864: *94 open()
> "/var/www/user/pub/static/version1593936946/adminhtml/Magento/backend/en_US/css/styles.css"
> failed (2: No such file or directory), client: x.x.x.x, server:
> www.domain.com, request: "GET
> /pub/static/version1593936946/adminhtml/Magento/backend/en_US/css/styles.css
> HTTP/1.1", host: "www.user.com", referrer:
> "https://www.user.com/index.php/admin_h7r4ak/admin/index/index/key/57fe0e9d24ad111c0afbf63b34a7fd456106047e74662ae8a/"

I have tried to give magento directory permissions with both, `files and & dir as 777' and also as mentioned in Magento docs i.e.

find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} + find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +

But this does not help. I have tried to install with both users i.e. nginx:nginx and user that i added to nginx group user:nginx. The result is same, as shown in the above images.

My Nginx.conf file:

    server {
    listen   80;
    server_name  example.com;
    root /var/www/example;
    return   301 https://www.example.com$request_uri; 
    }
    server {
    listen   80;
    server_name  www.example.com;
    root /var/www/example;
    return   301 https://www.example.com$request_uri; 
    } 
    server {
    listen   443 ssl http2;
    server_name example.com;
    keepalive_timeout    70;
    root   /var/www/example;
    return   301 https://www.example.com$request_uri;

    gzip    on;
    ssl_certificate  /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key  /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
    ssl_protocols   TLSv1.2;
    ssl_ciphers     EECDH+AESGCM:EDH+AESGCM:ECDHE-RSA-AES128-GCM-SHA256:AES256+EECDH:DHE-RSA-AES128-GCM-SHA256:AES256+EDH:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4:!3DES;
    ssl_dhparam     /etc/nginx/conf.d/dhparam.pem;
    ssl_prefer_server_ciphers   on;
    ssl_session_tickets     off;
    ssl_session_cache       shared:SSL:10m; 
    }

    server {
    listen   443 ssl http2;
    server_name www.example.com;
    keepalive_timeout    70;

    gzip    on;
    #       modsecurity on;
    #       modsecurity_rules_file /etc/nginx/modsec/main.conf;

    ssl_certificate  /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key  /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
    ssl_protocols   TLSv1.2;
    ssl_ciphers     EECDH+AESGCM:EDH+AESGCM:ECDHE-RSA-AES128-GCM-SHA256:AES256+EECDH:DHE-RSA-AES128-GCM-SHA256:AES256+EDH:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4:!3DES;
    ssl_dhparam     /etc/nginx/conf.d/dhparam.pem;
    ssl_prefer_server_ciphers   on;
    ssl_session_tickets     off;
    ssl_session_cache       shared:SSL:10m;

    add_header   X-Frame-Options "DENY";
    add_header   X-Content-Type-Options nosniff;

    access_log  /var/log/nginx/example.access.log;
    error_log   /var/log/nginx/example.error.log;


    set $MAGE_ROOT /var/www/example;      root $MAGE_ROOT/pub;
          charset UTF-8;      autoindex off;
  
    location / {
            root   /var/www/example;
            #try_files $uri $uri/ = /404.html;
            if ($request_uri ~ ^/(.*)\.html$) {  return 302 /$1;  }
            try_files $uri $uri/ $uri.html $uri.php?$args;
            #try_files $uri $uri/ /index.php$is_args$args;
            index  index.php index.html;
            add_header   Strict-Transport-Security "max-age=63072000; includeSubdomains" always;
    }

    error_page 404 403 = /errors/404.php;
    # redirect server error pages to the static page /50x.html
    #
    error_page  500 502 503 504  = /errors/50x.php;

  # PHP entry point for update application        
  location ~* ^/update($|/) {
      root $MAGE_ROOT;
      index  index.php;
      location ~ ^/update/index.php {
          fastcgi_split_path_info  ^(/update/index.php)(/.+)$;
          fastcgi_pass   php-fpm;
          fastcgi_index  index.php;
          fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
          fastcgi_param  PATH_INFO        $fastcgi_path_info;
          include        fastcgi_params;
      }

      # Deny everything but index.php
      location ~ ^/update/(?!pub/). {
          deny all;
      }

      location ~ ^/update/pub/ {
          add_header X-Frame-Options "SAMEORIGIN";
      }       }


  location /pub/ {
  location ~ ^/pub/media/(downloadable|customer|import|custom_options|theme_customization/.*\.xml)
  {
          deny all;
      }
      alias $MAGE_ROOT/pub/;
      add_header X-Frame-Options "SAMEORIGIN";        }

  location /static/ {
      # Uncomment the following line in production mode
      # expires max;

      # Remove signature of the static files that is used to overcome the browser cache
      location ~ ^/static/version {
          rewrite ^/static/(version\d*/)?(.*)$ /static/$2 last;
      }

      location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2|html|json)$
      {
          add_header Cache-Control "public";
          add_header X-Frame-Options "SAMEORIGIN";
          expires +1y;

          if (!-f $request_filename) {
              rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
          }
      }

      location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
          add_header Cache-Control "no-store";
          add_header X-Frame-Options "SAMEORIGIN";
          expires    off;

          if (!-f $request_filename) {
                  rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
          }
      }
          if (!-f $request_filename) {
          rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
      }
      add_header X-Frame-Options "SAMEORIGIN";        }

  location /media/ {
      try_files $uri $uri/ $uri.html $uri.php?$args;

      location ~ ^/media/theme_customization/.*\.xml {
          deny all;
      }

      location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
          add_header Cache-Control "public";
          add_header X-Frame-Options "SAMEORIGIN";
          expires +1y;
          try_files $uri $uri/ $uri.html $uri.php?$args;
      }
      location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
          add_header Cache-Control "no-store";
          add_header X-Frame-Options "SAMEORIGIN";
          expires    off;
          try_files $uri $uri/ $uri.html $uri.php?$args;
      }
      add_header X-Frame-Options "SAMEORIGIN";        }

  location /media/customer/ { deny all; }

  location /media/downloadable/ { deny all; }

  location /media/import/ { deny all; }

  location /media/custom_options/ { deny all; }

  location /errors/ {
      location ~* \.xml$ { deny all; }        }

  # Deny access to sensitive files        
  location /.user.ini { deny all; }

  ######################################################################
  ######################################################################

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~* \.php$ {
            root           /var/www/example;
            fastcgi_pass php-fpm;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            if ($request_uri ~ ^/([^?]*)\.php($|\?)) {  return 302 /$1?$args;  }
            try_files $uri = 404;
            fastcgi_split_path_info  ^(.+\.php)(/.+)$;
            fastcgi_param QUERY_STRING  $query_string;
            fastcgi_param REQUEST_METHOD  $request_method;
            fastcgi_param CONTENT_TYPE  $content_type;
            fastcgi_param CONTENT_LENGTH  $content_length;
            fastcgi_intercept_errors  on;
            
            fastcgi_param  PHP_FLAG  "session.auto_start=off \n suhosin.session.cryptua=off";
            fastcgi_connect_timeout  600s;
            fastcgi_read_timeout  600s;
            fastcgi_buffers 1024 4k;
            include  fastcgi_params;
    }


  gzip_disable "msie6";       
  gzip_comp_level 6;      
  gzip_min_length 1100;
  gzip_buffers 16 8k;
  gzip_proxied any;
  gzip_types
      text/plain
      text/css
      text/js
      text/xml
      text/javascript
      application/javascript
      application/x-javascript
      application/json
      application/xml
      application/xml+rss
      image/svg+xml;      gzip_vary on;

  # Banned locations (only reached if the earlier PHP entry point regexes don't match)
  location ~* (\.php$|\.phtml$|\.htaccess$|\.git) {
      deny all;       }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
            deny  all;
    } 
    }

I have set memory_limit to 3G and execution timeout to 18000. What am I missing here?

3 Answers 3

0

In development mode (the default after installing magento2) the app deploys assets to pub/static and also uses var/view_preprocessed to generate files. Try rm -rf pub/static/* && rm -rf var/view_preprocessed/*

Personally, i make a user called magento and add it to the www-data group, with a php-fpm pool configured for that user. I then sudo su - magento (for user magento) and deploy in there, saves problems with permissions every deployment. Happy to help if have issues still, for now though, add your user to www-data, then chown -r user:www-data the entire magento dir, and clear the static and view_preprocessed dirs

3
  • i have tried this way, ssh'd into the magento user which was in nginx group. installed magento successfully and finally executed this command rm -rf pub/static/* && rm -rf var/view_preprocessed/*. However, its same black messed up home and admin panel.
    – nix
    Commented Jul 5, 2020 at 12:00
  • The errors you show indicate either a. The folder can't be written to, or b. Incorrect nginx configuration. Is the folder being written to? E.g are you seeing content in there after flush cache and reload? (bin/magento c:f) Commented Jul 5, 2020 at 12:43
  • this is the output >> bin/magento c:f Flushed cache types: config layout block_html collections reflection db_ddl compiled_config eav customer_notification config_integration config_integration_api google_product full_page config_webservice translate vertex I have also given my nginx config file in the Question. I am not sure if something is wrong with that. Can you review?
    – nix
    Commented Jul 5, 2020 at 14:07
0

Try:

php bin/magento setup:static-content:deploy -f
13
  • here is the result >> link . you can see the content of pub/static directory too. However, the website searches for CSS files in pub/static/version1593957476/frontend/Magento/luma/en_US/mage/calendar.css' . I do not see any version* folder
    – nix
    Commented Jul 5, 2020 at 14:16
  • Ah I see. You will NOT see a "version*" folder. This is normal. Try flushing your cache and see if your assets are loading on the frontend now. Commented Jul 5, 2020 at 14:28
  • bin/magento c:f I see same result. in the pub/static/frontend/Magento/luma/en_US/css/ directory I can find the file style-l.css, however it gives 404 error in the web URL https://www.domain.com/pub/static/version1593959619/frontend/Magento/luma/en_US/css/styles-l.css
    – nix
    Commented Jul 5, 2020 at 14:51
  • I executed this command, but nothing... same missing files. php bin/magento indexer:reindex
    – nix
    Commented Jul 5, 2020 at 15:03
  • Double check your nginx configuration. If everything seems ok and you still can't get the version location to resolve, you can try disabling static file signing. Run this command at the cli then redeploy: bin/magento config:set dev/static/sign 0 Commented Jul 5, 2020 at 15:31
0

go to your magento root directory navigate to app/etc/di.xml

search for symlink and replace it with Copy now just flush:cache and check

7
  • I have already tried this, but the admin panel keeps loading, and javascript log shows some files missing. as shown in the image link
    – nix
    Commented Jul 6, 2020 at 6:34
  • i think you need to set perimission for pub/static just give it a try
    – Pramod
    Commented Jul 6, 2020 at 6:37
  • i have tried sooooo many ways, i gave all kinds of permission, 777/755/077/g+w/g+ws etc to files and directories. But each time, its same. I am using only SSL, i have HTTP disabled on server. I am not sure if it has to do something with it. Although, home page works fine.
    – nix
    Commented Jul 6, 2020 at 6:41
  • switch to developer mode and then run the deploy command or clear everything from pub static and generated
    – Pramod
    Commented Jul 6, 2020 at 6:42
  • I am already using developer mode and not default or production. I have also tried bin/magento setup:static-content:deploy -f several times now. @Chikku I don't have generated directory in pub/static , is it normal?
    – nix
    Commented Jul 6, 2020 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.