Symfony cache:clear Failed to remove directory - php

I am unable to successfully run cache clear on my Symfony application. I have set the permissions to the /var/cache directory as 777. But still get this error:
[Symfony\Component\Filesystem\Exception\IOException] Failed to
remove directory "/vagrant/app/var/cache/de~/pools": .
Does anyone know what I am doing wrong here?
This was working before whilst I was using the file sharing type: nfs.

Are you sure you changed the permissions on the cachefolder recursively, and not just one the cache folder itself, (also, try chmod'ing from the host instead of the guest)
EDIT:
if PURELY FOR DEVELOPMENT, setup your vagrant shared folder like so:
config.vm.synced_folder "/home/git/-something-", "/var/www/-something-/public_html", owner: "-something-", group: "nginx", mount_options: ["dmode=777,fmode=777"]

Updated my VM to run the latest version (1.9.5) of vagrant. Was then able to use nfs, see:
config.vm.synced_folder "./", "/vagrant", type: "nfs"

Related

Deploy Laravel 6 App on Google App Engine Standard Error: Please provide a valid cache path

I've been trying to deploy my Laravel 6 App to the standard environment of Google App Engine the whole day, but seems like I'm just stuck at how to make cache and some "local" files to work.
This is the error I get when I try to load any page:
(1/1) InvalidArgumentException
Please provide a valid cache path.
in Compiler.php line 36
at Compiler->__construct(object(Filesystem), false)
in ViewServiceProvider.php line 92
at ViewServiceProvider->Illuminate\View\{closure}(object(Application), array())
in Container.php line 799
at Container->build(object(Closure))
in Container.php line 681
at Container->resolve('blade.compiler', array(), true)
in Application.php line 785
(...)
I followed every tip at this question, this tutorial and this issue, but anything seemed to help me.
As CACHE_DRIVER, for convenience, I'm trying to just use file, instead of database or any other else. So, my app.yaml, have the additional env_variables :
CACHE_DRIVER: file
SESSION_DRIVER: cookie
APP_STORAGE: /tmp
VIEW_COMPILED_PATH: /tmp
APP_SERVICES_CACHE: /tmp/services.php
APP_PACKAGES_CACHE: /tmp/packages.php
APP_CONFIG_CACHE: /tmp/config.php
APP_ROUTES_CACHE: /tmp/routes.php
I know that the /tmp folder is the only writable folder for the App Engine Standard Environment. With that in mind, I put the above at app.yaml, and even tried renaming /storage folder to /tmp.
I've added the following line to my bootstrap/app.php file:
$app->useStoragePath(env('APP_STORAGE', base_path() . '/tmp'));
At my composer packages, I made sure that it doesn't have facade/ignition. Also, as I can't run any command after deploy my app to Google App Engine, at composer.json I have:
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump"
],
"post-install-cmd": [
"composer dump-autoload",
"php artisan config:clear",
"php artisan view:clear",
"php artisan cache:clear"
]
I also tried to put at post-install-cmd php artisan storage:link, while using $app->useStoragePath(env('APP_STORAGE', base_path() . '/storage')); and the /storage folder as storage itself, but nothing worked.
I have the whole folder tree for caching at my /temp (or /storage, if this is the right way) folder:
/tmp
/framework
/cache
/data
/sessions
/testing
/views
/logs
/medialibrary
/temp
Also, besides the views not rendering, I noticed that when trying to load the favicon.ico, located at /public folder, it returns an 500 error. I am new to AppEngine, but even reading everything I can find I've been struggling to make it work. I really appreciate any help.
I figured out I had some config files published at /config, and besides changing /bootstrap/app.php, some of them had their own path to /storage folder. So, my solution was just gave up on using files cache, and for the views cache, and some other packages I had, use the path /tmp, at their respective config files. Also, I removed all cache cleaning artisan commands from composer, as I wasn't sending any cache files to deploy.
Also, I needed to make some changes in order to be able to access /public files, like some local css and js. For this, I followed these docs.
I was struggling with the same problem today and the solution was I changed the 'compiled' value in config/view.php to a root folder:
Go to root directory.
mkdir compiled_views
Change 'compiled' value to 'compiled' => realpath(base_path('compiled_views/')),
I solved it by explicitly adding the APP_STORAGE env in config/view.php:
'compiled' => realpath(env('APP_STORAGE', realpath(storage_path('framework/views')))),
(which surprises because I do have $app->useStoragePath(env('APP_STORAGE', base_path() . '/storage')); added to app.php - but it seems that it didn't yet(?) override storage_path )

AWS Elastic Beanstalk Deployment Order

I'm deploying code to a single-instance web server AWS EB environment that will provision/update my connected RDS database. I've got an .ebextensions file that calls deployment code:
---
container_commands:
01deploydb:
command: /var/www/html/php/cli/deploy-db.php
leader_only: true
On the same deployment, I dropped the deploy-db.php file back one directory into /cli/. On deployment, I get ERROR: [Instance: i-*****] Command failed on instance. Return code: 127 Output: /bin/sh: /var/www/html/php/cli/deploy-db.php: No such file or directory.
container_command 01deploydb in .ebextensions/01_db.config failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.
If I deploy a version that does not include the command, then deploy a second update including the command, there is no error. However, adding the command and the file it calls at the same time produces the error. A similar sequence occurred earlier with a different command/file.
My question is: is there a documented order/sequence for how AWS updates the environment? I would have expected that my new version would have fully deployed (and the .php file installed) before container_commands are called.
The commands: section runs before the project files are put in place. This is where you can install server packages for example.
The container_commands: section runs in a staging directory before the files are put in its final destination. Here you can modify your files if you need to. Current path is this staging directory so you can run it like this (I might get the app directory wrong, maybe it should be php/cli/deploy-db.php)
container_commands:
01deploydb:
command: cli/deploy-db.php
leader_only: true
Reference for above: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html
You can also run a post deploy scripts. This is not very well documented (at least it wasn't). You can do something like this (it won't be leader only though, but you could put a file in this directory through a container_commands:):
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/99_deploy.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
/var/www/html/php/cli/deploy-db.php

symfony2 assets targets the /www server folder, not the /web symfony folder when deploy in production

I have some problems with Symfony 2 application deployment. I have import all files I need on my OVH shared server, but some errors occured like css and js files not found (internal server error for example) or error like Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://my-server/css/458dafd_bootstrap-theme.min_1.css".
Notice that I have installed the CoresphereBundle in order to have a console in my browser when my application is iploaded on my server, I have access to the console only on dev environment.
This is step by step what I did in order to deploy my application:
1 I updated my application and vendors with composer (because I have no ways to install composer on my server)
composer.phar update
2 I clear the dev cache php app/console cache:clear
3 I clear the prod cache php app/console cache:clear --env=prod --no-debug
4 I install assets php app/console assets:install web
5 I dump the assets php app/console assetic:dump web
6 I uploaded my symfony application on my server.
7 Once the files are uploaded in web/app.php I I authorize
the prod debug
$kernel = new AppKernel('prod', true);
8 Then in web/config.php I remove this block
// …
if (!in_array(#$_SERVER['REMOTE_ADDR'], array(
'127.0.0.1',
'::1',
))) {
header('HTTP/1.0 403 Forbidden');
exit('This script is only accessible from localhost.');
}
So, on my server, if I would like to go to http://my-server/web/config.php it works well, so I see if my server is compatible with symfony. the only thing that appears is Set short_open_tag to off in php.ini*.
9 I set the access rights for the app/cache and app/log folders to 777 on my server, it allows the applications to write in these folders.
10 In web/app_dev.php I write this code, in order to allow the dev mode for my IP adress and so have access to the console bundle
// …
if (!in_array(#$_SERVER['REMOTE_ADDR'], array(
'127.0.0.1',
'::1',
'121.457.719.2' //a random ip adress it's just for you to understand
))) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
11 So I have access to the dev environment on my server, all works well, and no errors occured here. To access to the console bundle, following to the bundle documentation, I have to wrote http://my-server/web/app_dev.php/_console (see the routing code here):
_console:
resource: "#CoreSphereConsoleBundle/Resources/config/routing.yml"
prefix: /_console
But this routes does not exist, If I wrote this url, nothing appear in my browser:
However, by the config.php, I have access to app_dev.php by following the Bypass configuration and go to the Welcome page link:
I click on the link and I arrived on app_dev.php. Like I said before, no errors occured in this environment, except for the console route. But I could have access to the console by clicking on the console logo under the symfony debug toolbar:
This is the url for the console when I click on the logo under symfony debug toolbar: http://my-server/web/app_dev.php//_console/_console, I would like to understand why?
Then when I would like to make some commands another error occured: [error] Internal Server Error in the console:
If I try to use the router debug php app/console debug:router, I have this:
and with the php app/console debug:router | grep _console:
So, there are the problems I have with my symfony application.
UPDATE
I resolved the problem of the console bundle. In fact my server does not use the same php version of my symfony application, I have to set this in the .ovhconfig at the root of my /www folder.
/www/.ovhconfig:
app.engine=php
app.engine.version=5.5
http.firewall=none
environment=production
Now when I would like to access to the production environment I have these errors concerning all my assets files (css/js/images, a 404 not found):
Failed to load resource: the server responded with a status of 404 (Not Found) -> http://my-server.com/bundles/fosjsrouting/js/router.js
Uncaught ReferenceError: fos is not defined -> routing:1
Failed to load resource: the server responded with a status of 404 (Not Found)
->http://my-server.com/css/45898d_dataTables.min_7.css
I don't really understand, the files are indeed at the root of the app, e-g I have no folder css or js or etc in http://my-server.com/. These folders are in http://my-server.com/web/. Where is the problem?
When I access to the console, this is the command I made:
1 cache:clear
2 assets:install web
3 assetic:dump web
EDIT: solution works
I understand that the assets target a /css /js /images etc folder at the root of my server, so I replace the css and js files to the root of the /www server folder, e-g in the /www folder of my server I have this:
//my server
/.ssh
/www /*http://my-server.com/...*/
/app/
/bin/
/css/
/fonts/
/images/
/js/
/src/
/vendor/
/web/
/.htaccess
/.ovhconfig
/composer.json
/composer.lock
/composer.phar
Why my symfony application tagets the assets here?
Have you tried to use the Symfony command line routing debugger?
php app/console debug:router
That will output all the routes the symfony app knows about and you could try piping it into grep to see if you're trying to use the wrong path to hit the _console route.
php app/console debug:router | grep _console

Twig is unable create cache directory

This is the error
RuntimeException: Unable to create the cache directory (1/25/20).
1- Changing the cache directory in the appKernel file didn't fix the problem
/*
public function getCacheDir()
{
return '/mnt/symfony_ram_cache/cache/'.$this->environment;
}
*/
2- Setting the permissions to "chmod 777 -R cache" didn't work, still throws the error
3- App works when I deactivate the twig cache (I obviously need it in production)
#Twig Configuration
twig:
cache: false
4- It DOES create several folders in cache (in both prod and dev) when I empty the cache directoy and reload, so what means the rights are actually set properly
5- Here is a screenshot of the error
6- PS: Updated to symfony 2.5.6 the twig bundle was updated but still have no luck
Maybe you should chown cache directory to user who fires up application (www-data?)?
Edit your
app/config/config.yml
And change this:
From:
twig:
cache: "%kernel.debug%"
To:
twig:
cache: "%kernel.cache_dir%/twig"
I don't know what was wrong, I installed symfony2 from scratch again and now it works.

phabricator on redhat's openshift

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.

Categories