Step 1: -
We need to set document root to pub, to do this go to file C:\xampp\apache\conf\extra\httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/magento24/pub"
ServerName yourname.magento.com
</VirtualHost>
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.
127.0.0.1 yourname.magento.com
Step 3: - Update the base URL:
Go to our magento database and run below command
UPDATE core_config_data SET value='http://yourname.magento.com/' WHERE path='web/unsecure/base_url';
Step 4:- Update the app/etc/env.php file
The following node needs to be appended to the env.php file.
'directories' => [
'document_root_is_pub' => true
]
Step 5 : - Switch to developer mode.
php bin/magento deploy:mode:set developer
php bin/magento cache:flush
Hurray !!! All done .... Lets check your
homepage http://yourname.magento.com/ and
admin page http://yourname.magento.com/admin