• Resolved rozard

    (@rozard)


    Hi Community,

    Is it possible to have two WordPress instances in two different Virtual machines and share the same database and content directory? I have a WordPress website running on a Linux virtual machine with a MySQL database, which is installed in a separate VM. Now, I am trying to install another WordPress instance on another virtual machine (from a different location) to have a high-availability system. I created an NFS share, copied the wp-content directory to the NFS share, and mounted it with the first instance. I restarted Apache, and it seems to be working fine. I installed another WordPress, configured it with the same database, and mounted the wp-content directory with NFS share. The service is starting, but the issue is it’s redirecting me to the first vm. I know why it’s redirecting to the old instance; it is because the option_value of siteurl and home from the wp_options table is the old instance IP.

    Do you know how I can access both instances separately? The goal is to add both instances to the load balancer for HA. I know there is a networking option within WordPress, but that won’t work since I want to have the site on two different physical servers. In that, there won’t be downtime if I patch a server, or just in case of a disaster, I will at least have one instance running. If someone can guide me, I appreciate that.

    The page I need help with: [log in to see the link]

Viewing 10 replies - 1 through 10 (of 10 total)
  • Moderator bcworkz

    (@bcworkz)

    Each WP instance of course needs its own unique URL. You can manage the DB option values by setting constants in one instance that overrides the values in the options table. See WP_SITE_URL and the subsequent Blog Address section.

    As long as wp-config.php of each instance refers to the same DB, they can both use the same DB. However, there is no data locking mechanism to prevent the two different sites from both trying to update the same record in similar time frames. It’s possible for one site to undo the efforts of the other site.

    Thread Starter rozard

    (@rozard)

    Thank you for your response. I added WP_HOME and WP_SITEURL entries and changed the table_prefix value from wp_ to node2_ from the wp-config.php file and started Apache. However, I am getting an”Already Installed” message. The screenshot is uploaded to this filebin link. https://filebin.net/otzl9khkdj6ekkbo

    Do you have any idea how I can fix this? I appreciate your help!

    • This reply was modified 2 months, 3 weeks ago by rozard.
    Moderator bcworkz

    (@bcworkz)

    You have no node2_* tables in your DB and yet you get that message? How much of the DB for the two installations do you intend to share? Just the DB itself, not any shared tables? It seems the installation routine is overly picky about existing tables even though they have the wrong prefix. You may need to initially configure a separate new DB, install there, then export/import the new tables to the desired DB. Once the appropriate tables are in place there should be no further issues with a shared DB.

    Thread Starter rozard

    (@rozard)

    I want to share all the tables from the same database with both websites. The goal is to add both websites in a load balancer and make it highly available. If one goes down the second one will be still serving with same contents.

    I have another question about changing the WordPress content directory. I went through the link you provided, copied the below line, added it to the wp-config.php file, moved the WordPress content directory to /mnt, and started Apache. It didn’t show anything; it was just a blank page with no content and no error. Then, I reverted the change and copied the line which is for the plugin to the config file, started the Apache, and the website came up. The plugin installed page was empty and there were error messages for each plugin, such as “The plugin?somePlugins.php?has been deactivated due to an error: Plugin file does not exist.”

    define( 'WP_CONTENT_DIR', dirname(__FILE__) . '/mnt/wp-content' );

    I am not sure I need to make other configuration changes. I didn’t find anything else in the article about making any other changes to make it work. I might have missed it. I appreciate your help!

    Moderator bcworkz

    (@bcworkz)

    If all tables are to be shared, ensure the prefix in wp-config.php matches that of existing tables. There is then no need to run the installation routine. It would be very similar to if you moved the same site to a different server, it should simply work.

    As for moving the content directory, I think there may be a permissions issue with the new location. Another possibility would be if any plugins are using relative references, for example require_once('../wp-load.php'); Relative references do not work well in WP, always use full, absolute references. Preferably through the use of available functions or constants.

    One thing to note with shared tables: resources referenced in post content such as images will always come from the installation the post was created in because the domain is hard coded into content. The constants you defined only affect dynamically generated URLs such as permalinks.

    Thread Starter rozard

    (@rozard)

    The database part works fine; I use the same table prefix for both instances. Now, I am trying to move the entire wp-content directory to a mount point and then mount the mount point to /mnt with both servers instead of moving plugins and uploads. However, when I tried that, I got the below error when I try to access the website. Permission looks fine; all files are owned by Apache, the Apache user and group have all permission, and others have read and execute permission. Selinux label also got copied but I still ran restorecon to relabeled it. Theme can’t be moved?
    The theme directory "themeName" does not exist.
    Error:?The themes directory is either empty or does not exist. Please check your installation.

    Thank you for your help!

    Moderator bcworkz

    (@bcworkz)

    All of wp-content can be moved, including themes. It’s normal to get that message when you first move wp-content, but you should be able to go back in and reactivate it from its new location.

    If you got that message after trying to activate the theme, I’m at a loss for an explanation. If the theme is visible on the themes admin screen, the theme directory should exist by logical deduction.

    Thread Starter rozard

    (@rozard)

    Theme exists in the directory, but when I go to the admin panel from the web UI, there isn’t a theme. It looks like it’s not reading the new location. I tried with /var by copying the wp-content directory into it, but I got the same error message. I disabled SELinux and changed permission to 755 for all of the directories and subdirectories. Not sure what I am doing wrong. Is there any way to enable WordPress logs? I don’t see any error from Apache logs. Thanks

    Moderator bcworkz

    (@bcworkz)

    You can define WP_DEBUG as true, but that merely displays errors on the page. The PHP log should log errors regardless of WP_DEBUG value. An inaccessible theme might not generate any errors though.

    This still sounds like a permissions issue of some sort. Determine the system user that PHP runs as with echo get_current_user(); (Not to be confused with current WP user with wp_get_current_user()). This PHP user should ideally be the owner of the content directory and all sub-directories and files within. Also verify permissions of theme files, especially style.css.

    Oh, one other thought, did you also define a WP_CONTENT_URL constant? You need both a DIR and URL constant which are assigned appropriate values. This means your wp-content directory needs to be accessible over the internet as well as by PHP.

    Thread Starter rozard

    (@rozard)

    Finally, I was able to make it work. I made two changes, and that fixed the issue. I added FS_METHOD line, and secondly, I removed “dirname(FILE)” part from the wp_content_dir code. I am not sure if it was added as an example or if it was part of the code. I just wanted to post the solution, just in case a newbie like me will have a similar issue in the future. They just need to add two lines below.

    define('FS_METHOD', 'direct');
    define('WP_CONTENT_DIR', '/mnt/wp-content');

    Thank you, @bcworkz, for your help!

Viewing 10 replies - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.