Permissions Symfony2 on Mac: Either Apache _www or my user can access cache files - macos

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.

Related

500 issue with Laravel

I have seen this answer in many posts but they have not helped me at all. I followed the regular steps to create the laravel project like this:
I cloned from my repository.
I ran composer update.
I added 777 permissions to storage and bootstrap folders.
I have a .env file.
I verfied the .htacces and it's ok.
It is working in locahost, but when I try to replicate it in Hostinger it does not work, it displays the 500 server error. So I wonder what is the problem?
I checked the logs by the way and they were empty. I put the laravel project debugger to true too.
the website url is xellin.com
The debug:
The logs folder:
Thanks.
I think this is a good opportunity to point out how PHP / Laravel / Underlying Server interacts one to each other.
First:
The HTTP server inspects Document Root and .htaccess to get instructions.
If the file is .php (like Laravel), then it CALLS to the php handler.
The php handler could be a FPM version or a Fast CGI version.
-> If an error ocurrs parsing the .htaccess or with the initial interaction between Http Server and PHP... Laravel never runs for real. All ends in a PHP error log
To find out what's wrong, you need to inspect what PHP / Http Server said about the error in their respective logs.
In short words: at this point is not a Laravel error, but a server/php one.
Second:
If Apache/PHP runs well, then PHP executes the Laravel Applicacion Lifecycle... if Laravel encounters a problem, then you will see the usual output error of Laravel Error Handler.
I think this is a must to know to work with web apps in general, because many times developers miss to catch if the problem was with Laravel, or with PHP / Server itself.
As a side note, that's why it is important to know how to choose propper hosting service for Laravel.
Thanks for reading.
You can try to clear cache
Like as
php artisan optimize
Or
You can manually delete cache files which is located in bootstrap folder and inside bootstrap folder you can see cache folder inside cache folder delete all files except git ignore file your issue fix
If you show again this error on live serve then tou can update your composer and then run
php artisan optimize
at first, if you give any of your folders 777 permissions, you are allowing ANYONE to read, write and execute any file in that directory.... what this means is you have given ANYONE (any hacker or malicious person in the entire world) permission to upload ANY file, virus or any other file, and THEN execute that file...so please be careful because IF YOU ARE SETTING YOUR FOLDER PERMISSIONS TO 777 YOU HAVE OPENED YOUR SERVER TO ANYONE THAT CAN FIND THAT DIRECTORY. please read the full explanation from here
the second here is the detailed steps I used to deploy my projects to the server:
run npm run production then update your github repo.
clone the project from GITHUB to server - clone to an outside folder (not public_html folder)
run cd <cloned folder name>
run composer install
run npm install
copy and configure .env file to cloned folder( be sure name is .env not env).
copy all content of cloned_project_folder_name/public to public_html folder
in index.php inside public_html folder edit as below
$app = require_once __DIR__.'/../cloned_project_folder_name/bootstrap/app.php';
require __DIR__.'/../cloned_project_folder_name/vendor/autoload.php';
set your .htaccess properly.
change permission to 755 to index.php and all file in public_html folder
run composer install --optimize-autoloader --no-dev
run php artisan config:cache
run php artisan route:cache
I think I state it all, hope that will help

Laravel 5.3 Cannot Find File Error

I've setup a project more than a month ago and all of a sudden (this afternoon) I started getting the following error:
ErrorException in Filesystem.php line 111: file_put_contents(/var/www/html/project/api/storage/framework/cache/d8/00/d800874b5dc22b961e0ee92f8d1c5a09c24ee911): failed to open stream: No such file or directory
I've done research and tried the following with no success:
php artisan cache:clear
chmod -R 777 storage (I know this is not ideal)
composer update
Nothing is working. Before the chmod I was getting a permission error. I'm tapped out of ideas. Does anyone know what is causing this and how to resolve it?
You gave 777 to /storage folder but did you also make sure it's in same group as apache server is running?
Generally apache is in www-data group, add storage and bootstrap folder to be written by this group:
chgrp -R www-data /storage /bootstrap
Assign current user and group permission to read and write:
chmod -R ug+rw /storage /bootstrap
I'm 99% sure this will do it.
My server runs CentOS 7 and somehow Selinux was set to enforcing which breaks Laravel for some reason. I remember changing it when I first set up Laravel, but somehow it reverted back.
So setting it to permissive or disabled fixed it for me.
https://www.centos.org/docs/5/html/5.2/Deployment_Guide/sec-sel-enable-disable.html

Changing Base URL in Magento

I am moving a magento store from mydomaintest.com to mydomain.com.
When I say move, in this instance, we simply used the Cpanel to Modify Account and changed the Domain Name from mydomaintest.com to mydomain.com.
Then using the advice found in forums I used PHPMyAdmin to update the Magento Core Config table to the new BaseURL for both Secure and Unsecure url's.
After doing this I deleted all files in /var/cache.
Trying to access the site by domain name or IP is providing the following error:
Fatal error: require_once() [function.require]: Failed opening required '/home/mydomain/public_html/errors/report.php' (include_path='/home/mydomain/public_html/app/code/local:/home/mydomain/public_html/app/code/community:/home/mydomain/public_html/app/code/core:/home/mydomain/public_html/lib:.:/usr/lib/php:/usr/local/lib/php') in /home/mydomain/public_html/app/Mage.php on line 847
Please help, we are trying to move live today and can't seem to figure this one out.
Thanks!
John
Go to System > Index management and Reindex data as it also contain the url rewrites. Also be sure to check System > Cache Management (some versions still have that) and flush all cache as var/cache is not the only caching location. The zend components save their cache in the tmp folder.
I had this issue with Magento running with Apache2 on Ubuntu 14.10
Make sure that MySQL module for PHP is install:
dpkg --list | grep php5-mysql
If it is not listed, you need to install it:
sudo apt-get install php5-mysql
Then restart Apache:
sudo service apache2 restart
In our case we get this message because someone deleted the "error" folder - the site works fine until an error happens.
Once we restored the folder (and make sure PHP can access it), we see the normal Magento error page.
If you don't have the folder you can download Magento and extract it from the archive.

Enabling CodeIgniter logging in Ubuntu

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)

Work with app/console in Symfony at Mac OS X

I've installed Symfony on Mac Os X and do:
chmod -R 777 app/cache app/log
Try do this:
php app/console cache:clear
And get back error:
[RuntimeException]
Unable to write in the "/Users/anton/Sites/local/Symfony/app/cache/dev" directory
Try to fix it! Thanks!
If you are on Mac you can use ACL as it is explained here.
From the project directory:
sudo chmod +a "_www allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs
sudo chmod +a "whoami allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs
_www in the first line is the name of which is running the web server
You have to change whoami in the second line as it is you when you type php app/console cache:clear. (usually the name of your home folder)
Apparently your web server (apache?) already created some files or dirs in the cache folder (so they are owned be the web servers user, probably www-data). In this case a chmod isn't enough, you have to execute a chown -R anton app/cache app/log.
To avoid the general problem of different owners of different cache files, your console user and the user executing php for the web server should be the same. There are different ways to accomplish this. You could:
Change your apache configuration, so the apache runs with your user (anton) rather than www-data
Drop mod_php and use php5-fpm instead (and configure it to use your user)
Use fast_cgi

Resources