php fopen() permissions issue - php

I looked everywhere on the web and just couldn't find a solution.
I am getting this error:
Warning: fopen(/var/www/html/includes/../log/404/log_2018-04-07.txt): failed to open stream: Permission denied in /var/www/html/vendor/katzgrau/klogger/src/Logger.php on line 167
Fatal error: Uncaught exception 'RuntimeException' with message 'The file could not be opened. Check permissions.' in /var/www/html/vendor/katzgrau/klogger/src/Logger.php:134 Stack trace:
#0 /var/www/html/includes/db_class.php(7204): Katzgrau\KLogger\Logger->__construct('/var/www/html/i...')
#1 /var/www/html/includes/db_class.php(7217): db_class->getLogger('404')
#2 /var/www/html/includes/furl_router.php(55): db_class->logger('404')
#3 /var/www/html/includes/furl_router.php(229): goTo404('no page-data / ...')
#4 /var/www/html/index.php(17): require_once('/var/www/html/i...')
#5 {main} thrown in /var/www/html/vendor/katzgrau/klogger/src/Logger.php on line 134
From what I read here it's a permission issue but I can't figure it out. I granted all permissions from root folder, I have no idea what am I doing wrong.

Check folder write permissions. Maybe the user trying to write the log has no permissions. sudo chmod -R 666 logs gives read and write permissions to all users.
For anyone using Katzgrau\KLogger\Logger and using relative paths to locate the log file, use an absolute path, e.g.:
$logger = new Logger(__DIR__ . '/../../logs');

After reading a bit about another issue I had but with a MySQL function, after exploring, I figured out I should use MySQL version 5.6 while I used version 5.7.
I uninstalled MySQL 5.7 and install 5.6 instead. It solved both the MySQL issue and the issue mentioned above.

Related

Fail to restore magento on a new domain

I used Ubuntu Desktop to be my server hosting Magento. I have restored the Magento in following way:
Import Magento database to MySQL server
Copy and paste all the files to /var/www/html
Remarks:
Permission: 755
Magento Version: 1.9.2
PHP version: 7.0
Unfortunately, I have got an error related to the code generated by Magento.
Fatal error:
Uncaught Error: Call to a member function extend() on boolean in /var/www/html/lib/Varien/Simplexml/Config.php:600
Stack trace:
#0 /var/www/html/app/code/core/Mage/Core/Model/Config.php(278): Varien_Simplexml_Config->extend(Object(Mage_Core_Model_Config_Base))
#1 /var/www/html/app/code/core/Mage/Core/Model/App.php(391): Mage_Core_Model_Config->loadBase()
#2 /var/www/html/app/code/core/Mage/Core/Model/App.php(304): Mage_Core_Model_App->_initBaseConfig()
#3 /var/www/html/app/code/core/Mage/Core/Model/App.php(348): Mage_Core_Model_App->baseInit(Array)
#4 /var/www/html/app/Mage.php(683): Mage_Core_Model_App->run(Array)
#5 /var/www/html/index.php(83): Mage::run('', 'store')
#6 {main} thrown in /var/www/html/lib/Varien/Simplexml/Config.php on line 600
How can I solve this error in order to restore Magento on a new domain?
I have tried to lower the permission to 644 but it failed. Moreover, I have tested that PHP7.0 can also open the installation page of a new Magento.
Although you have tried to set permissions of folders and files but still it seems to be a problem with folder and file permission.
Please try resetting permission using magento-cleanup.php
file.
Please put this file in document root of your magento and run this file from browser.
Please let me know whether it solves your problem or not.
This will help:
Try clearing cache, and check file permissions are correctly set,
Directories : 755
Files : 644
If this still doesn't work then may be your files are corrupt.

Deploying Laravel 5.2 unusual permission error

