Permissions – 500 Error After Installation

[Ubuntu 18.04 / Apache 2.4 / PHP 7.2.17 / Magento 2.3.1]

Once the installation is complete, magento displays a blank page. I found the following error in apache error.log:

[php7:error] [pid 29252] [client 127.0.0.1:45454] PHP error fatal:
RuntimeException Uncaught: Can not Create a Directory
/var/www/html/magento/generated/code/Magento/Framework/App/ResourceConnection/.nClass
Magento Framework App ResourceConnection Proxy build error:
The requested class did not generate correctly because the generated property was not generated correctly.
The directory authorization is read-only. If — after running the
& # 39; bin / magento setup: di: compile & # 39; the CLI command when the & # 39; generated & # 39;
the directory authorization is set to write — the requested class has not
generate correctly, then you have to add the generated class object to the
signature of the associated construction method, only. in
/var/www/html/magento/vendor/magento/framework/Code/Generator.php:135nStack
trace: n # 0
/var/www/html/magento/vendor/magento/framework/Code/Generator/Autoloader.php(35)
Magento Framework Code Generator-> generateClass ("Magento \ Framewo …") n # 1
[internal function]:
Magento Framework Code Generator Autoloader-> load (Magento \ Framewo …) n # 2
[internal function]: spl_autoload_call ("Magento \ Framewo …") n # 3
/ var / www / html / magento / vendor / mag in
/var/www/html/magento/vendor/magento/framework/Code/Generator.php on
line 135

I put chmod -R 777 / var / www / html / magento / generated.
But that shows the same mistake.
Can you help?