Upgrade Guide

Always back up your database and files before upgrading. If this is a fresh install instead, see the Installation page.

Upgrading from a version older than 14.0.0. Passwords stored by these versions are not accepted and all passwords must be reset. The default password for admin is 1234 and its encoding is in install/db_data.sql. Create a new administrator (level 10) and delete the default admin user as soon as possible.

Requirements

  • PHP >= 8.2 (tested on 8.2 / 8.3 / 8.4 / 8.5).

  • MySQL 5.7.7+ or MariaDB 10.2.2+ for MySQL installations (utf8mb4 tables), PostgreSQL or Oracle.

  • Composer. The PHP libraries (tc-lib-pdf, PHPMailer, phpCAS, RADIUS) are installed with Composer, and the PDF fonts and translation caches are generated:

    composer install     # installs vendor/, generates the PDF fonts (post-install hook)
    make lang            # (optional) pre-builds the translation caches
    

    Without composer install the application will not run. Regenerate the PDF fonts with make fonts and the language caches with make lang (the language caches are also built on first request).

General upgrade process

  1. Back up your entire existing database and the TCExam folder.

  2. Upgrade the database schema. If the new main version number (Y) differs from your installed main version number (X), execute the matching SQL file for your engine:

    install/upgrade/mysql/mysql_db_upgrade_XtoY.sql
    install/upgrade/postgresql/postgresql_db_upgrade_XtoY.sql
    install/upgrade/oracle/oracle_db_upgrade_XtoY.sql
    

    For MySQL databases that do not use utf8mb4 yet, see MySQL character set.

  3. Rename the current folder (e.g. /var/www/tcexam → /var/www/tcexam.old).

  4. Extract the new version into the same location (e.g. /var/www/tcexam).

  5. Install the PHP dependencies and generate the assets:

    composer install
    make lang
    
  6. Delete the tcexam/install folder.

  7. Update the configuration files in admin/config/, public/config/ and shared/config/ (see Configuration).

  8. Migrate cached multimedia content (images, etc.) from the old cache/ folder to the new one. Keep the shipped cache/.htaccess file.

  9. Set the file permissions for your web server / PHP environment (example for Apache running as www-data, installation in /var/www/tcexam):

    cd /var/www/tcexam
    chown -R www-data:www-data .
    find . -type f -exec chmod 544 {} \;
    find . -type d -exec chmod 755 {} \;
    find cache/ -type d -exec chmod 775 {} \;
    find cache/ -type f -exec chmod 664 {} \;
    
  10. Restore custom translations. If you use custom language files, replace shared/config/lang/language_tmx.xml and rebuild the caches with make lang (or delete the cache/lang/*.php files).

  11. Review existing data (see Existing data).

  12. Verify that TCExam is working correctly.

  13. Remove the old installation (tcexam.old) after confirming the upgrade succeeded.

Configuration

Start from the shipped *.default files and re-apply your customisations. Check the following settings:

FileSetting
shared/config/tce_general_constants.phpK_RANDOM_SECURITY must be a unique random value for each installation. The installer generates it; to set it manually, use php -r "echo bin2hex(random_bytes(32)), PHP_EOL;".
shared/config/tce_db_config.phpK_DATABASE_TYPE: 'MYSQL', 'POSTGRESQL' or 'ORACLE'.
shared/config/tce_config.phpK_ERROR_TYPES: default E_ALL. The file does not create variables from posted form fields; remove any such block from a customised copy.
shared/config/tce_paths.phpK_FILE_ALLOWED_PATHS, K_FILE_ALLOWED_HOSTS (allow-lists for file/URL access), K_PATH_URL_ADMIN (base URL of the administration area).
shared/config/tce_pdf.phpK_PDF_UNICODE, K_PDF_SUBSET_FONT, K_PDF_COMPRESS, K_PDF_MODE, K_PDF_ALLOWED_PATHS / K_PDF_ALLOWED_HOSTS / K_PDF_MAX_REMOTE_SIZE.
shared/config/tce_cas.php (CAS only)K_CAS_SERVICE_BASE_URL; K_CAS_SERVER_CA_CERT (path of a PEM file with the CA certificates of the CAS server; when empty, the CAS server certificate is not validated).
shared/config/tce_user_registration.phpK_USRREG_ALLOWED_GROUPS: groups listed on the registration form (the field is hidden when the list is empty). K_USRREG_GROUP is always assigned.
admin/config/tce_config.phpK_ALLOWED_UPLOAD_EXTENSIONS (see Uploaded files); K_MYSQL_QA_BIN_COLLATION: a utf8mb4 collation, default 'utf8mb4_bin' (other values are replaced by 'utf8mb4_bin').

With K_OTP_LOGIN enabled, every user needs an OTP key. A new key is generated when an administrator sets a new password in the user editor. A key entered manually must be a base32 key of at least 16 characters; an empty key field removes the key.

Web server rules

  • cache/. The shipped cache/.htaccess serves the directory as passive content: X-Content-Type-Options: nosniff, a Content-Security-Policy with sandbox, Content-Disposition: attachment for markup types, and no script execution. It requires mod_headers and AllowOverride AuthConfig FileInfo (or All). For nginx, add the equivalent rules to the server block:

    location ^~ /cache/ {
        location ~* \.(php[0-9]?|pht|phtml|phar|phps|cgi|pl|py|sh|asp|aspx|jsp)(\.|$) { deny all; }
        location ~* \.(svgz?|xml|xslt?|xht|xhtml|s?html?|mht|mhtml|m?js|swf)$ {
            add_header Content-Disposition "attachment" always;
            add_header X-Content-Type-Options "nosniff" always;
            add_header Content-Security-Policy "default-src 'none'; sandbox" always;
        }
        add_header X-Content-Type-Options "nosniff" always;
        add_header Content-Security-Policy "default-src 'none'; img-src 'self' data:; media-src 'self'; style-src 'unsafe-inline'; sandbox" always;
    }
    

    Adjust the /cache/ prefix if TCExam is installed in a sub-path. cache/index.php only redirects to the public area, so denying it is harmless.

  • Log and backup directories. admin/backup/.htaccess, admin/log/.htaccess and public/log/.htaccess deny web access (Apache 2.4 syntax). Keep these files when copying old directories. For nginx, add:

    location ^~ /admin/backup/ { deny all; }
    location ^~ /admin/log/ { deny all; }
    location ^~ /public/log/ { deny all; }
    
  • Administration area. See Isolating the administration area for a separate admin host, network restrictions and web server examples. Set K_PATH_URL_ADMIN when the admin area is served from its own host.

MySQL character set

The MySQL connection uses utf8mb4. Databases with utf8mb3 tables work, but text with 4-byte characters (emoji, some mathematical symbols) is rejected with a database error. To convert a database to utf8mb4:

  1. Back up the database.

  2. If the tables use a prefix other than tce_, replace tce_ in install/upgrade/mysql/mysql_db_upgrade_utf8mb4.sql.

  3. Set the database default character set (replace tcexam with the database name):

    ALTER DATABASE tcexam CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
    
  4. Run the conversion script. It rewrites every table, so large tce_tests_logs tables can take a long time:

    mysql -u root -p tcexam < install/upgrade/mysql/mysql_db_upgrade_utf8mb4.sql
    
  5. Set K_MYSQL_QA_BIN_COLLATION to 'utf8mb4_bin' in admin/config/tce_config.php.

Uploaded files

  • Media uploads (File Manager, media selector, question/answer/subject attachments) reject markup and script types (svgz, xml, xsl, xslt, xht, xhtml, htm, html, shtml, mht, mhtml, js, mjs, swf) even when they are listed in K_ALLOWED_UPLOAD_EXTENSIONS. Server script types (php*, phtml, phar, cgi, pl, py, sh, …) are rejected for every upload. File content is checked, inner dots in file names become underscores and existing files are never overwritten. File Manager rename follows the same rules; new directory names are restricted to [A-Za-z0-9_-].

  • Imports (users, questions, SSL certificates) are read from the PHP temporary upload directory. Keep 'xml', 'tsv', 'csv', 'txt', 'pfx', 'pem' and 'crt' in K_ALLOWED_UPLOAD_EXTENSIONS as needed by the importers. A custom question importer (admin/code/tce_import_custom.php) receives the temporary file path, which has no file name extension.

  • Previews and [object] tags display images with <img>, audio with <audio>, video with <video> and every other type as a download link.

  • SVG uploads. Add 'svg' to K_ALLOWED_UPLOAD_EXTENSIONS to enable them. Each SVG file must be well-formed UTF-8 XML with an <svg> root element and contain only static graphics. The upload is rejected if the file contains any of the following:

    • scripts, event handler attributes (onload, onclick, …), <foreignObject>, links (<a>), animation elements, or SVG fonts;
    • references to anything other than an element of the same file (#id) or an embedded PNG, JPEG or GIF image (data:image/png;base64,...), including in CSS url(), @import, image(), image-set(), cross-fade() and src();
    • entity declarations, an internal DTD subset, or processing instructions such as <?xml-stylesheet?>;
    • editor-specific elements or attributes (Inkscape, Sodipodi, Adobe Illustrator, Sketch, …);
    • an encoding other than UTF-8 (declared, or detected such as UTF-16), or gzip compression (.svgz).

    Save drawings as plain SVG before uploading them:

    • Inkscape: File > Save a Copy… and choose Plain SVG or Optimized SVG.
    • Adobe Illustrator: File > Export > Export As… and choose SVG, with Styling: Presentation Attributes or Internal CSS, Font: Convert to Outlines and Images: Embed. Do not use Save As with Preserve Illustrator Editing Capabilities.
    • Other editors: remove editor metadata with an optimizer such as SVGO or Scour.

Test IP ranges

*.*.*.* (and *) match IPv4 and IPv6 clients. Use 0.0.0.0-255.255.255.255 to allow IPv4 clients only. Other * patterns (e.g. 192.168.*.*) match IPv4 addresses only.

Custom pages and code

  • A page that does not set $pagelevel requires the administrator level. Pages meant for anonymous users set $pagelevel = 0; explicitly; do the same in any customised page, including admin/code/tce_export_custom.php and admin/code/tce_import_custom.php.
  • Every POST request with form data or files to a page that loads the form helpers must carry a valid csrf_token.
  • F_file_exists() checks local files only and returns false for URLs and stream wrapper paths.

Existing data

Files and text already stored in an existing installation are not checked again. Review them after upgrading:

  1. List markup and script files in the cache and review or delete them:

    find cache/ -type f \( -iname '*.svg' -o -iname '*.svgz' -o -iname '*.xml' -o -iname '*.xsl*' \
        -o -iname '*.htm*' -o -iname '*.xht*' -o -iname '*.mht*' -o -iname '*.js' -o -iname '*.mjs' \
        -o -iname '*.swf' -o -iname '*.php*' -o -iname '*.phtml' \) -not -path 'cache/lang/*' \
        -not -name index.php
    
  2. List file and directory names that contain characters outside [A-Za-z0-9_.-]:

    find cache/ -name '*[!A-Za-z0-9_.-]*'
    
  3. Delete import files (*.tsv, *.csv, *.txt, *.xml) from the cache/ root.

  4. Delete cache/latex_*.png. Formula images are generated again when they are displayed.

  5. Search question, answer and subject text for [object] tags that reference non-media files:

    SELECT question_id FROM tce_questions
     WHERE question_description LIKE '%[object]%' OR question_explanation LIKE '%[object]%';
    SELECT answer_id FROM tce_answers
     WHERE answer_description LIKE '%[object]%' OR answer_explanation LIKE '%[object]%';
    SELECT subject_id FROM tce_subjects WHERE subject_description LIKE '%[object]%';
    
  6. List accounts without a password and set a new password for them (user editor or password reset):

    SELECT user_id, user_name FROM tce_users WHERE user_password = '' AND user_id > 1;