Local WordPress Multisite Setup

Setting up a local environment for a WordPress Multisite configuration requires additional steps beyond a normal single-site installation.

  1. Set up a Local WP installation, but in the Advanced section check the “Is this a multisite” box.

  2. Once the site is set up, import the database either by using wp-cli tools, Migrate, or the db tool of your choice. The steps for doing this with wp-cli tools are:

    1. Copy the database file into the root of the Local install directory and rename it to “local.sql"

    2. In Local, click on “Open in site shell"

    3. In the new Terminal window, type wp db import and hit enter

    4. Once the import is complete, change the urls by typing

      wp search-replace --url=example.com example.com example.test 'wp_*options' wp_blogs wp_site --network
  3. Assuming you don’t have an existing Super Admin account, you need to set one up for yourself. Using Local, click the Database tab and then click Open Adminer.

  4. Open the wp_users table and then Select Data

    image-20240327-144515.png

     

  5. Click New Item

  6. Fill in the relevant information:

    1. You need to know the ID for this new user, so if you use Auto Increment instead of manually putting in an ID you know isn’t already taken, you’ll need to revisit the wp_users table again once you're done to see what it was set to.

    2. Set the password field to MD5.

    3. Set the user_registered field to now.

      image-20240327-144646.png
  7. Click Save.

  8. Insert user meta values

    1. Go to the wp_usermeta table and click on New Item.

    2. Fill in the ID of the user you created in the previous step in user_id.

    3. For meta_key enter wp_capabilities

    4. For meta_value fill in the field with a:1:{s:13:"administrator";s:1:"1";}

       

    5. Click Save.

  9. You now have an administrator account for the main blog in the multisite, but you need to be a super admin to administer the entire network. Infomation about super admins in a multisite network is stored as site meta in wp_sitemeta table. In a single option. Most likely this option already exists. It means that we can use an UPDATE SQL query and replace the existing super admins with our new one just like this:

    UPDATE wp_sitemeta SET site_admins='a:1:{i:1;s:8:"kalamuna";}' WHERE site_id=1;

    Alternatively you can access the wp_sitemeta table and edit the site_admins field directly, replacing the current content with a:1:{i:1;s:8:"kalamuna";}

    Please note that after running this query all the existing super admins will stop being super admins! So maybe in your case it is better to change this option manually. But what is inside it? What is actually site_admins value?

    It is simple – it is just a serialized array of usernames, for example Array( 'rudrastyh' ), or Array( 'misha', 'rudrastyh' ), so you can use serialize() PHP function or any kind of a online tool out there to convert it to a:2:{i:0;s:5:"misha";i:1;s:9:"rudrastyh";}. You you can even format it by yourself:

    • a:2: – it means an array with 2 elements,

    • i:0;s:5: – it means the first element of array which is a string of length 5, i:1;s:9: – second array element which is a string of length 9.

  10. You are now the Super-Admin of the multisite install and should see the usual Network options now when you are in the dashboard.