Magento 2 : 404 issue
Question
- Magento 2 'Home Page'
throws "Invalid Document Element 'type': Character content other than whitespace is not allowed because the content type is 'element-only'" in developer mode
but it's coming fine in production mode.
All other pages (such as http://example.com/admin, http://example.com/contact, http://example.com/catalogsearch/advanced/ ) gives 404 error in both developer and production mode.
Note : above such are done with 'var' and 'pub' directories recursively given 777 permission.
- It also gives "SOAP-ERROR: Parsing WSDL: Couldn't load from....." may be because of the same issue.
Though SOAP is enabled, IP in host file is okay but SOAP connection gets failed.
Note:
I already followed the solutions given in magento forums and stackoverflow, stackexchange.. etc, But the problem still persists.
Solution
The issue has been solved by following the below steps:
i. applying proper permissions, ii. enable apache rewrite_module iii. refresh apache server.
sudo chmod -R 777 /var/www/html/MAGENTO_2_ROOT_DIRECTORY/ sudo a2enmod rewrite sudo service apache2 restart
run following command from Magento root:
php bin/magento setup:static-content:deploy
Now clear var directory except .htaccess file and check admin. If still the issue persists, then it may be because of Symlink. For this, Edit apache config file
sudo gedit /etc/apache2/apache2.conf
and replace this code :
Options Indexes FollowSymLinks AllowOverride none Require all granted
with
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
Note: changed AllowOverride none to AllowOverride All
Now restart apache sudo service apache2 restart
and check admin. This should fix admin 404 issue.
- Also make sure, you don't leave
/app/etc/ directory
writable
OTHER TIPS
I believe the problem comes from the xml of a theme or a module. The fact that it "works fine" in production mode is just that the errors are not displayed but logged (var/log/
most probably or var/report/
).