Question

How to enable /wp-admin on subdomains

Hello,

I’ve created 2 subdomains for my domain.com: dev.domain.com and dev2.domain.com. I created them by copying databases and apache configs. I made the necessary changes in apache configs and enabled them, but did nothing with databases for now.

So dev. dev2. domains are working - I can open them and when I change something on domain.com these changes do not impact dev. and dev2.

But there’s one problem. When I am trying to connect to dev.domain.com/wp-admin and dev2.domain.com/wp-admin they both redirect me to domain.com/wp-admin.

Can you please guide me to where I must make changes to enable dev. and dev2 /wp-admin to work independently from each other and from domain.com. If I am not mistaken I must change something in my databases.

Please ask if you need more information.


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
November 11, 2019
Accepted Answer

Hello,

Yes, indeed you are correct. What you need to do is:

  • Make sure that your wp-config.php files for your new subdomain names are set to the new databases and database users that you’ve created

  • You need to run a search and replace for your new databases to update all of the references for your domain to your subdomain name

For example to do that you could either use the wp-cli toolor the following script:

https://interconnectit.com/products/search-and-replace-for-wordpress-databases/

If you decide to go with the wp-cli tool, the command that you would need to use would look something like this:

wp search-replace 'http://example.com' 'http://sub1.example.com'

It is best to run that command from within the document root directory of your new sub domain so that the tool could pick up the database details from your wp-config file.

Note that this is a really dangerous operation as it can mess up your whole database in case anything goes wrong so it is very important to always make a backup of your database before proceeding with the operation.

Hope that this helps! Regards, Bobby

This comment has been deleted

    Try DigitalOcean for free

    Click below to sign up and get $200 of credit to try our products over 60 days!

    Sign up

    Get our biweekly newsletter

    Sign up for Infrastructure as a Newsletter.

    Hollie's Hub for Good

    Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

    Become a contributor

    Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

    Welcome to the developer cloud

    DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

    Learn more
    DigitalOcean Cloud Control Panel