Trying to set up a Symfony 3.3 environment with Flex. Currently, when trying to require some packages like the following:
composer req annotations security orm template asset validator
Everything goes well, except on cache:clear I'm getting the following errors:
!! [Symfony\Component\Filesystem\Exception\IOException]
!! Failed to remove directory "/home/vagrant/Code/multi-user-gallery-blog/var/
!! cache/loca~/pools": rmdir(/home/vagrant/Code/multi-user-gallery-blog/var/ca
!! che/loca~/pools): Directory not empty.
I already tried to remove the folders manually, but those are generated automatically in the installation process, and then Symfony cannot remove them.
I'm running this on Vagrant Homestead.
Any idea on how can I solve this problem?
This is an issue with the way Vagrant/VirtualBox maps shared folders between the host and guest machines. In Symfony projects, the cache directory is typically placed within the project directory that gets synced from the host machine.
We can change the cache directory to use a location within the guest machine's filesystem to avoid these problems by adding an override method to the app/AppKernel.php class:
class AppKernel extends Kernel
{
...
public function getCacheDir()
{
if ($this->environment === 'local') {
return '/tmp/symfony/cache';
}
return parent::getCacheDir();
}
}
The example above demonstrates how we can set a custom cache directory for local development environments while retaining the default behavior for production. /tmp/symfony/cache is just an example. We can choose a location anywhere on the guest machine's filesystem that the application has permission to write to. Replace 'local' with the name of the environment the project uses for development.
See my comment to the accepted answer, here is the code:
public function getCacheDir()
{
if (in_array($this->environment, ['dev', 'test'])) {
return '/tmp/cache/' . $this->environment;
}
return parent::getCacheDir();
}
public function getLogDir()
{
if (in_array($this->environment, ['dev', 'test'])) {
return '/var/log/symfony/logs';
}
return parent::getLogDir();
}
Related
I recently started building an application, locally, using CakePHP 4.X. I installed Composer and successfully installed the CakePHP Authentication and Authorization plugins using it. Now, I'm trying to move on to some community-developed plugins such as
https://github.com/FriendsOfCake/bootstrap-ui
https://github.com/gutocf/page-title
https://github.com/dereuromark/cakephp-feedback
I'm able to install all of the plugins okay but the issue arises when I try to load the plugins. Per the instructions on each of the plugin Git pages, I try to load the plugin from my CLI using the line
bin\cake plugin load BootstrapUI
(I'm on Windows hence the backslash)
I am returned the following message in all cases:
Your Application class does not have a bootstrap() method. Please add one.
My src/Application.php file looks like this
class Application extends BaseApplication
public function bootstrap() : void
{
// Call the parent to `require_once` config/bootstrap.php
parent::bootstrap();
if (PHP_SAPI === 'cli') {
$this->bootstrapCli();
} else {
FactoryLocator::add(
'Table',
(new TableLocator())->allowFallbackClass(false)
);
}
/*
* Only try to load DebugKit in development mode
* Debug Kit should not be installed on a production system
*/
if (Configure::read('debug')) {
$this->addPlugin('DebugKit');
}
// Load more plugins here
$this->addPlugin('Authorization');
$this->addPlugin('Authentication');
$this->addPlugin('BootstrapUI');
}
Your Application class is missing an { after class Application extends BaseApplication but I guess it was pasted/edited incorrectly here.
Your command seems to work because I see the plugin $this->addPlugin('BootstrapUI') already added in the file.
Make sure to be on the correct path (in the root of your app) when you execute the CLI command:
bin\cake plugin load BootstrapUI
You can manually add the plugins in the bootstrap() method without CLI.
I'm using Homestead for symfony 4 application.
Everthings work with symfony web server but,
homestead not recognized controller changes.
For example:
I create /test route in TestController but homestead
No route found for "GET /test"
I run cache:clear and remove var directory but nothing changed.
I'm using arch linux and homestead/virtualbox.
Can anyone give me a help about that?
Thanks,
I use a custom vagrant script to build my VM but I have had this issue a few times - this is how I solved it:
src/Kernel.php
public function getCacheDir ()
{
//return $this->getProjectDir().'/var/cache/'.$this->environment;
return '/var/tmp/cache/' . $this->environment;
}
public function getLogDir ()
{
//return $this->getProjectDir() . '/var/log';
return '/var/tmp/log';
}
Also read https://symfony.com/doc/current/configuration/override_dir_structure.html#override-cache-dir
I fixed my problem.
I recreated homestead box and left only one site in homestead.yaml file.
sites:
- map: sf18.app
to: /home/vagrant/code/sf18/public
type: symfony4
I believe it's related homestead.yaml and homestead-17 box.
i have a problem hosting a symfony2 app on azure. It am always getting an "Failed to write cache file" error in Filesystem.php. I guess that php does not not have the permission to write to the cache folder. How can i give php the permisson to
modify the cache, without webdeploy or git, i only have ftp and the azure management portal.
KR Manuel
You have to set the correct directories for logs and cache in your Kernel.
And you can usually set permissions for that folder using your FTP client.
public function getCacheDir()
{
if ($this->getEnvironment() == 'prod') {
return 'D:\\home\\data\\cache\\prod';
}
return parent::getCacheDir();
}
public function getLogDir()
{
if ($this->getEnvironment() == 'prod') {
return 'D:\\home\\LogFiles\\app\\';
}
return parent::getLogDir();
}
there is also a pre-made bundle to take care of these things:
https://github.com/brainsonic/AzureDistributionBundle
and even a detailed tutorial:
http://symfony.com/doc/current/cookbook/deployment/azure-website.html
I've registered a custom Artisan command:
Artisan::add(new MigrateAll);
The class resides in app/commands (default location)
However when I run Behat I get the error:
Class 'MigrateAll' not found
Artisan is called in Behat for setting up the DB:
/**
* #static
* #beforeSuite
*/
public static function setUpDb()
{
Artisan::call('migrate:install');
//...
}
Do I need to give it a namespace? (I could not find the correct way to call the Artisan::add command with a namespaced class)
This is somewhat related to your earlier question. Your Behat test suite runs in a separate process independently of your app and knows nothing about the configuration. This also applies to the autoloading in your bootstrap and the autoloading would be the most likely reason why classes don't get found. This should be easily fixed by using Composer to autoload your own sources and vendor packages (both in your app and in your test suite).
# composer.json
{
"require": {
"…": "…"
},
"autoload": {
"psr-0": {
"": "../src"
}
}
}
// Include composer's autoloader in your `setUp()` / bootstrap / index.php.
include __DIR__ . '../vendor/autoload.php';
Take that process separation as a rule and keep in mind that Laravel like any other framework requires a whole bunch of other configuration. Since you are trying to use the database component, your next issue will be with that, because it won't be configured in your test suite.
The best approach is to create separate bootstrap file for Behat, which would inherit most lines from your normal bootstrap, where you need to pass the necessary configuration and do this:
/**
* #static
* #beforeSuite
*/
public static function setUp()
{
include_once('bootstrap.php');
}
If you configured your behat environment with this tut (Laravel, BDD And You: Let’s Get Started), after you added a new command, you need to $ composer dump-autoload to make behat to know the command.
I have encountered this error
Fatal error: Class 'PHPExcel_Shared_ZipStreamWrapper' not found in \VBOXSVR\ACACIASOFT\apc\spreadsheet\lib\phpexcel\PHPExcel\Autoloader.php on line 29
My currrent setup is :
Host Machine : Windows 7
: this is where i check out my solution from svn
Virtual Box Guest Machine :
: Windows XP
: where my apache, php, mysql installed.
: I have also added the shared directory on my virtual box so that i will use this as the documentroot location
My dilemma started when i change the documentroot. it bring error on my phpexcel modules but when i changed back the documentroot c:/program files/apache.... copy the project to this directory. this will not bring any error.
The same problem has been nagging me to death for a whole day.
I found out that if you have your own autoloader function previously registered with spl, then you'll have to return false in the event your autoloader fails to load the required class, like this:
spl_autoload_register('my_autoload');
function my_autoload($className)
{
if(file_exists(CLASS_PREFIX.".$className.php"))
{
require_once(CLASS_PREFIX.".$className.php");
}
else
{
return false;
}
}
Looks like you're running some other library with its own autoloader that interferes with the PHPExcel autoloader. The latest SVN code has been modified to prevent this problem.
In the /Classes/PHPExcel/Autoloader.php script itself, change:
public static function Register() {
return spl_autoload_register(array('PHPExcel_Autoloader', 'Load'));
} // function Register()
to
public static function Register() {
if (function_exists('__autoload')) {
// Register any existing autoloader function with SPL, so we don't get any clashes
spl_autoload_register('__autoload');
}
// Register ourselves with SPL
return spl_autoload_register(array('PHPExcel_Autoloader', 'Load'));
} // function Register()
If anyone happens to be on Linux, then this error can be caused by incorrect usage rights.
I had this same issue, but I changed the owner of the 'Shared' folder, and set it to be 'www-data' user, which is the apache user on my system (chown www-data:www-data Shared). This fixed the "Class 'PHPExcel_Shared_ZipStreamWrapper' not found" error.
Yet this is not the full fix, What you really need to do is make sure the folders and files in the PHPExcel folder are assigned to the correct user, and that they have the correct rights. Here is how you do it:
You need to assign the PHPExcel folder and every item in it to the www-data user so Apache can access the files. Make sure you are one level below your PHPExcel folder and then run this command:
sudo chown -R www-data:www-data PHPExcel
And that is that it. Apache should be able to access all the files and the error should be resolved.
You must enable on php extension the zip dll
Ok I know it's already a year ago, but since this problem occured to my setup (Virtual Machine running Windows 7 Professional in an Active Directory network with explicit user rights) just a few days ago i wanted to share my solution, maybe this will help others to save some time:
I figured out 2 problems (only on WINDOWS HOSTS!):
the PHPEXCEL_ROOT-Constant is defined with wrong directory seperators
MY SOLUTION: change the php code to use the DIRECTORY_SEPARATOR constant in the defitinions
in the file: PHPExcel.php (around Line 32) like this:
//OLD: define('PHPEXCEL_ROOT', dirname(__FILE__) . '/');
define('PHPEXCEL_ROOT', dirname(__FILE__) . DIRECTORY_SEPARATOR);
there are 2 more files to change: "IOFactory.php" and "Settings.php" (Line 34) to:
//OLD: define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../');
define('PHPEXCEL_ROOT', dirname(__FILE__) . DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR);
the PHP function "is_readable" does not always return correct results on Windows hosts, in my case the file was readable but the result was false.
MY WORKAROUND: To work around this Bug, you can remove the "is_readable" check in the file "autoload.php" change line 77 to:
// if ((file_exists($pClassFilePath) === FALSE) || (is_readable($pClassFilePath) === FALSE)) {
if (file_exists($pClassFilePath) === FALSE) {