Posted By

jonhenshaw on 10/14/08


Tagged

database wordpress single multiple


Versions (?)


Advertising

Website Promotion DIRECTORY is a crucial factor for all websites that need to gain better organic search engine rankings and increase website traffic.
Submitting your website as part of your Web Promotion strategy to our SEO friendly and high traffic Business Directory for review is an excellent way to gain a valuable backlink and increase your websites visibility online.

Submit Site


Who likes this?

3 people have marked this snippet as a favorite

lee
absolon
lilumi


Manage Multiple WordPress Sites With One Database and One Code Base


Published in: PHP 






URL: http://sitening.com/blog/how-to-easily-manage-multiple-wordpress-sites-with-one-database-and-one-code-base/

This is a simple but powerful tweak to the wp-config.php file that will make it easy to run multiple websites using one database and codebase. Simply change "yourdomain.com" with your domain and that's it. Repeat that line for new domains.

Expand | Embed | Plain Text
  1. // You can have multiple installations in one database if you give each a unique prefix
  2.  
  3. $domain_list = array();
  4.  
  5. // auto database name
  6. $domain_list["yourdomain.com"] = "";\
  7.  
  8. $domain_name = preg_replace("/^www\./", "", $_SERVER["SERVER_NAME"]);
  9.  
  10. if (array_key_exists($domain_name, $domain_list))
  11. {
  12. $table_prefix = $domain_list[$domain_name];
  13. if (!$table_prefix) { $table_prefix = "wp_" . md5($domain_name); }
  14. }
  15. else
  16. {
  17. print "Unknown error"; exit;
  18. }

Report this snippet 

Comments

RSS Icon Subscribe to comments
Posted By: absolon on October 23, 2008

I'm confused a little bit. Should I point each domain to folder where Wordpress files are? For instance if it's /wordpress domains should be pointed to this folder? Will I be able to change template for each site (domain)?

Posted By: absolon on October 23, 2008

I'm confused a little bit. Should I point each domain to folder where Wordpress files are? For instance if it's /wordpress domains should be pointed to this folder? Will I be able to change template for each site (domain)?

Posted By: jonhenshaw on November 1, 2008

Yes, point each domain to the same folder. The code automatically creates a new database table prefix based on the domain name pointing to it. The first time you visit the domain, it creates the unique database entry. Then, after you run through the WordPress setup, you can choose whatever theme you want. Themes and plugins are handled by the database. So, you can have 20 themes and 20 plugins in one install, but pick and choose which ones you want to use for each individual site.

Posted By: cayenne on November 27, 2008

I'm assuming sub-domains can be used in the same way to accomplish what is described above? Is this correct?

Posted By: the_coder on May 5, 2009

What method do you recommend "pointing to" the central wordpress directory?

Posted By: the_coder on May 5, 2009

Assuming a server setup of: /home/domain1.com/html/ /home/domain2.com/html/ /home/domain3.com/html/ /home/wordpress/[central wordpress code base]

How would you configure the domain1.com to point to /home/wordpress/ directory?

When a file is referenced by the domain (ex. domain1.com/wp-content/themes/default/style.css), how does the server know to look for it in the central code base (/home/wordpress/) rather than under the domain directory?

Posted By: the_coder on May 5, 2009

Assuming a server setup of: /home/domain1.com/html/ /home/domain2.com/html/ /home/domain3.com/html/ /home/wordpress/[central wordpress code base]

How would you configure the domain1.com to point to /home/wordpress/ directory?

When a file is referenced by the domain (ex. domain1.com/wp-content/themes/default/style.css), how does the server know to look for it in the central code base (/home/wordpress/) rather than under the domain directory?

Posted By: the_coder on May 5, 2009

Assuming a server setup of:
/home/domain1.com/html/
/home/domain2.com/html/
/home/domain3.com/html/
/home/wordpress/[central wordpress code base]

How would you configure the domain1.com to point to /home/wordpress/ directory?

When a file is referenced by the domain (ex. domain1.com/wp-content/themes/default/style.css), how does the server know to look for it in the central code base (/home/wordpress/) rather than under the domain directory?

You need to login to post a comment.