Magento 2.2 – Fix 404 on All Pages/Files Except Homepage

404magento2magento2.2

I setup a Ubuntu server with the LAMP at my home network for testing. I downloaded Magento-CE-2.2.0-2017-09-25-08-19-44.zip and extracted it into /var/www/html and started the installation process. The check was OK, I created the database, the hostname is set to 192.168.5.61, installation seemed to be OK.

But when I clicked the "Launch Magento Admin" at success page, it threw 404. So I visited 192.168.5.61 and the homepage showed, but it was only blank HTML – no styles or other things. I checked the page source code, the styles are linked there

<link  rel="stylesheet" type="text/css"  media="all" href="http://192.168.5.61/pub/static/version1506716871/frontend/Magento/luma/en_US/mage/calendar.css" />
<link  rel="stylesheet" type="text/css"  media="all" href="http://192.168.5.61/pub/static/version1506716871/frontend/Magento/luma/en_US/css/styles-m.css" />
<link  rel="stylesheet" type="text/css"  media="screen and (min-width: 768px)" href="http://192.168.5.61/pub/static/version1506716871/frontend/Magento/luma/en_US/css/styles-l.css" />
<link  rel="stylesheet" type="text/css"  media="print"     href="http://192.168.5.61/pub/static/version1506716871/frontend/Magento/luma/en_US/css/print.css" />

But when I want to view the file, I got 404.
First I thought the .htaccess is missing/ignored, but .htaccess in Magento root has 322 lines and adding random characters to it causes an internal server error, so the .htaccess is working.

Next thing I checked was the /pub/static directory, where all the styles are linked to. But it seems to be a bit empty:

adam@ubuntu:/var/www/html$ tree pub/static
pub/static
├── deployed_version.txt
└── frontend
    └── Magento
        └── luma
            └── en_US
                └── requirejs-config.js

What I did wrong? How to fix it? Still didn't do any work, so deleting everything and starting over is acceptable, but tried 2 times and still the same result.

//EDIT:
Rafael Corrêa Gomes provided an answer on how to recreate the missing files. However, the problem is with permissions settings, as the installer has no permissions to modify the files it creates during installation. My problem is caused by Apache and permission, so it's a bit off-topic for this forums, as it has nothing to do with Magento.

Best Answer

Seems like your URL_Rewrite isn't enabled.

Try using these commands in your folder /var/www/html:

alias mage="php -d memory_limit=-1 -f bin/magento";

chmod -R 775 pub/static/ var/ pub/media/ &&
rm -rf var/view_preprocessed/ var/cache/ var/page_cache/ var/tmp/ var/generation/ pub/static/frontend/;
composer install && composer update -vvvv;
mage deploy:mode:set developer;
mage config:set web/seo/use_rewrites 0;
mage setup:upgrade &&
mage cache:flush &&
mage indexer:reindex;
mage setup:static-content:deploy -f
chmod -R 775 pub/static/ pub/media/ var/

You can use just these commands if the issue is the folders permission:

find app/code pub/static app/etc var/generation var/di var/view_preprocessed vendor \( -type f -or -type d \) -exec chmod u-w {} \;
chmod o-rwx app/etc/env.php;
chmod u+x bin/magento
Related Topic