[title sub="Written by Chris Graham"]Composr Tutorial: Disaster recovery[/title]

[i]The Composr 'error log' screen points to this tutorial (as well as the 'critical error' screen and the 'system scheduler hooks' screen). If you think you have found a bug, please [page="_SEARCH:report-issue"]report it[/page]. The rest of this tutorial deals with potential disaster situations -- an error in the error log does not imply a disaster has happened.[/i]

This tutorial will go through some solutions to 'disastrous' scenarios that could happen on an unstable web server configuration. It does not cover all that could go wrong by any means, as there are literally an infinite number of things that could go wrong if Composr is running in an unreliable environment.

I am going to assume that you have access to phpMyAdmin for the purposes of this tutorial. phpMyAdmin is a user-friendly web-based frontend to MySQL, and is available from most webhosting control panels. For more information, see the [page="_SEARCH:tut_sql"]Manually editing your database with phpMyAdmin[/page] tutorial.

If you need a quick data rescue, consider [page=":partners"]hiring a Composr partner[/page] or, your preferred third-party developer.

[contents]decimal,lower-alpha[/contents]

[title="2"]Viewing the error log[/title]

You may view the Composr error log even if Composr won't start. Just look at the contents of the [tt]data_custom/errorlog.php[/tt] file manually (don't run it, open it in a text editor). The error log often contains clues to what is causing a problem.

[title="2"]Clearing caches[/title]

Changes in the database or to files may be obscured by caching. If you have a problem so severe that you cannot get into the Admin Zone, you can clear caching either:
1) from the upgrader tool (accessible via [tt]http://yourbaseurl/upgrader.php[/tt])
2) opening up a command prompt to your base directory and running [tt]php decache.php[/tt] (Linux/Mac only) -- this works if the upgrader won't run; it doesn't immediately clear database caching, but it adds a flag for Composr to do that automatically next time the site is loaded

[title="2"]Repairing a corrupted copy of Composr[/title]

