Nette Is Not Working, White Page Is Displayed

  1. Verify that the version of PHP on the web host supports the Nette Framework.
  2. Check if directories temp and log are writable. See Setting directory permissions.
  3. Force Debugger to work in development mode (Debugger::enable(Debugger::DEVELOPMENT)).

Error #[\ReturnTypeWillChange] attribute should be used

This error occurs if you have upgraded PHP to version 8.1 but are using Nette, which is not compatible with it. So the solution is to update Nette to a newer version using composer update. Nette has supported PHP 8.1 since version 3.0. If you are using an older version (you can find out by looking in composer.json), upgrade Nette or stay with PHP 8.0.

Setting Directory Permissions

If you're developing on macOS or Linux (or any other Unix based system), you need to configure write privileges to the web server. Assuming your application is located in the default directory /var/www/html (Fedora, CentOS, RHEL)

cd /var/www/html/MY_PROJECT
chmod -R a+rw temp log

On some Linux systems (Fedora, CentOS, …) SELinux may be enabled by default. You may need to update SELinux policies, or set paths of temp and log directories with correct SELinux security context. Directories temp and log should be set to httpd_sys_rw_content_t context; for the rest of the application – mainly app folder – httpd_sys_content_t context will be enough. Run on the server as root:

semanage fcontext -at httpd_sys_rw_content_t '/var/www/html/MY_PROJECT/log(/.*)?'
semanage fcontext -at httpd_sys_rw_content_t '/var/www/html/MY_PROJECT/temp(/.*)?'
restorecon -Rv /var/www/html/MY_PROJECT/

Next, the SELinux boolean httpd_can_network_connect_db needs to be enabled to permit Nette to connect to the database over network. By default, it is disabled. The command setsebool can be used to perform this task, and if the option -P is specified, this setting will be persistent across reboots.

setsebool -P httpd_can_network_connect_db on

Error 500 in Production Mode

If the application works correctly in development mode and throws a 500 error in production mode, the cause may be in an outdated cache. While Nette cleverly automatically updates the cache in development mode, in production mode it focuses on maximizing performance, and clearing the cache after each code modification is up to you. Try to delete temp/cache.

In any case, the reason for the error is listed in the log. If you don't see anything in the log (and in error 500 is notice Tracy is unable to log error), find out why it can't log errors. For example, switch to development mode and call Tracy\Debugger::log('hello') and Tracy will tell you why it can't log. This may be due to insufficient permissions to write to the log/ directory.

How to Configure a Server for Nice URLs?

Apache: extension mod_rewrite must be allowed and configured in a .htaccess file.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !\.(pdf|js|ico|gif|jpg|png|css|rar|zip|tar\.gz)$ index.php [L]

To alter Apache configuration with .htaccess files, the AllowOverride directive has to be enabled. This is the default behavior for Apache.

nginx: the try_files directive should be used in server configuration:

location / {
	try_files $uri $uri/ /index.php$is_args$args;  # $is_args$args is important

Block location must be defined exactly once for each filesystem path in server block. If you already have a location / block in your configuration, add the try_files directive into the existing block.

Use of Characters { } in JavaScript

Characters { and } are used for writing Latte tags. Everything (except space and quotation mark) following the { character is considered a tag. If you need to print character { (often in JavaScript), you can put a space (or other empty character) right after {. By this you avoid interpreting it as a tag.

If it's necessary to print these characters in a situation where they would be interpreted as a tag you can use specials tags to print out these characters – {l} for { and {r} for }.

{is tag}
{ is not tag }
{l}is not tag{r}