How to Change Admin URL in Magento 2 Easily

Magento is one of the most widely used ecommerce platforms out there. The CMS  is recognized for its security as well as it is the most secure among many platforms for ecommerce store.

While there are many best practices recommended for the security of Magento store, one highly recommend practice is to use a unique URL for Magento admin rather than using the default URL.

In this tutorial, I am going to teach you how to change the admin URL in Magento 2. There are multiple methods of doing it:

  • Through the Admin Panel
  • Via a Command Line
  • By Editing the env.php

Method 1: Through the Admin Panel

Open the Admin panel of your store and navigate to STORES → Configuration

Scroll down and click on Admin under ADVANCED.

Now unfold the Admin Base URL section. Select Yes from Use Custom Admin Path drop down and enter the admin path of your choice in a Custom Admin Path text field like I have:

Method 2: Via a Command Line

Connect your store with an SSH terminal and go to the root directory of your Magento 2 store. Now just run the following command:

php bin/magento setup:config:set --backend-frontname="magento"

In the command above, I have set the admin URL path as magento, and you can set it as whatever you desire.

Method 3: By Editing env.php

Open the env.php file in the text editor by going to app/etc directory from the root directory of your store. Now, you will see the following code:

I have set the ‘frontName’ as magento, but you can change it to one of your choice.

I have discussed three methods of changing the Admin URL in Magento 2. After using the method of your choice, you have to clean the cache. To do that, run the following commands in the Magento 2 root directory:

Wrapping Up

Every ecommerce store must have a secure admin URL. After following this tutorial, you should now be able to change the Admin URL of Magento 2. If you still have any confusion or want to discuss something, feel free to use the comment box below!

About Author

Syed Muneeb Ul Hasan is an expert in PHP and Magento, he prefers to educate users in implementing and learning Magento. When not working, he loves to watch cricket.

  • Mammouth

    Please change Url to Path in the title of the article, please …. the current version is quite misleading …..