I'm trying to enable logging for CodeIgniter in Ubuntu. However, nothing seems to be written in my application/logs directory. Here's what I've done so far...
In the controller login.php, I have the following lines:
public function index(){
log_message("error", "Logging sanity check.");
}
I set it to error just to make sure it gets logged no matter what. Then, in my config.php, I set log_threshold to 3 (just to be safe).
Then, in the terminal running as superuser, I do chmod 666 logs and chown root logs.
Now no matter how many times I visit index.php/login, nothing seems to get logged. I've tried that both in a browser ran as superuser and as normal user. All I get in application/logs is an index.html which displays "Directory access is forbidden." I've even tried resetting XAMPP. What have I missed?
Apache on ubuntu doesn't run as root, that's for one. Secondly, directory permissions must be rwx, which equals to 7. So you have two options:
1) Relax writing permissions for everyone on the logs dir with chmod 777 logs, or
2) chown the directory to the user that's running apache (apache)
Related
I have a couple of projects on a homestead box.
last week i cloned a project from git and i noticed that when the logger was called the logfile was created and written to but the second time it complained it had no write access.
I didnt pay attention to it much because i was in a hurry, so i just deleted the log everytime.
But now, returning to a laravel 6 project i worked on previously i see the same problem suddenly occur.
This time is different, instead of not being able to write to existing logs, this time its also not able to create the logs.
I did a 777 on the storage dir and the log file error went away but now it complains it cant write session files?!
ErrorException
file_put_contents(/home/vagrant/code/laravel6_project/storage/framework/sessions/hA3459VveGgYn761YijeEBcQgNylx0mToIRyLhkR):
failed to open stream: Permission denied
Why would something that worked fine suddenly break in regard to permissions.
I dont want to go on and chmod 777 everything everytime over and over again.
All files have owner: vagrant:vagrant and this is what it always was as far as i can tell.
anyway, i figured perhaps something changed with an update or something so now in the vagrant machine i tried
sudo chmod -R vagrant:www-data
but its being ignored... folder is still vagrant:vagrant.
stumped...
There are lots of questions on this exact problem with many more times of different suggested solutions but none work for me.
Im starting to suspect the virtual machine is corrupted or something..
any ideas?
someone suggested to check if perhaps the wrong user was specified in:
/etc/php/7.3/fpm/pool.d/www.conf
perhaps it said user = www-data instead of user = vagrant
all the other versions like:
/etc/php/7.1/fpm/pool.d/www.conf
/etc/php/7.2/fpm/pool.d/www.conf
/etc/php/7.4/fpm/pool.d/www.conf
indeed all had: user = vagrant but the /var/log/php7.3-fpm.log says:
user = www-data
so i was very confident i had found the problem but after changing it to user=vagrant and restarting apache still the same error.
going nuts...
So,
editing the /etc/php/7.3/fpm/pool.d/www.conf and setting:
user = vagrant
group = vagrant
fixed it , but only after restarting the VM!
simply doing:
sudo apachectl restart
somehow didn't cut it.
I'm using the default Apache on Mac, Symfony 2.
Following Permissions issues on Symfony2, I tried rm -rf app/cache/* and chmod 777 app/cache afterwards.
That works. But...
a)
When Symfony 2 writes any cache files first, my user does not have access to the files afterwards. So clearing the cache via app/console cache:clear results in... [RuntimeException]
Unable to write in the "/Workspace/MyProject/app/cache/dev" directory
I tried to compensate by running sudo app/console cache:clear. But then ...
b)
As soon as I clear the cache using app/console cache:clear or sudo app/console cache:clear and then reload the page, Apache can't access the files:
RuntimeException in ClassCollectionLoader.php line 239: Failed to write cache file "/Workspace/yProject/app/cache/dev/classes.php".
I tried to delete the files and set the ACLs granting read and write for both, me and _www via the Mac GUI. But the result was the same as above.
It looks like only the owner (tested using chown) can access the files when apache runs as sudo. And Apache has to run as sudo when using port 80, else apachectl start would throw This operation requires root.. I found out there's tricky ways who to use port 8080 and redirect 80. But I want to understand the basic problem.
Why is it that either apache or me who has access but not both?
Thanks,
Boris
I don't know, what the problem was but I found a sloution. I zpped the folder and unzipped the files. I hoped they would lose all permissions and so they did. The unzipped files work out fine now. If somebody knows a reason, I would still be interested.
Based on a recommendation on stack overflow, i am giving yii framework a spin.
It appears that I am only able to gain shell access to my web server if I log in as root.
I am running through the tutorial, and am having a number of problems typical command to create a web app-
/usr/local/bin/php /home/testuser/public_html/yii/framework/yiic webapp /home/testuser/public_html/demo
Do I have to type /usr/local/bin/php EVERY TIME???
Do I have to type /home/testuser/public_html/yii/framework/yiic in full every time???
Do I have to yype /home/testuser/public_html/demo in full?
As I am logged in as ROOT, I have to chown every file / folder created by root to make the file viewable by testuser!!!
I create a new controller using yii. controller message helloWorld, yii does some funky stuff, but I can't do ANYTHING with the files without chown EVERYTHING!!!
I'm not too confident with SSH, and I know it's all a learning curve, but... having to change file permissions EVERY time, and having to type full directories every time is just a pain.
I know that there are some shortcuts that I will probably learn with time, but if anybody could give me some pointers to make my life about 1M times easier (considering my main objectives at present are to learn yii framework) linux/terminal/shell commands are currently secondary to my requirements.
Here's what I'd do, in this order:
1 - When you login as root issue the command su - testuser. This changes your effective user id and groupid to that of testuser, meaning, you now are operating as that user account. Your current directory should now be the testuser's home directory. To get back to root user just type exit.
2 - Try running php -v without the fullpath. If it prints out a version number then you don't have to use the fullpath to run php. If you get an error then you can add /usr/local/bin to your PATH environment variable in your .profile file which is present in testuser's home directory. If the .profile doesn't exist then you can create it.
3 - Add /home/testuser/public_html/yii/framework to your PATH in testuser's .profile.
After doing all that then the next time you login as root you would be able to do the following:
su - testuser
cd public_html
php yiic webapp demo
And you wont have to worry about permissions since you are creating directories/files as testuser, not root.
See also: StackOverflow question about modifying your PATH
Apache is running, localhost is working, if I put an index.html that works as well. However I can't access any folders (my websites) within the document root, which is /Users/Me/Sites
I get a forbidden error when I try to access these.
What's going wrong?
You should check the permissions of your home folder and your sites directory to make sure that they allow Apache access.
You could check the permissions, or just run (in a Terminal)
chmod o+x $HOME
chmod -R o+rX $HOME/Sites
Under config.php I have:
$config['log_threshold'] = 4;
$config['log_path'] = '/home/myaccount/logFilesFolder';
In index.php I have:
error_reporting(E_ALL);
The only way I can seem to get anything to log is if I chmod that directory to rwx (777), which doesn't seem right to me. That and it doesn't see to be logging all the errors.
In my local/dev environment it seems to be working but on my production server nothing is being logged. I can't seem to figure out why.
The log filename in the configuration settings needs a trailing "/" above making sure the webserver process has writeable access to the directory.
Change the logs owner and group to what owner/group your live web server is running, give it write perms and it should work. I take it that in your local/dev server your CI folder is owned by you that is why you need to chmod it to 777 to make it work.
The directory where you want the log files to be saved needs to be writable.
I have tried a lot of solutions and finally what worked for me was this:
Open system/libraries/Log.php
and change the following lines;
set the value of: $this->log_path to a writable directory, preferably home directory so that there are no permission issues. If you want to change the filename also, search for the variable $filepath and change the name.
Example:
$this->log_path = '/log';
touch /log/
restart the webserver.
The logs will start coming.
I have tried a lot of other options, none worked, this is not neat approach but at least I can see my logs now.
I had the same problem with my Codeigniter 4 project. The log was created successfully in my local window machine but was not creating on the remote Linux machine. I was using a custom path to generate log files under the 'app' folder. So what I did is to change the settings in my config/Logger.php file back to
'path' => WRITEPATH.'logs/',
and it created the log files under writeable/logs folder.