The upgrader tool (accessible via [tt]http://yourbaseurl/upgrader.php[/tt]) contains a very useful 'integrity checker' which can find out-dated and corrupt files. You can use this tool at any point, regardless of whether you have recently upgraded or not.

More details on the integrity checker are in the [page="_SEARCH:tut_upgrade"]Performing an upgrade[/page] tutorial.

[title="2"]Repairing corrupted MySQL tables[/title]

Instructions are provided in the [page="_SEARCH:tut_sql"]Manually editing your database with phpMyAdmin[/page] tutorial.

If you don't have phpMyAdmin, whatever database management tool should have an equivalent feature as table repair is a standard MySQL mechanism.

If you don't have any visual database management tool, you should look into getting one. However if you are technical you can use the command line using the MySQL [tt]REPAIR TABLE <tablename>[/tt] command, or the [tt]myisamchk[/tt] program to batch fix all [tt]*.MYI[/tt] files while having the MySQL server temporarily offline.

[title="2"]Fixing a theme[/title]

If you've set up a theme, that is activated, and you've edited it in such a way that you can no longer realistically use the Admin Zone, you'll need to rescue your theme.

If you still are logged in as admin or the default theme is accessible from guest accounts, use the 'Safe mode' link you were asked to bookmark during the Setup Wizard -- this will allow you to use your website, using the default theme. If you have forgotten the link, it's any link to your website with [tt]&keep_theme=default[/tt] added to the end of the URL.

If you are not logged in as admin, connect to your web server using FTP, then rename all the folders inside the [tt]themes[/tt] folder except [tt]default[/tt] and [tt]admin[/tt]. For instance, if you have folders [tt]my_theme[/tt], [tt]another_theme[/tt], [tt]default[/tt], and [tt]admin[/tt], rename the first two to [tt]my_theme.old[/tt] and [tt]another_theme.old[/tt], but leave [tt]default[/tt] and [tt]admin[/tt] alone. This renaming will essentially temporarily erase your themes and force Composr to use the default theme regardless of permissions. Now change the theme selection on your site back to default, rename your theme folders back to their prior names (remove the [tt].old[/tt] suffix you added), fix your theme, and then restore your theme selection.

[title="2"]Changing an account password[/title]

If you've misset a Composr account password and for whatever reason can't use the 'lost password' feature to reset it (perhaps because of an invalid/non-existent e-mail address for that account, or a faulty/non-existent mail server, or a protected admin account), then you'll want to manually reset it.
Obviously this needs a greater level of access than ordinary members would have. We could either use:
 - Database access
 - Disk access

[title="3"]Via the database[/title]
[surround]
For this, I am assuming that you are using [concept]Conversr[/concept]. If you are using another forum then the method will be similar, but will be done upon the data of that forum.

[media_set]
[media width="150" description="Select to browse the f_members table" float="right"]data_custom/images/docs/tut_disaster/disaster_pass_1.png[/media]
[media width="150" description="Edit the row for the username for which the password should be changed" float="right"]data_custom/images/docs/tut_disaster/disaster_pass_2.png[/media]
[media width="150" description="Change the settings and 'Go'" float="right"]data_custom/images/docs/tut_disaster/disaster_pass_3.png[/media]
[/media_set]

[list="1"]
[*] Enter phpMyAdmin
[*] Browse the contents of the Composr f_members table (named [tt]cms_f_members[/tt] if you used the default table prefix).
[*] You will see rows for all usernames. Click the little edit icon and you'll see an editing screen.
[*] There are numerous fields, but we only need to change three:[list]
[*][tt]m_pass_hash_salted[/tt] should be given the new password. It is essential that you also choose 'MD5' from the list to the left of the input field, so that the password gets 'encrypted' (Composr assumes an encrypted password and if it is not then it will not successfully log in).
[*][tt]m_pass_salt[/tt] should be blanked out.
[*][tt]m_password_compat_scheme[/tt] should be set to the literal value 'md5'.[/list]
[*] Scroll to the bottom of the form and click 'Go'.
[/list]

You should now be able to log in to Composr using your new password. Note that once you log in, your password will be re-hashed back to the bcrypt algorithm in the database for security.
[/surround]

[title="3"]Via the disk[/title]

If you need to 'hack' your way in to the site using your FTP access, you can place a temporary backdoor.

Go to https://www.myipaddress.com/ and copy your IP address, then put it into your [tt]_config.php[/tt] file:
[code="PHP"]
$SITE_INFO['backdoor_ip'] = '12.34.56.78'; // Enable to a real IP address to force login from FTP access (if lost admin password)
[/code]

You will then be logged in as the first admin user there is. Additionally membership bans, probation, and flood control, will not apply when using the backdoor (so it is useful if your account was locked somehow, e.g. by a malicious other staff member).

It should go without saying that you should only use this 'backdoor' for a short space of time and not disclose your IP address to third parties when doing it. The developers make no claims to how secure this backdoor might be and you open it up entirely at your own risk.

[title="2"]Changing the maintenance password[/title]

If you need to log in to the upgrader, config editor, or code editor, you'll need the maintenance password.

If you have forgotten it, to change it just edit the [tt]_config.php[/tt] file:
[code="PHP"]
$SITE_INFO['maintenance_password'] = '...';
[/code]
Change the [tt]...[/tt] bit to the actual password you want. You don't need to encrypt it, just put it in exactly.

You should then encrypt your password via changing the password within the [tt]http://yourbaseurl/config_editor.php[/tt] script.

[title="2"]Unbanning an IP address[/title]

[surround]
[media width="150" description="Delete the row corresponding to your IP address" float="right"]data_custom/images/docs/tut_disaster/disaster_ban_2.png[/media]
[media width="150" description="Select to browse the banned_ip table" float="right"]data_custom/images/docs/tut_disaster/disaster_ban_1.png[/media]
If you are unfortunate enough to have somehow been banned from your own website, use phpMyAdmin to browse the [tt]banned_ip[/tt] table, and delete the row containing your IP address.

If you don't know your IP address then you can find it out from https://www.myipaddress.com/.
[/surround]

[title="2"]Resetting page ownerships[/title]

If you delete or demote an admin, you may find lots of pages now show Comcode permission errors (even default ones, which are assigned to the first site admin automatically).

To fix this, edit the Comcode page and assign a new submitter via the edit form.

To do it en-masse, you can run this in Commandr (this example assumes you are reassigning from member #5 to member #2):
[code="Commandr"]
:$GLOBALS['SITE_DB']->query_update('comcode_pages',['p_submitter'=>2],['p_submitter'=>5]);
[/code]
and then clear the Comcode page cache from Admin Zone > Tools > Cleanup tools.

[title="2"]Changing Installation Options[/title]

If your server base configuration has changed (such as your database password, for example) then you need to update Composr's [tt]_config.php[/tt] config file to reflect this. You can either do this directly, or you can do it via launching the [tt]http://yourbaseurl/config_editor.php[/tt] script installed at the base of your website (you will need your maintenance password to do this).

[title="2"]Removing Facebook from an account[/title]

If you have associated an account with Facebook, you can remove it by doing a password reset on that account.

[title="2"]Problems with addons[/title]

If you find an addon is crashing your site, the safe mode link ([tt]http://yourbaseurl/index.php?keep_safe_mode=1[/tt]) can help. It should let you into your site to uninstall (or update, as may be the case for non-bundled addons) the addon causing the problem.

The above requires for to be logged in at admin, which you may not be or be able to do. If you can't then you can force Safe Mode on using the [tt]http://yourbaseurl/config_editor.php[/tt] script. Load up the [tt]http://yourbaseurl/config_editor.php[/tt] script, login, look for the "Whether Composr is to be forced into Safe Mode, meaning no custom files will load and most caching will be disabled" option, tick (check) the option, and then save the configuration. Turn the option back off after you've solved your problem.

[title="2"]Disabling URL Schemes[/title]

URL Schemes are subject to your webhost supporting rewrites and not doing any strange redirects or filter rules. It is possible you could enable them, and then find they don't work and that you can't get back at the configuration to disable them. We try and detect them working before we allow the option to be changed, but the detection may not be perfect. Or, they may work, then your host may change something, causing them to stop working.
You can use the [tt]http://yourbaseurl/config_editor.php[/tt] script in order to turn them off, overriding the main configuration setting. Load up the [tt]http://yourbaseurl/config_editor.php[/tt] script, login, look for the "Whether to block the URL Scheme (mod_rewrite)" installation option, tick (check) the option, and then save the configuration.

[title="2"]Closing the site[/title]

If you can't access the Admin Zone then the upgrader tool (accessible via [tt]http://yourbaseurl/upgrader.php[/tt]) can close the site while you're working on problems. If that won't work reliably you can create a [tt]closed.html[/tt] file in your base directory which will automatically be displayed to all users accessing Composr.

If failover-mode is configured you can activate it manually from within the [tt]http://yourbaseurl/config_editor.php[/tt] script.

[title="2"]See also[/title]

 - [page="_SEARCH:tut_sql"]Manually editing your database with phpMyAdmin[/page]
 - [page="_SEARCH:tut_webhosting"]Webhosting for Composr[/page]
 - [page="_SEARCH:tut_website_health"]Website Health[/page]
 - [page="_SEARCH:tut_telemetry"]Relaying Errors and Statistics to Composr[/page]
 - [page="_SEARCH:codebook_3"]Code Book, part 3 (Miscellany)[/page]

{$SET,tutorial_tags,Maintenance,core,novice}{$SET,tutorial_add_date,Aug 2008}{$SET,tutorial_summary,Some 'life saving' solutions to disastrous scenarios that can happen on an unstable web server configuration.}[block]main_tutorial_rating[/block]
