How to Run Magento 2 using pub/index.php file

Magento 2 comes with two index.php files where one file is inside root folder and another one is inside /pub folder. Magento 2 offers to run your application using any one of this file. If you choose to run your application using /pub/index.php then it is a good decision for security point of view as it restrict unauthorized direct access of application files.

Here i will show you how to configure Magento 2 in localhost using pub/index.php file by creating virtualhost. You can do the same by following below steps after installing Magento 2.

  1. Open httpd-vhosts.conf file of apache server. You wll find this file at “D:\xampp\apache\conf\extra” location.
  2. Create virtual host by adding below code in httpd-vhosts.conf file.
    vhosts
  3. Save httpd-vhosts.conf file and restart apache server.
  4. Open C:\Windows\System32\drivers\etc\hosts file and add your server Name entry as like below.
    hosts
  5. Open your Magento 2 database table “core_config_data“. Update value for path “web/unsecure/base_url” and “web/secure/base_url” to “http://local.magento2.com/“.
    core-config-data
  6. Open web browser and hit URL: “http://local.magento2.com” for frontend and “http://local.magento2.com/admin” for backend.
    frontendbackend

Now your application is running using pub/index.php file.

Leave a comment