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
adminis1234and its encoding is ininstall/db_data.sql. Create a new administrator (level 10) and delete the defaultadminuser 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 cachesWithout
composer installthe application will not run. Regenerate the PDF fonts withmake fontsand the language caches withmake lang(the language caches are also built on first request).
General upgrade process
Back up your entire existing database and the TCExam folder.
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.sqlFor MySQL databases that do not use utf8mb4 yet, see MySQL character set.
Rename the current folder (e.g.
/var/www/tcexam→/var/www/tcexam.old).Extract the new version into the same location (e.g.
/var/www/tcexam).Install the PHP dependencies and generate the assets:
composer install make langDelete the
tcexam/installfolder.Update the configuration files in
admin/config/,public/config/andshared/config/(see Configuration).Migrate cached multimedia content (images, etc.) from the old
cache/folder to the new one. Keep the shippedcache/.htaccessfile.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 {} \;Restore custom translations. If you use custom language files, replace
shared/config/lang/language_tmx.xmland rebuild the caches withmake lang(or delete thecache/lang/*.phpfiles).Review existing data (see Existing data).
Verify that TCExam is working correctly.
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:
| File | Setting |
|---|---|
shared/config/tce_general_constants.php | K_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.php | K_DATABASE_TYPE: 'MYSQL', 'POSTGRESQL' or 'ORACLE'. |
shared/config/tce_config.php | K_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.php | K_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.php | K_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.php | K_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.php | K_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 shippedcache/.htaccessserves the directory as passive content:X-Content-Type-Options: nosniff, aContent-Security-Policywithsandbox,Content-Disposition: attachmentfor markup types, and no script execution. It requiresmod_headersandAllowOverride AuthConfig FileInfo(orAll). 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.phponly redirects to the public area, so denying it is harmless.Log and backup directories.
admin/backup/.htaccess,admin/log/.htaccessandpublic/log/.htaccessdeny 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_ADMINwhen 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:
Back up the database.
If the tables use a prefix other than
tce_, replacetce_ininstall/upgrade/mysql/mysql_db_upgrade_utf8mb4.sql.Set the database default character set (replace
tcexamwith the database name):ALTER DATABASE tcexam CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;Run the conversion script. It rewrites every table, so large
tce_tests_logstables can take a long time:mysql -u root -p tcexam < install/upgrade/mysql/mysql_db_upgrade_utf8mb4.sqlSet
K_MYSQL_QA_BIN_COLLATIONto'utf8mb4_bin'inadmin/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 inK_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'inK_ALLOWED_UPLOAD_EXTENSIONSas 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'toK_ALLOWED_UPLOAD_EXTENSIONSto 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 CSSurl(),@import,image(),image-set(),cross-fade()andsrc(); - 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.
- scripts, event handler attributes (
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
$pagelevelrequires the administrator level. Pages meant for anonymous users set$pagelevel = 0;explicitly; do the same in any customised page, includingadmin/code/tce_export_custom.phpandadmin/code/tce_import_custom.php. - Every
POSTrequest with form data or files to a page that loads the form helpers must carry a validcsrf_token. F_file_exists()checks local files only and returnsfalsefor URLs and stream wrapper paths.
Existing data
Files and text already stored in an existing installation are not checked again. Review them after upgrading:
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.phpList file and directory names that contain characters outside
[A-Za-z0-9_.-]:find cache/ -name '*[!A-Za-z0-9_.-]*'Delete import files (
*.tsv,*.csv,*.txt,*.xml) from thecache/root.Delete
cache/latex_*.png. Formula images are generated again when they are displayed.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]%';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;