One of the new features for Textpattern 4.2.0 is the multi-sites file system layout. What this means is that you can now have one Textpattern install controlling many sites. Instead of upgrading many sites, you only need to upgrade the one install.
Note that each site will still be separate and your pages, forms and styles will not be shared between installs – only the base installation of Textpattern is shared. As usual you will have a separate Admin for each site.
This tutorial
This tutorial is mainly aimed at installing multi-sites on Joyent but the instructions may be helpful for other web server installations. I used the following guidelines for setting up multi-sites on TXP Tips. Note that I used Coda’s in built Terminal for shell access – use whichever application works for you.
Advantages of a multi-site system layout
- Create multiple Textpattern-driven web sites from a single installation of the Textpattern core code base
- Separate the Textpattern admin area from the Textpattern-driven web site by placing it into its own web root and subdomain
- Gain a modicum of extra security by removing the vast majority of the Textpattern core code from the web document root
- Easily protect the admin area via SSL, if you place it into its own web root and subdomain
The multi-sites feature is very powerful, and allows for two basic setup methods:
- A. Multi-Site with Separate Admin Area
- B. Multi-Site with Integrated Admin Area
Option A
This setup method results in separate subdomains for your Textpattern-powered site and its associated admin area. For example:
http://www.mysite.com <-- URL to your site
http://admin.mysite.com <-- URL to your site's admin area login
Option B
This setup method results in the more traditional Textpattern installation, where the admin area is located in a subdirectory of the main site’s domain. For example:
http://www.mysite.com <-- URL to your site
http://www.mysite.com/admin <-- URL to your site's admin area login
Installing multi-sites on your server
On many hosts, all you need to do is follow the instructions provided in the readme.txt
file within the textpattern-4.2.0/sites/
folder of a default Textpattern 4.2.0 install.
Installing multi-sites on Joyent
In the case of TXP Tips, which is hosted by Joyent, the default method outlined in the readme.txt
does not work.
Sam Weiss, the Textpattern developer who created the multi-sites feature, has a Multi-sites install script for Joyent that automates the multi-site setup on Joyent servers. For shared hosts that impose a domain directory structure (Joyent shared hosting falls into this category), you cannot use the included sites directory. Instead, you must create your own.
What the script does
The script should not overwrite directories that already exist. The default settings are for Joyent, so it tries to create:
web/
admin/
public/
private/
If the site already exists, web/public will already be there, so the script should not overwrite it.
Getting started with a clean install
- Upload the
txp_create_site.sh
script to your server in the root:/users/home/yournamehere/
- I set the permissions on the script to 700
- Read the readme.txt thoroughly
- Open a shell window – I used Coda’s Terminal
- In the Terminal window go to your domain –
$ cd /users/home/yourusername/
or$ cd /users/home/yourusername/domain/yourdomain.com
- Run the
txp_create_site.sh
script withtxp_create_site.sh
or~/txp_create_site.sh
depending on if you are in the main domain or a sub-domain - You should now have a new
/web
directory. Enter eithercd ~/web
orcd ~/domains/yourdomain.com/web
in Terminal, depending on whether you are in the main domain or a sub-domain - Run the following command in Terminal to download Textpattern 4.2.0 – but be sure to change the path and domain name as necessary
cd ~/domains/txptips.com/web
wget http://textpattern.com/file_download/56/textpattern-4.2.0.tar.gz
tar xzf textpattern-4.2.0.tar.gz
rm textpattern-4.2.0.tar.gz
ln -s textpattern-4.2.0 textpattern
The script creates a config-dist.php file in your site’s private directory that is preconfigured. Simply copy that file and edit the appropriate lines as instructed by the textpattern setup process. Again, change the path if necessary.
cd web/private
cp config-dist.php config.php
nano -w config.php
You are nearly done. Update your “File directory path” and “Temporary directory path” settings in Advanced Preferences. These will default to directories inside the shared textpattern directory. You want to change them to (for example):
/users/home/{username}/domains/{mydomain.com}/web/public/files
/users/home/{username}/domains/{mydomain.com}/web/public/tmp
Upgrading existing sites
If you are upgrading an already existing site, some slightly different steps are required:
- Rename your
/web
directory to, for example, web.orig - Open a shell window in Terminal
- Navigate to the directory where you will run the script
cd ~/domains/txptips.com
– change the path as necessary - Run the script – I used
~/txp_create_site.sh ~/web/textpattern
because multi-sites had already been installed in the root directory and we need to point the script at the main domain Textpattern install (if it already exists, if not, follow the next step) - If Textpattern has already been installed, move onto the next step (copy assets) because you only require one Textpattern install for multi-sites. Otherwise, run the following command in Terminal to download Textpattern 4.2.0 – but be sure to change the path and domain name as necessary.
cd ~/domains/txptips.com/web
wget http://textpattern.com/file_download/56/textpattern-4.2.0.tar.gz
tar xzf textpattern-4.2.0.tar.gz
rm textpattern-4.2.0.tar.gz
ln -s textpattern-4.2.0 textpattern
- Copy your static assets (images, files, etc.) from web.orig/public/ to the new web/public/
- The script creates a config-dist.php file in your site’s private directory that is preconfigured. You can copy the file and change the name to config.php
- Update the “File directory path” and “Temporary directory path” settings in your Advanced Preferences. These will default to directories inside the shared textpattern directory. You want to change them to (for example):
/users/home/{username}/domains/{mydomain.com}/web/public/files
/users/home/{username}/domains/{mydomain.com}/web/public/tmp
Your site will be down for a short while during the transition.
Run the script in each domain
By default, Joyent has a domain directory structure like so:
/users/home/yournamehere/web/public <-- the root domain
/users/home/yournamehere/domains/yourdomain.com/web/public <-- your secondary domains
On Joyent, you will need to run the script on each sub-domain if you wish to run multi-sites on all your domains. Your Textpattern install is shared by all domains through the symlinks created by the script.
Install Textpattern only once
Again, please note that Textpattern itself only needs to be installed once, either in your main domain as in my case or in a sub-domain.
For more information or help with this script, please visit the forum thread.
Jonathan, thank you so much for this, I was gonna have a stab at this myslef but never had the time.
Cheers mate
A quick one (hope artagesw is reading this):
What’s the reason for creating a symlink after extracting the tar.gz?
It may be a bit OCD, but if you create that symlink, you will end up with a double /textpattern/textpattern on your path, which may be a little confusing (or not!).
Thanks for the tip, Jonathan.
Also, what about the message on Diagnostic tabs:
“/home/user/public/textpattern/textpattern/setup/ still exists”?
As far as I understand, this folder is (or should, at least) out of reach thru a browser.
But I’ve read somewhere (cannot find it now) that it shouldn’t be deleted on this case (a multi-site setup) as it has to be there for creating new sites (of course, one could delete /setup/ to be safe, and re-upload it if there is the need to create new sites).
Any comments are welcome. Thanks.
And last comment, I promise:
neither the README.TXT nor this post mentions that the .htaccess file should be copied to /sites/site1/, /sites/site2/, etc.
At least, I had to do that, does anybody else had to?
Great news.