When not in production mode Magento 2 will try to create symlinks for some static resources. You can change that behavior by doing the following.
Open up app/etc/di.xml
and find the virtualType name="developerMaterialization"
section.
In that section you'll find an item name="view_preprocessed"
that needs to be modified or deleted. You can modify it by changing the contents from Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink
to Magento\Framework\App\View\Asset\MaterializationStrategy\Copy
Delete the files under pub/static to get rid of any existing symlinks. You may want to be careful not to delete the .htaccess
file.
This should solve your error with the symlink.
It seems now Magento will only load from pub folder. By default it will not be possible to load it from the root of Magento.
So the best solution for this is to create a virtual host and point it to pub directory.
Alternative
Meanwhile, as an alternative to run this on local machine I tried something else that seems to be working fine with the default setup. Like earlier we were using the base_url
as http://127.0.0.1/magento
. So instead of this now we need to use http://127.0.0.1/magento/pub
as the base_url
. Secure and Unsecure URL needs to be setup on the basis of this.
Setting this up will avoid the issue of 404 page coming.
Note: Verified this with the default Magento only. Not sure for the projects having much complex functionalities. But you can give this a try.
We have another option without adding /pub follow below steps
1. Copy .httaccess file from pub folder and override it to root .htaccess file
2. Upload pub/index.php file to root magento directory
3. Add below code in app/etc/env.php file
'system' => [
'default' => [
'web' => [
'unsecure' => [
'base_media_url' => '{{secure_base_url}}pub/media/',
'base_static_url' => '{{secure_base_url}}pub/static/'
],
'secure' => [
'base_media_url' => '{{secure_base_url}}pub/media/',
'base_static_url' => '{{secure_base_url}}pub/static/'
]
]
]
],
Best Answer
Step 1: -
We need to set document root to pub, to do this go to file C:\xampp\apache\conf\extra\httpd-vhosts.conf
paste this code at the bottom of the file.
yourname.magento.com - this is domain name which you set as per your wish. So now you need to access magento frontend and admin with base url "yourname.magento.com".
Step 2:-
Now lets edit C:\Windows\System32\drivers\etc\hosts file and add the below line at the bottom of the file.
Step 3: - Update the base URL:
Go to our magento database and run below command
Step 4:- Update the app/etc/env.php file
The following node needs to be appended to the env.php file.
Step 5 : - Switch to developer mode.
Hurray !!! All done .... Lets check your
homepage http://yourname.magento.com/ and
admin page http://yourname.magento.com/admin