I know this may seem as a repeated question but so far I have 4 hours digging around unable to find a straight answer to this. I have setup a brand new CentOS 7 and I installed NGINX (https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-centos-7) + PHP 5.6 (https://webtatic.com/packages/php56/) and MariaDB.
Following the guides I was able to make the NGINX serve PHP files successfully.
I have a project in Symfony2 which I am trying to get in this server, my problem is when I try to open up http://server/web/app.php. I get the following error:
Fatal error: Uncaught exception 'RuntimeException' with message 'Unable to create the cache directory (/usr/share/nginx/html/app/cache/prod) ' in ................
I read in the documentation (http://symfony.com/doc/current/book/installation.html) that I should work around my permissions so I was able to apply the following:
$ HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1`
$ sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache app/logs
$ sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache app/logs
Since I have CentOS 7 from scratch that was the option that I was able to apply. However, I still have the same issue, after this approach these are the other options I've tried:
changed the owner for app/cache and app/logs to nginx:nginx
changed the permissions to 777 to the above folders
verified and re-verified that PHP is running under the nginx user, I had to change this in the www.conf
if I do ls -Al it shows that app/cache and app/logs are owned by nginx
restarted services after each single change
restarted the server completely
cleared the cache and performed warmup and still
Tried the umask option provided by symfony and still.
So after all these options I still get the same issue, to other people out there with this problem it's simply following the Symfony2 guidelines for applying the ACL and puff, done. But this is not the case.
What am I missing?
Ps: I double checked the permissions of the folder..and I am in the server as root.
Update 1
I re-installed CentOS 7 from scratch and followed https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-centos-7 and in combination with Symfony's suggestion for the configuration file and still I get the " Uncaught exception 'RuntimeException' with message 'Unable to create the cache directory" error
You might be running into SELinux issues, since CentOS 7 ships with SELinux running by default.
You can test by executing setenforce 0 to see if that solves the problem. If that works, you need to configure SELinux to allow the nginx user to write to the cache directory, and then re-enable SELinux. SELinux does provide some good security, so it would be best to figure out how to configure it properly, as opposed to turning it off completely.
You need to add a local custom rule (policy module), suppose you have your application under the /usr/share/nginx/www directory:
semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/www/.+/app/(cache|logs)(/.*)?'
You need to restore the contexts for all the files in that dir:
restorecon -Rv /usr/share/nginx/www/your-app-dir
Change the group of the cache and logs directories and add permissions for the group:
chgrp -R apache /usr/share/nginx/www/your-app-dir/app/{cache,logs}
chmod -R 775 /usr/share/nginx/www/your-app-dir/app/{cache,logs}
Related
I have web based on symfony 3. For deploy i have own bash script. In this script are routines like git pull, clear cache...
On server is: Debian GNU/Linux 9 (stretch)
But after deploy i can see exception in prod.log:
[2018-05-11 16:55:36] request.CRITICAL: Uncaught PHP Exception InvalidArgumentException: "The directory "/var/www/domain.com/var/cache/prod/annotations" is not writable." at /var/www/domain.com/vendor/doctrine/cache/lib/Doctrine/Common/Cache/FileCache.php line 92 {"exception":"[object] (InvalidArgumentException(code: 0): The directory \"/var/www/domain.com/var/cache/prod/annotations\" is not writable. at /var/www/domain.com/vendor/doctrine/cache/lib/Doctrine/Common/Cache/FileCache.php:92)"} []
But problem is - before and after clear cache i have command chmod -R 777 /var and after deploy if i look to /var/cache/prod/annotations i see new files with time of change equals time when i run clear cache (via sh script).
Anybody some ideas? Where look what chceck?
This error occurs if your shell writes into app/cache first and then you open your website where other parts should be written to that folder too.
Simple solution: add your shell user to the group that your webserver uses, probably www-data, through sudo usermod -a -G www-data userName
The problem is the permissions, to fix use this:
setfacl -R -m u:www-data:rX folderProject
setfacl -R -m u:www-data:rwX folderProject/var/cache folderProject/var/logs folderProject/var/sessions folderProject/app/sessions
setfacl -dR -m u:www-data:rwX folderProject/var/cache folderProject/var/logs folderProject/var/sessions folderProject/app/sessions
Replace folderProject with your project name.
If you are using Ubuntu with apache this command fix the problem, if you are using another GNU/Linux change the user www-data to your user
I got this continuous error with cache. Something with permissions but I can't figure what's going on. In my local environment when I go a php bin/console cache:clear -e=dev it return me this
[Symfony\Component\Filesystem\Exception\IOException]
Failed to remove file "/project/var/cache/de~/pools/ORsqbHaOKl/L/K/iZULk48B-k00dzIKC2qg": unlink(/project/var/cache/de~/pools/ORsqbHaOKl/L/K/iZULk48B-k00dzIKC2qg): Permission denied.
So I need to make first a chmod -R 777 var/, then again the clear cache and it works. But when I run the website it return me
Failed to create "/project/var/cache/dev/tcpdf": mkdir(): Permission denied.
So I need again to make chmod -R 777 var/
In the production server without erasing anything sometimes i get this error
Warning: rename(C:\project\var\cache\prod/doctrine/orm/Proxies\__CG__AppBundleEntitySomeEntity.php.5a142ad84e8464.47105642,C:\project\var\cache\prod/doctrine/orm/Proxies\__CG__AppBundleEntitySomeEntity.php): Access is denied. (code: 5)
error in vendor\doctrine\common\lib\Doctrine\Common\Proxy\ProxyGenerator.php
(line 309 rename())
$tmpFileName = $fileName . '.' . uniqid('', true);
file_put_contents($tmpFileName, $proxyCode);
#chmod($tmpFileName, 0664);
rename($tmpFileName, $fileName);
}
Local environment: debian 9
Production environment: windows server 2008
You need to set the var folder permissions as suggested by this symfony article.
Run the following commands in your project directory and you will not come across any permission related issues on cache and logs
HTTPDUSER=$(ps axo user,comm | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1)
sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:$(whoami):rwX var
sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:$(whoami):rwX var
I've just played around with it a bit and noticed that every time you call
bin/console cache:clear --env=prod
The user of the folder /prod will be changed to the user that is executing the call. The scripts deletes the folder and creates a new own, but that will be done be the current user set.
You can stop the script from creating a new folder by using the --no-warmup option. With that, I've fixed my problem.
bin/console cache:clear --env=prod --no-warmup
For that to work you need to fix the current situation once, at best by deleting all folders and files within the /var/cache directory.
I've been trying to install Symfony3 into Ubuntu 14.04 running in virtualbox and have been following this tutorial:
http://symfony.com/doc/current/setup.html
So far I can get the Symfony command installed. I try running the Symfony command to create an application under the /var/www/html/ folder - my Apache web directory - and the following error is thrown :
I want to set up my application in this folder as this is a shared folder to a Windows 10 host. I can install Symfony under my home directory and can access this from the host browser.
Personally I think it's a permissions issue. I did find this this page for help and did not get much success. Can someone enlighten me as to what's going on?
Did you run this command already:
HTTPDUSER=`ps axo user,comm | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1`
sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX var
sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX var
Run it under the /var/www/html/symfony_test directory and tell us the results.
You have no write permissions because /var/www folders are writable by apache user. In some case (often linux) apache user is wwwdata. In MacOs the user is _www.
You can also try with some trick. First one, is to avoid apache for your development: just install symfony in you ~/Development folder, and run ./bin/console server:run command. Symfony allow you to run the php builtin server.
I'm new to Symfony2 and I'm trying to create a new project in my local environment following the steps listed in the Symfony book:
Download
$ curl -s http://getcomposer.org/installer | php
$ php composer.phar install
Create Project (path relative to /var/www/)
$ php composer.phar create-project symfony/framework-standard-edition grupo76/final/ Symfony 2.5.*
1st Problem: I have to add /web/ to paths
So, now I have to test the configuration by hitting
http://localhost/grupo_76/final/config.php
I get a 404, and have to change the address to
http://localhost/grupo_76/final/web/config.php
It complains about permissions on /app/logs and /app/cache but that's ok. I ran
HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1`
sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache app/logs
sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache app/logs
2nd Problem: app_dev.php is completely broken
Then, the book suggest I should hit
http://localhost/grupo_76/final/app_dev.php
but, again, I need to add /web/
http://localhost/grupo_76/final/web/app_dev.php
The page renders, but full of errors like this No route found for "GET /"
Please, see attachment.
I'm running:
Apache2
PHP 5.5.9-1ubuntu4
Ubuntu 14.04
1st Problem
You have to configure a web server. There is an official documentation for configuring web server for both Apache and Nginx. What you are doing is accessing app_dev.php or config.php from your localhost host relatively. See: http://symfony.com/doc/current/cookbook/configuration/web_server_configuration.html
2nd Problem
You have to define routing for your / path (homepage, in other words). See: http://symfony.com/doc/current/book/routing.html
A virtual-host won't help you, I already tried that, my working solution is:
1- Delete the old Symfony installation
2- Install a fresh one as root (sudo su)
3- Grant permissions to /var/www/html with chmod 777 -R /var/www/html"
Just take in count that you may want to readjust the folder's permissions when you get it working, to your specific scenario.
first I took you to excuse my English.
I made a website with Symfony which works fine locally. (dev and prod).
But as soon as I put online the dev version works but the prod version displays a blank page.
Lighttpd does not give me error.
PHP does not give me error.
Cache and log are writable.
I do not understand anything.
OK, this is highly undesirable situation as you need to squash bugs one-by-one. It could be as benign as missing php module or some major httpd misconfiguraion.
Some steps that should shed some light on the issue:
Fire up the Terminal (you do have ssh access, right?)
Check logs (both httpd and symfony)
httpd log:
tail -f /var/log/httpd/error_log
... and refresh your page
Symfony
tail -f /path-to-your-symfony-app/app/logs/prod.log
... again, refresh your page
In your comment, you said you encountered HTTP500 error. Is that Apache's or Symfony's HTTP500?
If you do not hape ssh access upload your app_dev.php and run it directly. Be sure to add your IP address to list of allowed (within the file)
Change your permission on cache and log folders in 777.
chmod 777 cache/ log/ -R
php symfony cc
As the documentation says:
Instead of the Welcome Page, you may see a blank page or an error page. This is caused by a directory permission misconfiguration. There are several possible solutions depending on your operating system. All of them are explained in the Setting up Permissions section.
And then you should follow these steps:
rm -rf app/cache/*
rm -rf app/logs/*
HTTPDUSER=' ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1'
sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:'whoami':rwX app/cache app/logs
sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:'whoami':rwX app/cache app/logs
I did the deployment as guided in this official docs
In my case the update of symfony before deploying was not BC with an old Bundle, so the clear:cache --env=prod was giving some error. So what I did was to manually delete the prod cache and then clear:cache with the prod environment and it worked: so to resume:
#rm -rf app/cache/prod/* #removes only production cache
rm -rf app/cache/ #removes prod and any other stage cache
php app/console cache:clear --env=prod