Laravel 5 not getting any error logs - php

I installed Laravel 5 on a new VPS, I was running everything fine but I noticed I wasn't getting any Laravel errors the system would only fire a server 500 error at me which is no help when debugging my code.
When I looked in the laravel storage/log it was empty which was strange because I had set the correct file permissions of 777.
So how do I get laravel logs? Why aren't they being written to my storage/log file.

If you've set your file permissions correctly on the /storage file directory and you're running on a VPS not shared hosting you might want to check your apache log, inside var/log/apache2/error.log
Here you might just see a line that read something along the lines of /var/www/html/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied
Well this is strange because you have the correct file permissions...
Let's start by SSH'ing into your VPS head to the directory where laravel is installed normally cd /var/www/html
In here if you run ls -l You should get some results similar to this image below:
Notice how we've been accessing the site as the root user, this is our problem and we can confirm this by running ps aux | grep apache2
You can see here apache2 is running as the user www-data, which is normal for apache. Which means when our laravel installation trys to move files either using ->move() or just trying to write the log file it fails as the www-data user doesn't have permission. So you can change to this www-data user by running: chown -R www-data:www-data * (shorthand for same user/group chown -R www-data. *)
Now if you run ls -l in your www/html directory you should see root user changed to www-data:
This means were now editing the files as the www-data user which has permission, so any changes you make via SFTP should reflect this user change. Fixed!
Edit - This is the first time I answered my own question hopefully it's okay.

Related

Renaming a file in php

I'm getting a permission denied error when trying to run the rename command in PHP.
The file it is trying to rename is in another users home directory.
Here's what I've done so far:
Given the PHP user (userA) access to that group. So when I run id
I get
uid=1004(userA) gid=1006(userA) groups=1006(userA),10(wheel),1007(userB)
The PHP script is running as userA.
I ran sudo chmod -R g+rwx ./* in from the /home/userB/subdomains/mp3s directory.
When I navigate to the directory where the files are kept, under /home/userB/subdomains/mp3s/ and run ls -lha I get:
-rw-rwxr-- 1 userB userB 62M Aug 8 2017 Stress Management - Lesson 1.mp3
So the group has permission to read/write/execute, and my userA has access to that group, so why can't it rename the file?
So I am betting you got SELinux with that fancy CentOS instance. Add the following on top of your permission changes to allow PHP to rename files:
sudo chcon -t httpd_sys_rw_content_t /home/userB/subdomains/mp3s/ -R
The command may need different permissions for PHP CLI as opposed to the web service operating against it but you can find information on that on the CentOS SELinux how to:
https://wiki.centos.org/HowTos/SELinux
The first command helped me and was found on:
https://blog.lysender.com/2015/07/centos-7-selinux-php-apache-cannot-writeaccess-file-no-matter-what/

Plesk Onyx & Nextcloud PHP Errors

I tried to install Nextcloud 13 in Plesk, but if I try to open the link I get a HTTP 500 error.
PHP version: 7.0.27
PHP modules: click here
php_error.log: too long (I can send the pastebin link)
Please tell me if you need more info. I would really appreciate any help.
You might have set the wrong file permission on your Nextcloud installation.
If you created the Nextcloud directory with root permission, you need to change the ownership of the directory to a user or a group, that Plesk has permissions for.
Use these commands to change the ownership (replace myPleskUser with the username you specified during the Plesk installation)
cd /var/www/vhosts/mydomain.tld/
chown -R myPleskUser ./nextcloud
chgrp -R psaserv ./nextcloud

weird apache behaviour: error 500 if not owner of files

My server runs on Centos 5 and I recently upgraded my php from 5.4.21 to 5.4.41 for some php_intl compability issues. (my problems stated then)
I usuall have all my httpdocs files in chown root:apache and chmod 755 (except the directory i need apache to write, like the symfony app/cache or others)
Recently (after update) my webpages went blank returning a silent (no message) 500 error.
Without changing the chown of root:apache I set a chmod 755 * -R and it worked again for 2 minutes or so and went back to this silent 500 error.
I then realized that the problem did not occure if i set the chown as apache:apache
This chmod 755 * -R that fixes the problem for two minutes is really strange though and i lost quite some time trying to understand if a file was switching back to an other chmod by itself or something but nop...
If you have any clue why this chmod would fix the problem for a few minutes only.
Second thing (most important) why would apache not read my file in root:apache 755 as it clearly has the read permissions ?
a few details :
I run httpd via a "sudo httpd start"
in the config the User and Group for httpd is "apache"
my linux user apache is in the group apache
it worked ok before i updated the php version which is weird as apache confi does not seem to have changed.

Vagrant file_put_contents permission denied

I cannot seem to allow permissions in vagrant. I am attempting to run importbuddy.php in order to migrate a WordPress instance. I get the following error.
file_put_contents(/path/): failed to open stream: Permission denied
I have setup permissions to 777 on the www directory, but that changes nothing. Any idea on how to fix this?
While recursively setting folder and file permissions to 777 should fix your problem (instructions for doing so here), the root of this is probably an issue with the ownership of the files and folders.
The owner of shared folders is usually 'vagrant' but the server itself (if you're using Ubuntu) runs as user and group 'www-data'. You can view the user/group of your files by sshing into your VM (vagrant ssh), navigating to the directory in question and entering ls -l in your console.
If you're running apache, then you can update the user to 'vagrant' by editing the following file (/etc/apache2/envvars) like below:
Find this section
export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data
And change it to
export APACHE_RUN_USER=vagrant
export APACHE_RUN_GROUP=vagrant
Afterward just be sure to restart apache (with this command sudo service apache2 restart) and the file permission errors should be fixed

PHP permission error on writing to a file in Linux CentOS

I have installed linux centos 7 on a VmWare in Windows.
There are two users in the linux: root, sample
I have created a laravel project with user "sample" (logged in as sample), but when I try to run the project with user root (logged in as root), it throws a permission error that cannot write to the file (file_put_content()). I have tried
chmod 777 /var/www/html/laravel
Or even I have tried to change the permission of the write-access of the file to root using right-click->properties->permission, but to no avail.
The only possible solution has been to delete the file and re-create it with user root. Now, what is the solution? I though user root is privileged to do anything. But it seems it is not the case. What is the solution? How should change this issue?
Try chmod 777 -R /var/www/html/laravel/ ,-R is recursive

Categories