Hello.
When I want to browse Magento then it show below error:
An error has happened during application run. See exception log for details.
And "exception.log" tell me:
# cat exception.log [2019-05-21 07:36:51] main.CRITICAL: The specified "/var/www/html/generated/code/Magento/Framework/App/Http/Interceptor.php.28775" file couldn't be written. Warning!file_put_contents(/var/www/html/generated/code/Magento/Framework/App/Http/Interceptor.php.28775): failed to open stream: Permission denied Class Magento\Framework\App\Http\Interceptor generation error: The requested class did not generate properly, because the 'generated' directory permission is read-only. If --- after running the 'bin/magento setup:di:compile' CLI command when the 'generated' directory permission is set to write --- the requested class did not generate properly, then you must add the generated class object to the signature of the related construct method, only. {"exception":"[object] (RuntimeException(code: 0): The specified \"/var/www/html/generated/code/Magento/Framework/App/Http/Interceptor.php.28775\" file couldn't be written. Warning!file_put_contents(/var/www/html/generated/code/Magento/Framework/App/Http/Interceptor.php.28775): failed to open stream: Permission denied Class Magento\\Framework\\App\\Http\\Interceptor generation error: The requested class did not generate properly, because the 'generated' directory permission is read-only. If --- after running the 'bin/magento setup:di:compile' CLI command when the 'generated' directory permission is set to write --- the requested class did not generate properly, then you must add the generated class object to the signature of the related construct method, only. at /var/www/html/vendor/magento/framework/Code/Generator.php:135)"} [] [2019-05-21 07:36:51] main.CRITICAL: The specified "/var/www/html/generated/code/Magento/Framework/App/Http/Interceptor.php.28773" file couldn't be written. Warning!file_put_contents(/var/www/html/generated/code/Magento/Framework/App/Http/Interceptor.php.28773): failed to open stream: Permission denied Class Magento\Framework\App\Http\Interceptor generation error: The requested class did not generate properly, because the 'generated' directory permission is read-only. If --- after running the 'bin/magento setup:di:compile' CLI command when the 'generated' directory permission is set to write --- the requested class did not generate properly, then you must add the generated class object to the signature of the related construct method, only. {"exception":"[object] (RuntimeException(code: 0): The specified \"/var/www/html/generated/code/Magento/Framework/App/Http/Interceptor.php.28773\" file couldn't be written. Warning!file_put_contents(/var/www/html/generated/code/Magento/Framework/App/Http/Interceptor.php.28773): failed to open stream: Permission denied Class Magento\\Framework\\App\\Http\\Interceptor generation error: The requested class did not generate properly, because the 'generated' directory permission is read-only. If --- after running the 'bin/magento setup:di:compile' CLI command when the 'generated' directory permission is set to write --- the requested class did not generate properly, then you must add the generated class object to the signature of the related construct method, only. at /var/www/html/vendor/magento/framework/Code/Generator.php:135)"} [] [2019-05-21 07:37:16] main.CRITICAL: The specified "/var/www/html/generated/code/Magento/Framework/App/Http/Interceptor.php.28772" file couldn't be written. Warning!file_put_contents(/var/www/html/generated/code/Magento/Framework/App/Http/Interceptor.php.28772): failed to open stream: Permission denied Class Magento\Framework\App\Http\Interceptor generation error: The requested class did not generate properly, because the 'generated' directory permission is read-only. If --- after running the 'bin/magento setup:di:compile' CLI command when the 'generated' directory permission is set to write --- the requested class did not generate properly, then you must add the generated class object to the signature of the related construct method, only. {"exception":"[object] (RuntimeException(code: 0): The specified \"/var/www/html/generated/code/Magento/Framework/App/Http/Interceptor.php.28772\" file couldn't be written. Warning!file_put_contents(/var/www/html/generated/code/Magento/Framework/App/Http/Interceptor.php.28772): failed to open stream: Permission denied Class Magento\\Framework\\App\\Http\\Interceptor generation error: The requested class did not generate properly, because the 'generated' directory permission is read-only. If --- after running the 'bin/magento setup:di:compile' CLI command when the 'generated' directory permission is set to write --- the requested class did not generate properly, then you must add the generated class object to the signature of the related construct method, only. at /var/www/html/vendor/magento/framework/Code/Generator.php:135)"} [] [2019-05-21 07:38:15] main.CRITICAL: The specified "/var/www/html/generated/code/Magento/Framework/App/Http/Interceptor.php.28773" file couldn't be written. Warning!file_put_contents(/var/www/html/generated/code/Magento/Framework/App/Http/Interceptor.php.28773): failed to open stream: Permission denied Class Magento\Framework\App\Http\Interceptor generation error: The requested class did not generate properly, because the 'generated' directory permission is read-only. If --- after running the 'bin/magento setup:di:compile' CLI command when the 'generated' directory permission is set to write --- the requested class did not generate properly, then you must add the generated class object to the signature of the related construct method, only. {"exception":"[object] (RuntimeException(code: 0): The specified \"/var/www/html/generated/code/Magento/Framework/App/Http/Interceptor.php.28773\" file couldn't be written. Warning!file_put_contents(/var/www/html/generated/code/Magento/Framework/App/Http/Interceptor.php.28773): failed to open stream: Permission denied Class Magento\\Framework\\App\\Http\\Interceptor generation error: The requested class did not generate properly, because the 'generated' directory permission is read-only. If --- after running the 'bin/magento setup:di:compile' CLI command when the 'generated' directory permission is set to write --- the requested class did not generate properly, then you must add the generated class object to the signature of the related construct method, only. at /var/www/html/vendor/magento/framework/Code/Generator.php:135)"} [] [2019-05-21 07:39:21] main.CRITICAL: The specified "/var/www/html/generated/code/Magento/Framework/App/Http/Interceptor.php.28772" file couldn't be written. Warning!file_put_contents(/var/www/html/generated/code/Magento/Framework/App/Http/Interceptor.php.28772): failed to open stream: Permission denied Class Magento\Framework\App\Http\Interceptor generation error: The requested class did not generate properly, because the 'generated' directory permission is read-only. If --- after running the 'bin/magento setup:di:compile' CLI command when the 'generated' directory permission is set to write --- the requested class did not generate properly, then you must add the generated class object to the signature of the related construct method, only. {"exception":"[object] (RuntimeException(code: 0): The specified \"/var/www/html/generated/code/Magento/Framework/App/Http/Interceptor.php.28772\" file couldn't be written. Warning!file_put_contents(/var/www/html/generated/code/Magento/Framework/App/Http/Interceptor.php.28772): failed to open stream: Permission denied Class Magento\\Framework\\App\\Http\\Interceptor generation error: The requested class did not generate properly, because the 'generated' directory permission is read-only. If --- after running the 'bin/magento setup:di:compile' CLI command when the 'generated' directory permission is set to write --- the requested class did not generate properly, then you must add the generated class object to the signature of the related construct method, only. at /var/www/html/vendor/magento/framework/Code/Generator.php:135)"} [] [2019-05-21 07:40:20] main.CRITICAL: The specified "/var/www/html/generated/code/Magento/Framework/App/Http/Interceptor.php.28771" file couldn't be written. Warning!file_put_contents(/var/www/html/generated/code/Magento/Framework/App/Http/Interceptor.php.28771): failed to open stream: Permission denied Class Magento\Framework\App\Http\Interceptor generation error: The requested class did not generate properly, because the 'generated' directory permission is read-only. If --- after running the 'bin/magento setup:di:compile' CLI command when the 'generated' directory permission is set to write --- the requested class did not generate properly, then you must add the generated class object to the signature of the related construct method, only. {"exception":"[object] (RuntimeException(code: 0): The specified \"/var/www/html/generated/code/Magento/Framework/App/Http/Interceptor.php.28771\" file couldn't be written. Warning!file_put_contents(/var/www/html/generated/code/Magento/Framework/App/Http/Interceptor.php.28771): failed to open stream: Permission denied Class Magento\\Framework\\App\\Http\\Interceptor generation error: The requested class did not generate properly, because the 'generated' directory permission is read-only. If --- after running the 'bin/magento setup:di:compile' CLI command when the 'generated' directory permission is set to write --- the requested class did not generate properly, then you must add the generated class object to the signature of the related construct method, only. at /var/www/html/vendor/magento/framework/Code/Generator.php:135)"} []
I guess it is an error about permission but how can I solve it?
Thank you.
Hi @jason_long
It looks like permission issue of generated directory.
Execute the following command from your root folder:
chmod -R 0777 var/ pub/ generated/
I did and permissions are:
# ll total 4 drwxr-xr-x. 2 root root 6 Apr 24 18:16 cgi-bin drwxrwxr-x. 14 magento apache 4096 May 20 10:54 html
And:
$ ll total 1212 drwxr-xr-x. 4 magento apache 4096 May 19 13:47 app -rw-r--r--. 1 magento apache 234 Mar 15 09:42 auth.json.sample drwxr-xr-x. 2 magento apache 36 May 21 11:36 bin -rw-r--r--. 1 magento apache 434981 Mar 15 09:42 CHANGELOG.md -rw-r--r--. 1 magento apache 2257 Mar 15 09:38 composer.json -rw-r--r--. 1 magento apache 714229 Mar 15 09:42 composer.lock -rw-r--r--. 1 magento apache 650 Mar 15 09:42 COPYING.txt drwxr-xr-x. 5 magento apache 59 May 19 13:47 dev drwxrwxrwx. 3 magento apache 33 May 19 16:57 generated -rw-r--r--. 1 magento apache 57 Mar 15 09:42 grunt-config.json.sample -rw-r--r--. 1 magento apache 2994 Mar 15 09:42 Gruntfile.js.sample -rw-r--r--. 1 magento apache 1370 Mar 15 09:42 index.php drwxr-xr-x. 4 magento apache 47 May 19 13:47 lib -rw-r--r--. 1 magento apache 10376 Mar 15 09:42 LICENSE_AFL.txt -rw-r--r--. 1 magento apache 10364 Mar 15 09:42 LICENSE.txt -rw-r--r--. 1 magento apache 5625 Mar 15 09:42 nginx.conf.sample -rw-r--r--. 1 magento apache 1416 Mar 15 09:42 package.json.sample -rw-r--r--. 1 root root 68 May 20 10:55 phpinfo.php drwxr-xr-x. 2 magento apache 55 May 19 13:47 phpserver drwxrwxrwx. 6 magento apache 4096 May 19 13:47 pub drwxr-xr-x. 7 magento apache 4096 May 19 13:47 setup drwxr-xr-x. 7 magento apache 4096 May 19 13:47 update drwxrwsrwx. 6 magento apache 81 May 21 11:48 var drwxrwsr-x. 76 magento apache 4096 May 19 13:47 vendor
But problem exist.
@jason_long
Are you on developer mode?
or try once following commands one by one in sequence:
chmod -R 0777 var/ pub/ generated/ rm -rf var/cache/* pub/static/* generated/* php bin/magento setup:upgrade php bin/magento setup:di:compile php bin/magento setup:static-content:deploy php bin/magento indexer:reindex php bin/magento cache:flush chmod -R 0777 var/ pub/ generated/
I hope it will help you!
Hello @jason_long
Can you check permission for generated/var folder?
solution :
chmod 0777 -R generated
if works then mark as solution.
The command show me below error:
$ sudo php bin/magento setup:di:compile Compilation was started. Repositories code generation... 1/7 [====>-----------------------] 14% < 1 sec 68.5 MiBPHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32768 bytes) in /var/www/html/vendor/magento/module-newsletter/Controller/Adminhtml/Template/Edit.php on line 1 Check https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors for more info on how to handle out of memory errors.
Any idea?
@jason_long
you need to increase memory limit and max execution time on php.
for now you can add following two lines in indexiphp of root folder. May be it will work for you.
ini_set('max_execution_time', 0); ini_set('memory_limit', '-1');
otherwise you need to increase from server end for php.
Hello @jason_long
firstly you are using sudo into command that will create permission issue
while run command you need to pass memory limit
php -d memory_limit=4G your command
Hope it will help you.
I must add two lines in "index.php"? I added but got the same error!!!
Thanks.
It solve the error but other command show me below error:
$ sudo php bin/magento setup:static-content:deploy In DeployStaticContentCommand.php line 108: NOTE: Manual static content deployment is not required in "default" and "developer" modes. In "default" and "developer" modes static contents are being deployed automatically on demand. If you still want to deploy in these modes, use -f option: 'bin/magento setup:static-content:deploy -f'
How can I solve it?