How to add an admin user to your WordPress using Virtualmin

🚑 Quick Instructions

Here are some quick instructions (for the detailed instructions see below):

Run the follwing SQL script under the desired site’s database. Make sure to replace the distinguished text with the desired values, and keep the quotes exactly as shown here.

⭐ Adding a User:

INSERT INTO `wp_users` (`user_login`, `user_pass`, `user_nicename`, `user_email`, `user_status`)
VALUES ('SomeNewUserName', MD5('SomeLongPassPhrase'), 'DisplayNameForUser', 'EmailAddressForNewUser', '0');
INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`)
VALUES (NULL, (Select max(id) FROM wp_users), 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');
INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`)
VALUES (NULL, (Select max(id) FROM wp_users), 'wp_user_level', '10');

⭐ Removing a User:

SET @user_id = (SELECT id FROM wp_users WHERE user_login = 'SomeExistingUserName');
DELETE FROM wp_users WHERE id = @user_id;
DELETE FROM wp_usermeta WHERE user_id = @user_id;

Using the SQL code execution service in Virtualmin is buggy (as of 2023-07-30). The code must be run from a file.

🧾 Detailed Instructions

1. Find the name of your site’s database

  • Using Virtualmin’s File Manager, or SSH (if you prefer SSH), locate the file wp-config.php, and view its contents to see what’s the database name.

2. Run the SQL query

  • Head over to the Database Editor, and click the button titled Manage next to the database you found in the previous step.
  • On the next page, click the button Excute SQL.
  • Enter the SQL query, change the values to the information of new user you want to add (or delete).
  • Alternatively, switch to the section titled Run SQL from file, and upload a text file that contains your query.
  • Click Execute. And you’re good to go.
    The result would look something like this:

3. Test it out

  • If you’ve added a new user, now would be a good time to head over to your WordPress login page to try the new user.
    The wordpress login screen is usually located at an address like: https://www.example.com/wp-login.php

Domain expired? How to migrate your WordPress site to a new domain.

If you’ve lost access to your domain (or subdomain) for whatever reason, and now you want to migrate your site to a new address, the process is unfortunately not very straight forward, and this is why we have this guide for you.

Please make sure to perform these steps in the order they are listed here.

1. Update DNS

The first step is to add your DNS records to the new domain. Typically you only need to add CNAME records for www and sftp pointing to the hostname of your hosting server.

If you have sites hosted on other subdomains, don’t forget to add them as well.

2. Update the Web Server

You need to tell the web server that your domain name has changed, so that it will start serving your site on the new domain.

This can be done from your Virtualmin administration panel, if you have the access to do it. If you cannot see this option, contact our support team and they will be happy to have this done for you.

This is how it would look like if you have access to this option:

3. Take a Backup

Take a backup of your site and settings before you do tests, just in case…

4. Update Your WordPress URL

At the time of this writing, WordPress will not allow you to access the management dashboard using the new domain name. What will happen is that your browser will keep getting redirected to the old domain as you try to access the dashboard from an address like http://example.com/wp-admin.

To fix this, you have first to add a couple of lines to wp-config.php. You can edit this file using Virtualmin’s file manager. Locate the file, right-click it and select Edit. Then add these two lines:

define('WP_HOME','http://example.com');
define('WP_SITEURL','http://example.com');

Of course, replace example.com with your new domain.

Once saved, you can now access the dashboard from an address like http://example.com/wp-admin.

Go to Settings -> General and update the site’s address fields.

Now you can revert the change made in wp-config.php.

Alternatively, you can update the site’s URL directly in the database via Virtualmin’s database management tool:

  1. Find the wp_options table and click it.
  1. Click View Data button.
  1. Locate the siteurl and home rows and change their option_value to the new domain name.

5. Use a Search and Replace to Update URLs

You face now the issue of having resources embedded on the sites’ pages still linked to the old domain. If you visit your site, you’ll see that images, videos, CSS styles, etc, will not be visible at the moment because WordPress usually stores the full URL of the resources, including the domain, in the database.

If you have the necessary expertise, you can use database queries to find and update all URLs in the database.
Alternatively, use a plugin like “Better Search & Replace” to replace the old domain and update permalinks and other URLs. Disclaimer: This plug-in was recommended by a search engine. Feel free to browse the WordPress Plugin catalogue for many other options.