I'm getting a Twig error ...
Uncaught exception 'RuntimeException' with message 'Unable to write in the cache directory (./cache/twig/69).
but only ever in that 1 hexadecimal directory listed above. If I then set the permissions on that folder to 0777 and also set the permissions on the files it contains, it works correctly but only for a few days. I then have to do the same fix and so on and so on. None of the other directories in the twig folder are affected. Any ideas?
Check the permission of the folder. It should have write access.
Check SELinux policy
sestatus
To disable SELinux
sudo setenforce 0
Are you running commands from the CLI with a different user than the webserver? This often occurs if you run console commands as e.g. root and they create cache directories. Try clearing the cache completely after each CLI call.
Related
I am trying to run R code from within PHP. I am using RHEL 7.4.
However, because Apache runs as a different user than installed the R packages, it cannot load packages:
My PHP code has this line:
echo shell_exec("(Rscript -e 'library(lme4, lib.loc = \"/var/www/R/lib\")')2>&1");
which produces this error in the browser:
Error: package or namespace load failed for 'lme4' in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/var/www/R/lib/Rcpp/libs/Rcpp.so':
/var/www/R/lib/Rcpp/libs/Rcpp.so: failed to map segment from shared object: Permission denied
Execution halted
The file /var/www/R/lib/Rcpp/libs/Rcpp.so has permissions 775, so I don't think the permissions are actually the problem.
How can I tell Apache / PHP where to look for the shared libraries?
The server is not public-facing, so I would take any solution from properly accessing the shared library, to giving user apache sudo access with NOPASSWD to run as my user (or something similarly reckless, since that didn't actually work...).
Thank you!
This appears due in part to an SELinux setting in Red Hat. I'm not entirely sure whether this is Red Hat-centric, or specific to the configuration at my university (who installed Red Hat in the first place).
Originally:
$ getenforce
Enforcing
Fix:
$ sudo setenforce 0
$ getenforce
Permissive
Persistent fix: modify /etc/selinux/config to have the line
SELINUX=Permissive
Credit to this StackOverflow thread.
I have a simple script that outputs Permission denied warning in the browser:
rename('/opt/web/test.tmp', '/opt/web/test.tmp1')
Script path is /opt/web/test_rename.php
/opt/, /opt/web/ and /opt/web/test_rename.php are 777 and have apache owner / group.
httpd process owner is apache
test.tmp is 777 and have apache owner as well
It works fine with cli.
What else could I do to make it work via apache?
The problem was with SELinux. It can block php rename function.
I've found the answer here: http://forums.fedoraforum.org/archive/index.php/t-111081.html
On the Fedora Core 3 Linux distribution, you may get a "failed to open stream: Permission denied in ..." message. In fact changing the permission of the directory will not work (even if you set to 0777).
It is because of the new SELinux kernel that allow apache user to write only in /tmp dir (I think). In order to solve the problem you must to disable the SELinux (at least for apache service) to allow the server to write in other directories. To do that, run the system-config-securitylevel app and disable the SE to apache service. Reboot your system and continue your work.
I have used Symfony a lot in the past and haven't had many problems. I have been trying to deploy it on a different server (Ubuntu 16 w/ Apache) and am having a lot of issues.
I am getting 500 error now (https://bereanboard.com/app_dev.php). What I have tried is to go to *.com/config.php and *.com/app_dev.php to see issues (I had to temporarily comment out the section that forbids access from non localhost). I have also been checking the Apache error.log and Symfony's var/logs/prod.log.
Keep in mind it works fine on local MAMP and on my previous CentOS.
First, I am for the first time encountering permission problems for var/cache and var/logs. This was pretty easy to fix with commands like chmod -R 777 var/cache. But why did this issue come up only on this new server? Anyway, config.php on the new server is now telling me "All checks passed".
Second, in var/logs/prod.log I am getting all sorts of 'Can't find class, did you forget a "use" statement?' errors. Some of these are for a twig extension AppBundle/Twig/AppExtension.php.
Here are some Critical erros:
request.CRITICAL: Uncaught PHP Exception InvalidArgumentException:
"Class "AppBundle\Controller\HomeController" does not exist." at
/home/travis/var/cache/prod/classes.php line 4872
{"exception":"[object] (InvalidArgumentException(code: 0): Class
\"AppBundle\Controller\HomeController\" does not exist. at
/home/travis/var/cache/prod/classes.php:4872)"} []
and
php.CRITICAL: Class 'AppBundle\Twig\AppExtension' not found
{"exception":"[object]
(Symfony\Component\Debug\Exception\FatalThrowableError(code: 0):
Class 'AppBundle\Twig\AppExtension' not found at
/home/travis/var/cache/prod/appProdProjectContainer.php:2881)"} []
[2017-01-19 06:35:03] request.CRITICAL: Uncaught PHP Exception
Symfony\Component\Debug\Exception\ClassNotFoundException: "Attempted
to load class "AppExtension" from namespace "AppBundle\Twig". Did you
forget a "use" statement for another namespace?" at
/home/travis/var/cache/prod/appProdProjectContainer.php line 2881
{"exception":"[object]
(Symfony\Component\Debug\Exception\ClassNotFoundException(code:
0): Attempted to load class \"AppExtension\" from namespace
\"AppBundle\Twig\".\nDid you forget a \"use\" statement for another
namespace? at
/home/travis/var/cache/prod/appProdProjectContainer.php:2881)"} []
[2017-01-19 06:35:03] request.CRITICAL: Exception thrown when handling
an exception
(Symfony\Component\Cache\Exception\InvalidArgumentException: Cache
directory is not writable
(/home/travis/var/cache/prod/pools/CtBqbs+VrF) at
/home/travis/var/cache/prod/classes.php line 1194)
{"exception":"[object]
(Symfony\Component\Cache\Exception\InvalidArgumentException(code:
0): Cache directory is not writable
(/home/travis/var/cache/prod/pools/CtBqbs+VrF) at
/home/travis/var/cache/prod/classes.php:1194)"} []
Also, it's worth mentioning that that a fresh, empty project made from the command symfony new project does work.
*EDIT
I have consulted these Symfony docs. I have tried every way of clearing cache that I could find.
*EDIT
Here is services.yml
services:
app.twig_extension:
class: AppBundle\Twig\AppExtension
arguments: ["#doctrine.orm.entity_manager", "#security.token_storage"]
public: false
tags:
- { name: twig.extension }
It seems that there is an access problem for your web server.
Check user which launching apache on Centos by
# egrep -i '^user|^group' /etc/httpd/conf/httpd.conf
It should return apache
Then give the good privilege to /home/travis directory:
Option 1: You could have a look on Stack Echange / AskUbuntu and adapt it with apache user instead of www-data
Option 2: With first option, if you've created a folder, Apache cannot write to it. This can be "fixed" by setting umask 0007 and adding yourself (travis) to the Apache group, so that newly created files and folders are writeable by the group.
Option 2 is better if ou have enough privileges to change mask.
Try to clear cache :
php bin/console cache:clear --env=prod
and set files permissions :
chmod -R 777 var/cache
chmod -R 777 var/logs
chmod -R 777 var/sessions
hope this help you.
I had faced the same problem before once. You will have to complete remove the vendor folder
rm -R vendor/
and freshly install all the dependencies again.
php composer.phar install
This will resolve the issue.
I installed phabricator on openshift using a quickstart from github
https://github.com/CodeBlock/phabricator-openshift-quickstart
I got it running up fine, but I now have two issues:
1.) A setup issue that says apc.stat is enabled and that must be disabled in
/var/lib/openshift/my-user-hash/php/configuration/etc/php.ini
however I cannot access that with sudo command(sudo permission denied), even if I open it normally, I didn't find any apc.stat settings in the php.ini
2.) I can't figure out how set the local path for tracking repositories for diffusion. It says
I must give a path which should be read-writable by phabricator, I tried to give the persistent storage location ..data/ , but it gives me an exception as follows :
Unhandled Exception ("CommandException")
Command failed with error #1!
COMMAND
(cd '../data/' && HOME='/var/lib/openshift/my-user-hash/app-root/runtime/repo/phabricator/support/empty/' git cat-file --batch)
STDOUT
(empty)
STDERR
sh: line 0: cd: ../data/: No such file or directory
how do I fix this?
1) According to Num Duong answer, it seems like u currently could not resolve this issue, probably u should wait for openshift php.ini permissions policy changes.
Anyway this is minor non blocking issue.
2) Modify config file and re-deploy to openshift.
Look for available phabricator options here
U need smth like this: 'repository.default-local-path' => getenv('OPENSHIFT_DATA_DIR'),
P.S. Anyway there is one particular issue with phabricator on openshift that possibly never got resolved: cloning git repositories from OpenShift instances into Phabricator do not
work by SSH, due to permissions regarding the ssh configuration.
Good day.
There is a PHP module ( .so) loaded within PHP. On MINIT stage it tries to read a file.
The file is a /tmp/aaa.txt
The directory /tmp belongs to root and its permissions are set to 777.
The file /tmp/aaa.txt belongs to apache user and is also set to 777 permissions.
Module opens the file with VCWD_FOPEN(), which is define for
#define VCWD_FOPEN(path, mode) virtual_fopen(path, mode TSRMLS_CC) which eventually is a fopen().
The VCWD_FOPEN fails with error 13 (permission denied).
The strange thing is, if I invoke the module manually
( #php -r 'echo "hi";' ) - it works.
But when it runs from apache - it doesnt.
Anybody knows why?
Thank you
Found the problem.
The user permission policy was enforced by SELinux.
To disable it i typed
#setenforce 0
#service httpd restart
Works now