How to change your Magento 2 Store URLs

Magento 2 URL Change

Post deployment, we will want and need to change our IP address URLs to a more friendly domain name structure.


A very quick way that works on our deployment stacks for Magento Open Source are these simple steps from the ubuntu CLI:

We recommend you reset both legacy paths and new paths, plus reset your admin frontname. In our example, our domain name is

Magento 2.4.0+
sudo php bin/magento config:set web/secure/base_url “”
sudo php bin/magento config:set web/secure/use_in_frontend “”

sudo php bin/magento setup:store-config:set –base-url=””
sudo php bin/magento setup:store-config:set –base-url-secure=””

Note: Use the trailing “/” and stay consistent with HTTP or HTTPS.

Run our compile script after you finish.

sudo ./

Backend Admin Reset

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

Assuming defaults, replace the ##### with your unique frontname value found in the /magento/apt/ect/env.php file.

Note: Failure to reset the Admin frontname value could lead to 404s when attempting to access the admin dashboard.

Then clear your Magento Store cache:

sudo php bin/magento cache:flush

And last, reset permissions to baseline:

sudo chown -R www-data:www-data /var/www/magento

If you are using Redis, flush Redis too:

sudo redis-cli flushall

Hostname Reset/Update

Another reason we may need to change our Magento store URLs is if we installed our store using an IP address, and now we want to change to a DNS hostname.

The overall process is still exactly the same as the below video will show. The only addition would be to make sure the vhost server name is updated too! You should be using HTTPS for a production store, and if you are using Let’s Encrypt to get your cert, you’ll need to make sure your vhost is updated using the correct hostname.

Please refer to your aMiSTACX instructions to walk you through the process.