How to change the OpenCart admin URL and protect the admin folder

To change the OpenCart admin URL, you give the admin folder, whose address is the OpenCart admin login page, a unique name. In OpenCart 4 you do this from the admin panel itself, with the Important Security Notification! window. In OpenCart 3 you rename the folder from the cPanel File Manager and edit the admin/config.php file. For real protection you also add a second password to the folder with cPanel's Directory Privacy, and you don't write the new name in robots.txt.

Why change the OpenCart admin URL

The address example.gr/admin is the same on every OpenCart store. Bots try it constantly with brute force attacks, meaning thousands of username and password combinations. With a different folder name, most automated requests don't even find the login page. This change is one step of OpenCart security, not a substitute for a strong password.

Which OpenCart version do I have

Log in to the OpenCart admin and look at the bottom of the page. The version is shown there, for example 4.1.0.4 or 3.0.5.1. The instructions differ between 4.x and 3.x, so follow the section for your version.

Before you start

  • Check that there is a recent backup. At Konet, JetBackup 5 keeps backups automatically and you can restore the folder or the whole site with the JetBackup 5 guide.
  • Download a copy of admin/config.php to your computer from the cPanel File Manager.
  • Choose the new name. Use only Latin letters and numbers, for example diaxeirisi7k2. Avoid obvious names such as admin1 or backend.
  • Write down the new address somewhere. After the change, example.gr/admin will no longer open the login page.

Changing the admin folder in OpenCart 4

In OpenCart 4 the rename is done from the admin panel. OpenCart copies the files to the new folder by itself and updates admin/config.php.

  1. Log in to the admin panel at example.gr/admin.
  2. On the Dashboard, the Important Security Notification! window appears.
  3. Open the Move admin directory section.
  4. In the field that says admin, delete it and type the new name.
  5. Click Move and wait for the files to finish copying.
  6. OpenCart takes you to the new login page, for example example.gr/diaxeirisi7k2/. Log in again.
  7. On the Dashboard, the same window now shows the Delete previous admin directory section. Open it and click Delete to remove the old admin folder.

If you see the message config.php and admin/config.php need to be made writable!, open File Manager, select the two files, click Permissions and check that the owner has write permission, for example 644. Save with Change Permissions and try Move again.

OpenCart does not accept admin, catalog, extension, image, install or system as the new name, because these are folders of the store itself.

Rename the admin folder in OpenCart 3

In OpenCart 3 the security window only deals with the storage folder. You rename the admin folder by hand.

  1. Open cPanel > Files > File Manager and go to the store's folder, usually public_html.
  2. Select the admin folder and click Rename in the toolbar, or right-click and choose Rename.
  3. Type the new name and confirm.
  4. Go into the renamed folder, select config.php and click Edit.
  5. In the three lines that mention admin/, replace admin with the new name and save the file.

After the change, the three lines look like this:

define('HTTP_SERVER', 'https://example.gr/diaxeirisi7k2/');
define('HTTPS_SERVER', 'https://example.gr/diaxeirisi7k2/');
define('DIR_APPLICATION', '/home/xxxxx/public_html/diaxeirisi7k2/');

Keep exactly the path the file already had and change only the folder name. The config.php file in the store's root does not need any change, because it doesn't mention the admin folder.

How do I know the change worked

  • example.gr/admin no longer opens the login page, but a page-not-found page.
  • The new address opens the login page and you log in normally.
  • Inside the admin panel, orders, products and the image manager open correctly.
  • The store works as before for visitors.

How do I add a second password to the admin page

The new name makes things harder for bots, but it is not a password. With Directory Privacy the browser asks for a username and password before the OpenCart login page even loads.

  1. Open cPanel > Files > Directory Privacy.
  2. Find the new admin folder and click Edit in the Actions column.
  3. Tick Password protect this directory, type a name in Enter a name for the protected directory and click Save.
  4. Create a user in Username with its own password, different from the OpenCart password, and click Save.

You will find detailed steps in the Directory Privacy guide. Search engines cannot see a page that asks for a password, so the login page won't appear in search results.

How do I enable two-factor in OpenCart 4

OpenCart 4 has a built-in option. Open System > Settings, edit the store, go to the Server tab and enable Two-factor Security for administrators. From then on, when you log in from a device that has not been approved, OpenCart sends a code to the user's email. The option requires email sending to be set up in the store. Also check that each administrator's email address is correct, otherwise they won't be able to log in.

In OpenCart 3, two-factor authentication is only possible with an extension from the OpenCart Marketplace. Choose an extension that explicitly supports your version.

Frequently Asked Questions

Should I add the new folder to robots.txt with Disallow?
No. robots.txt is a public file and anyone can open it at example.gr/robots.txt. If you write the folder there, you hand the new address to anyone looking for it. To keep the login page out of search engines, Directory Privacy is enough. If you already had Disallow: /admin/, you can leave it, because that folder no longer exists.

After the change I see a blank page or an error at the new address, what do I do?
In OpenCart 3, usually the path in one of the lines of admin/config.php is still wrong. Compare the file with the copy you downloaded and check that the new name is written the same everywhere, with the trailing slash. If you can't find the mistake, upload the original file back and rename the folder to admin again. In any version you can restore the site from JetBackup 5.

An extension stopped working in the admin panel, why?
Some extensions and themes have the admin/ path hard-coded instead of reading it from the settings. In OpenCart 3, first click the refresh button in Extensions > Modifications. If the problem remains, ask the extension's developer for a fix or go back to the old name until it is fixed.

What is the Move storage directory I see in the same OpenCart 4 window?
The storage folder holds logs, cache, sessions and downloadable files. OpenCart recommends moving it outside public_html, so that it can't be opened from the browser. The new folder name must start with storage, for example storage_example. Do this step with a recent backup, just like the admin rename.

I forgot the Directory Privacy password, how do I get in?
Open Directory Privacy again on the same folder and set a new password for the user, or create a new user. This password is independent of the OpenCart administrator password.

Are the store's customers affected?
No. The store works normally. Only those logged in to the admin panel will need to log in again at the new address. Make the change at a quiet time, after you finish the orders you are processing.

Was this article helpful?

Related service Konet Web Hosting cPanel, LiteSpeed and automatic backups: 24 every 2 hours for 48 hours, then 6 daily, 4 weekly and 3 monthly.