I am trying to load my project on the live server.
these are the specs
PHP version 5.6
Server : Windows
I have loaded all the files and chmod 777
Storage
Vendor
bootstrap/cache
but it keeps giving me the following streaming error:
Fatal error: Uncaught exception 'UnexpectedValueException' with
message 'The stream or file
"C:\inetpub\wwwroot\websites\mysite\storage/logs/laravel.log" could
not be opened: failed to open stream: Permission denied' in
C:\inetpub\wwwroot\websites\mysite\vendor\monolog\monolog\src\Monolog\Handler\StreamHandler.php:87
Stack trace: #0
C:\inetpub\wwwroot\websites\mysite\vendor\monolog\monolog\src\Monolog\Handler\AbstractProcessingHandler.php(37):
Monolog\Handler\StreamHandler->write(Array) #1
C:\inetpub\wwwroot\websites\mysite\vendor\monolog\monolog\src\Monolog\Logger.php(336):
Monolog\Handler\AbstractProcessingHandler->handle(Array) #2
C:\inetpub\wwwroot\websites\mysite\vendor\monolog\monolog\src\Monolog\Logger.php(615):
Monolog\Logger->addRecord(400, Object(UnexpectedValueException),
Array) #3
C:\inetpub\wwwroot\websites\mysite\vendor\laravel\framework\src\Illuminate\Log\Writer.php(202):
Monolog\Logger->error(Object(UnexpectedValueExc
in C:\inetpub\wwwroot\websites\mysite\vendor\monolog\monolog\src\Monolog\Handler\StreamHandler.php on
line 87
Fatal error: Uncaught exception 'UnexpectedValueException' with
message 'The stream or file
"C:\inetpub\wwwroot\websites\mysite\storage/logs/laravel.log" could
not be opened: failed to open stream: Permission denied' in
C:\inetpub\wwwroot\websites\mysite\vendor\monolog\monolog\src\Monolog\Handler\StreamHandler.php:87
Stack trace: #0
C:\inetpub\wwwroot\websites\mysite\vendor\monolog\monolog\src\Monolog\Handler\AbstractProcessingHandler.php(37):
Monolog\Handler\StreamHandler->write(Array) #1
C:\inetpub\wwwroot\websites\mysite\vendor\monolog\monolog\src\Monolog\Logger.php(336):
Monolog\Handler\AbstractProcessingHandler->handle(Array) #2
C:\inetpub\wwwroot\websites\mysite\vendor\monolog\monolog\src\Monolog\Logger.php(615):
Monolog\Logger->addRecord(400,
Object(Symfony\Component\Debug\Exception\FatalErrorException), Array)>
3 C:\inetpub\wwwroot\websites\mysite\vendor\laravel\framework\src\Illuminate\Log\Writer.php(202):
Monolog\Logger->er
in C:\inetpub\wwwroot\websites\mysite\vendor\monolog\monolog\src\Monolog\Handler\StreamHandler.php on
line 87
You need to allow writing for logs dir chmod -R 777 storage/logs
You didn't set permissions correctly. You're on Windows, so read this or this. storage folder with all subfolders and files should be accessible to r&w.
I had a similar problem, turns out the server didnt create the file with the correct owner, even though permissions were set correctly. Hope this helps someone!
I deleted that particular log (im using daily logs) and it worked again.
Delete laravel.log file inside logs folder.
It worked for me.

Laravel 5.0: Migration Refresh Error

I am an absolute beginner of laravel.
I would like to make some changes in my database. but when I try to refresh my databases, I keep dealing with the error below.
Before making this post, I googled so much and read many references. However, none of that worked and helped me solve the error.
Has anyone encountered this error before? Any advice would be appreciated. Thanks in advance.
PHP Fatal error: Uncaught exception 'UnexpectedValueException' with message 'The stream or file "/web/journal/storage/logs/laravel-2016-04-03.log" could not be opened: failed to open stream: Permission denied' in /web/journal/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:87 Stack trace: #0 /web/journal/vendor/monolog/monolog/src/Monolog/Handler/RotatingFileHandler.php(88): Monolog\Handler\StreamHandler->write(Array) #1 /web/journal/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog\Handler\RotatingFileHandler->write(Array)#2 /web/journal/vendor/monolog/monolog/src/Monolog/Logger.php(336): Monolog\Handler\AbstractProcessingHandler->handle(Array)#3 /web/journal/vendor/monolog/monolog/src/Monolog/Logger.php(615): Monolog\Logger->addRecord(400, 'exception 'Unex...', Array)#4 /web/journal/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(47): Monolog\Logger->error('exception 'Unex...')#5 /web/journal/app/Exceptions/Handler.php(27): Illuminate\Foundation\ in /web/journal/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php on line 87 PHP Fatal error: Uncaught exception 'UnexpectedValueException' with message 'The stream or file "/web/journal/storage/logs/laravel-2016-04-03.log" could not be opened: failed to open stream: Permission denied' in /web/journal/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:87Stack trace: #0 /web/journal/vendor/monolog/monolog/src/Monolog/Handler/RotatingFileHandler.php(88): Monolog\Handler\StreamHandler->write(Array) #1 /web/journal/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog\Handler\RotatingFileHandler->write(Array)#2 /web/journal/vendor/monolog/monolog/src/Monolog/Logger.php(336): Monolog\Handler\AbstractProcessingHandler->handle(Array)#3 /web/journal/vendor/monolog/monolog/src/Monolog/Logger.php(615): Monolog\Logger->addRecord(400, 'exception 'Symf...', Array) #4 /web/journal/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(47): Monolog\Logger->error('exception 'Symf...')#5 /web/journal/app/Exceptions/Handler.php(27): Illuminate\Foundation\ in /web/journal/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php on line 87
run
composer dump-autoload
inside project, before running artisan
Add www-data group and write permission to the folder /storage/logs/. error is about writing permission of the log file. need to change permission of /storage/logs/. then only the real error will be seen
sudo chmod -R 777 storage
would help change permission

Trouble getting cakephp 2.4.0 running - fatal errors when attempting to complete tutorial

I am trying to follow the instructions for the cakephp tutorial found here: http://book.cakephp.org/2.0/en/getting-started.html
I uploaded the CakePHP files to my webserver, created the database using MySQL workbench, and created database.php and updated it to point to my MySQL server.
At this point it sounds like I should be able to open up the website in my browser and see something, but instead I get these errors (I have removed the full path):
Warning: _cake_core_ cache was unable to write 'cake_dev_en-us' to File cache in /caketut/lib/Cake/Cache/Cache.php on line 325
Warning: caketut/app/tmp/cache/persistent/ is not writable in /www/premium/med/pediatrics/www.hobmt.umn.edu/htdocs/caketut/lib/Cake/Cache/Engine/FileEngine.php on line 380
Fatal error: Uncaught exception 'CacheException' with message 'Cache engine _cake_core_ is not properly configured.' in /caketut/lib/Cake/Cache/Cache.php:181
Stack trace:
#0 /caketut/lib/Cake/Cache/Cache.php(151): Cache::_buildEngine('_cake_core_')
#1 /caketut/app/Config/core.php(367): Cache::config('_cake_core_', Array)
#2 /caketut/lib/Cake/Core/Configure.php(72): include('/www/premium/me...')
#3 /caketut/lib/Cake/bootstrap.php(177): Configure::bootstrap(true)
#4 /caketut/app/webroot/index.php(92): include('/www/premium/me...')
#5 {main} thrown in /caketut/lib/Cake/Cache/Cache.php on line 181
I tried setting the permissions for the Cache folder located in /caketut/lib/Cake and all subfolders/files to be 0776, and this removes all errors except this one:
Fatal error: Class 'Cache' not found in /caketut/app/Config/core.php on line 361
I tried doing searches but was unsuccessful in finding a solution. I would really appreciate any assistance!
try to chmod the whole script with 0777 permissions .
sudo chmod -R 0777 caketut

permission denied on php from command line

I'm trying to run a script using crontab, but I have problems making it work even from the command line. The script runs fine from the browser and it creates some excel files in reports/ folder which is owned by apache. The script file is owned by me: john.
When I try to run the script from the command line, I get the following warnings, and the excel file doesn't create. I've tryed with the full path, but I get the same results.
This is what I got after I try to run the script from command line
public_html]$ php include/tests/mailme.php
PHP Warning: fopen(reports/4-March.xls): failed to open stream: Permission denied in /home/john/public_html/PHPExcel/Shared/OLE/PPS/Root.php on line 90
Warning: fopen(reports/4-March.xls): failed to open stream: Permission denied in /home/john/public_html/PHPExcel/Shared/OLE/PPS/Root.php on line 90
PHP Fatal error: Uncaught exception 'Exception' with message 'Can't open reports/4-March.xls. It may be in use or protected.' in /home/john/public_html/PHPExcel/Shared/OLE/PPS/Root.php:93
Stack trace:
#0 /home/john/public_html/PHPExcel/Writer/Excel5.php(233): PHPExcel_Shared_OLE_PPS_Root->save('reports/...')
#1 /home/john/public_html/include/generate_daily_excel.inc(401): PHPExcel_Writer_Excel5->save('reports/...')
#2 /home/john/public_html/include/tests/mailme.php(41): generateDailyExcel('04-02-2013')
#3 {main}
thrown in /home/john/public_html/PHPExcel/Shared/OLE/PPS/Root.php on line 93
Fatal error: Uncaught exception 'Exception' with message 'Can't open reports/4-March.xls. It may be in use or protected.' in /home/john/public_html/PHPExcel/Shared/OLE/PPS/Root.php:93
Stack trace:
#0 /home/john/public_html/PHPExcel/Writer/Excel5.php(233): PHPExcel_Shared_OLE_PPS_Root->save('reports/...')
#1 /home/john/public_html/include/generate_daily_excel.inc(401): PHPExcel_Writer_Excel5->save('reports/...')
#2 /home/john/public_html/include/tests/mailme.php(41): generateDailyExcel('04-02-2013')
#3 {main}
thrown in /home/john/public_html/PHPExcel/Shared/OLE/PPS/Root.php on line 93
I assume that if I change the owner of reports, the browser version will not be allowed to save. I'm new to linux and rights.
When you run php code from command line. The script runs with your user permission , not with www-data user permissions.
You should run script as root (not recommend) , or instead change the file permissions:
sudo chown yourUser:www-data file
sudo chmod 664 file
And you should do nearly the same with the directory:
sudo chown yourUser:www-data dir
sudo chmod 775 dir
The error is laid out very explicitely for you: "failed to open stream: Permission denied". When you are running this from the command line, you are user "john" (I assume from your home path). Does user "john" have permission to write in the reports directory?
What are the permissions of the actual reports directory?
ls -al /home/john/public_html/reports

Categories