I am trying to write a query to a file for debugging. The file is in database/execute.php
. The file I want to write to is database/queries.php
.
If you are pulling from git from local to server, you will need to clear cache sometimes because of the view files it gets uploaded with it / or other cached files .
php artisan cache:clear
Sometimes it might just to the trick if your application was working before the git pull
Furthermore, as said in file_put_contents man page
in php.net
, beware of naming issues.
file_put_contents($dir."/file.txt", "hello");
may not work (even though it is correct on syntax), but
file_put_contents("$dir/file.txt", "hello");
works. I experienced this on different php installed servers.
Realise this is pretty old now, but there's no need to manually write queries to a file like this. MySQL has logging support built in, you just need to enable it within your dev environment.
Take a look at the documentation for the 'general query log':
http://dev.mysql.com/doc/refman/5.1/en/query-log.html
For anyone using Ubuntu and receiving this error when loading the page locally, but not on a web hosting service,
I just fixed this by opening up nautilus (sudo nautilus
) and right click on the file you're trying to open, click properties > Settings > and give read write to 'everyone else'
is that you can make Apache (www-data)
, the owner of the folder
sudo chown -R www-data:www-data /var/www
that should make file_put_contents
work now. But for more security you better also set the permissions like below
find /var/www -type d -print0 | xargs -0 chmod 0755 # folder
find /var/www -type f -print0 | xargs -0 chmod 0644 # files
/var/www
to the root folder of your php fileshad the same problem; my issue was selinux was set to enforcing.
I kept getting the "failed to open stream: Permission denied" error even after chmoding to 777 and making sure all parent folders had execute permissions for the apache user. Turns out my issue was that selinux was set to enforcing (I'm on centos7), this is a devbox so I turned it off.