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
Related
I want to update database password inside the env file. I want to update the db_password variable.
I am trying the following command after navigation to /var/www/html
php artisan env:set db_password=myPassWordHere
And I am getting error.
PHP Fatal error: Uncaught UnexpectedValueException: The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied in /var/www/html/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:107
Full error
PHP Fatal error: Uncaught UnexpectedValueException: The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied in /var/www/html/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:107
Stack trace:
#0 /var/www/html/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog\Handler\StreamHandler->write(Array)
#1 /var/www/html/vendor/monolog/monolog/src/Monolog/Logger.php(337): Monolog\Handler\AbstractProcessingHandler->handle(Array)
#2 /var/www/html/vendor/monolog/monolog/src/Monolog/Logger.php(616): Monolog\Logger->addRecord(400, Object(UnexpectedValueException), Array)
#3 /var/www/html/vendor/laravel/framework/src/Illuminate/Log/Writer.php(202): Monolog\Logger->error(Object(UnexpectedValueException), Array)
#4 /var/www/html/vendor/laravel/framework/src/Illuminate/Log/Writer.php(113): Illuminate\Log\Writer->writeLog('error', Object(UnexpectedValueException), Array)
#5 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundati in /var/www/html/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php on line 107
PHP Fatal error: Uncaught UnexpectedValueException: The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied in /var/www/html/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:107
How can I update db_password variable inside env file, using command line?
Check that the log file exists and that it has write permissions:
ls -l /var/www/html/storage/logs/laravel.log
If it's not writable, run:
chmod 755 /var/www/html/storage/logs/laravel.log
You can use the Github Package https://github.com/svenluijten/flex-env
After the Successful Package Installation
For Example
If you want to add new constant to .env File
Maybe if you want to add ADMIN_EMAIL with the value admin#app.com
php artisan env:set ADMIN_EMAIL admin#app.com
I had a similar issue and was able to resolve it by running the following set of commands.
php artisan route:clear
php artisan config:clear
php artisan cache:clear
(In that order)
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.
I'm trying to install pterodactyl server management panel on my CentOS 7 server.. I did chown and chmod stuff like docs told me so. But when i try to open the website i see a blank page (phpinfo.php file works like it should work)
output of www-error.log
[22-Nov-2017 16:49:58 UTC] PHP Fatal error: Uncaught UnexpectedValueException: The stream or file "/var/www/html/pterodactyl/storage/logs/laravel-2017-11-22.log" could not be opened: failed to open stream: Permission denied in /var/www/html/pterodactyl/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:107
Stack trace:
#0 /var/www/html/pterodactyl/vendor/monolog/monolog/src/Monolog/Handler/RotatingFileHandler.php(107): Monolog\Handler\StreamHandler->write(Array)
#1 /var/www/html/pterodactyl/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog\Handler\RotatingFileHandler->write(Array)
#2 /var/www/html/pterodactyl/vendor/monolog/monolog/src/Monolog/Logger.php(337): Monolog\Handler\AbstractProcessingHandler->handle(Array)
#3 /var/www/html/pterodactyl/vendor/monolog/monolog/src/Monolog/Logger.php(616): Monolog\Logger->addRecord(400, Object(Symfony\Component\Debug\Exception\FatalErrorException), Array)
#4 /var/www/html/pterodactyl/vendor/laravel/framework/src/Illuminate/Log/Writer.php(203): Monolog\Logger->error(Ob in /var/www/html/pterodactyl/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php on line 107
You should create the following folder /var/www/html/pterodactyl/storage/logs/ then change the permission so Apache or Nginx can write to that folder.
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.
I am trying to execute my first application in cakephp, but it's giving an error
Fatal error: Uncaught exception 'CacheException' with message 'Cache
engine _cake_core_ is not properly configured.' in
/opt/lampp/htdocs/CakeTooDoo/lib/Cake/Cache/Cache.php:166 Stack trace:
#0 /opt/lampp/htdocs/CakeTooDoo/lib/Cake/Cache/Cache.php(136): Cache::_buildEngine('_cake_core_') #1
/opt/lampp/htdocs/CakeTooDoo/app/Config/core.php(336):
Cache::config('_cake_core_', Array) #2
/opt/lampp/htdocs/CakeTooDoo/lib/Cake/Core/Configure.php(78):
include('/opt/lampp/htdo...') #3
/opt/lampp/htdocs/CakeTooDoo/lib/Cake/bootstrap.php(171):
Configure::bootstrap(true) #4
/opt/lampp/htdocs/CakeTooDoo/app/webroot/index.php(92):
include('/opt/lampp/htdo...') #5 {main} thrown in
/opt/lampp/htdocs/CakeTooDoo/lib/Cake/Cache/Cache.php on line 166
and two warnings
Warning: _cake_core_ cache was unable to write 'cake_dev_en-us' to
File cache in /opt/lampp/htdocs/CakeTooDoo/lib/Cake/Cache/Cache.php on
line 310
Warning: /opt/lampp/htdocs/CakeTooDoo/app/tmp/cache/persistent/ is not
writable in
/opt/lampp/htdocs/CakeTooDoo/lib/Cake/Cache/Engine/FileEngine.php on
line 337
Pleas give me any solution to do my first application with cakephp.
you can use a permissive ownership:
chmod -R 777 app/tmp
A better method is to change group ownership of tmp and everthing below it to www-data ( or whatever group your apache server runs in ) with 'chgrp -R www-data tmp' followed by 'chmod -R 774 tmp' This makes tmp read/write for you and the www-data group but readonly for everyone else
let me know if i can help you more.
The cache folder is not writable according to warning.
open terminal, run sudo chmod 777 /opt/lampp/htdocs/CakeTooDoo -R
Plus, you should reconfigure file permissions, like 775, in real productions.