I have a couple of other WordPress blogs on the same server besides this one. One day I realised that all of them have 3 different WP versions and, as result, different admin areas which is not handy. I decided to make them use the same WordPress installation.
Ok, first of all, I deleted
wp-includes folders and created new ones as symbolic links. Though the frontend worked well, I couldn’t log in into admin area, because the browser was redirected to that blog which was the base for all the rest for unknown reason.
The investigation shown, that admin area of WordPress is a separate sub-application, thing in itself, and in my case it resolves the absolute path to its source as the path to the base blog. I wanted each blog to use its own folder because there are config file and
It took me some time to find a solution. It requires two steps.
First, I added this line to the top of the
.htaccess to make any PHP request to the blog (the blog front-end and the admin area scripts) call the same script before thier start:
#fix for several sites on the same WP installation php_value auto_prepend_file "/var/www/site_doc_root/prepend.php"
In this code
/var/www/ is the root folder for all my sites, and the
site_doc_root is the document root of the current site (folder where all its files are located).
OK, the 2nd step — the contents of the
prepend.php script. It is easy — it just must define an absolute path constant which is used all around the WordPress:
<?php define('ABSPATH', dirname(__FILE__).'/');
OK, after that I decided not to use one of the blogs as source for others, but download a fresh copy of WordPress and make it a source of the symbolic links for all my blogs. This helps to update them.
Then I deleted
wp-includes folders and some wp-files and recreated them as symlinks. Attention to
wp-config.php — don’t delete it, keep it unique for every site!
To make this task easier, I created
setup.sh file, pasted the contents I show below, run this command
chmod 755 setup.sh
then I copied it in every site folder and launched there for every site:
ln -s /var/www/wordpress/wp-admin wp-admin ln -s /var/www/wordpress/wp-includes wp-includes ln -s /var/www/wordpress/wp-app.php wp-app.php ln -s /var/www/wordpress/wp-atom.php wp-atom.php ln -s /var/www/wordpress/wp-blog-header.php wp-blog-header.php ln -s /var/www/wordpress/wp-comments-post.php wp-comments-post.php ln -s /var/www/wordpress/wp-commentsrss2.php wp-commentsrss2.php ln -s /var/www/wordpress/wp-config-sample.php wp-config-sample.php ln -s /var/www/wordpress/wp-cron.php wp-cron.php ln -s /var/www/wordpress/wp-feed.php wp-feed.php ln -s /var/www/wordpress/wp-links-opml.php wp-links-opml.php ln -s /var/www/wordpress/wp-load.php wp-load.php ln -s /var/www/wordpress/wp-login.php wp-login.php ln -s /var/www/wordpress/wp-mail.php wp-mail.php ln -s /var/www/wordpress/wp-pass.php wp-pass.php ln -s /var/www/wordpress/wp-rdf.php wp-rdf.php ln -s /var/www/wordpress/wp-register.php wp-register.php ln -s /var/www/wordpress/wp-rss.php wp-rss.php ln -s /var/www/wordpress/wp-rss2.php wp-rss2.php ln -s /var/www/wordpress/wp-settings.php wp-settings.php ln -s /var/www/wordpress/wp-trackback.php wp-trackback.php ln -s /var/www/wordpress/xmlrpc.php xmlrpc.php
That’s not all 😉
I decided to update my WordPress installation every one or two months.
To do that, in the
/var/www/ folder (where all my sites reside) let’s create an update script
update_wordpress.sh with the following contents:
wget --timestamping http://wordpress.org/latest.zip unzip -o latest.zip
This will download a fresh copy of the wordpress if it’s changed (though wordpress team doesn’t show the file
Last-Modified header, I think one day they will) and unzip it to
/var/www/wordpress/ folder which is the source for our symlinks.
Yes, you got it right — launching this script is all I need to update all my blogs.
Let’s make it periodic:
and then add this line to run the update process automatically every 1st day of every month at 9 AM:
0 9 1 * * /var/www/update_wordpress.sh > mail -s "Wordpress updated" firstname.lastname@example.org
P.S. Of course,