hosting symfony2 app on azure web app - php

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

Related

Error: "Your Application class does not have a bootstrap() method. Please add one."

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.

Laravel ``$user->can("...")`` throws server error 500

I host a SPA with a Laravel API on AWS (EC2). When you fill out this form: http://ec2-52-59-214-55.eu-central-1.compute.amazonaws.com/register (feel free to do so), the server throws an error with a response code of 500, right at the point where a $user->can("...") method is called. I developed the app localy and everything worked fine there.
Local environment:
Windows 10 / XAMPP - Apache 2.4.41
PHP 7.4.4
Laravel 7.5.2
Server environment:
Ubuntu 18.04 / Apache 2.4.29
PHP 7.4.6
Laravel 7.5.2
It uses spatie/laravel-permission for role management, which also affects the can method provided by the Laravel framework.
Here is the code causing the error:
echo "Before store<br>";
if($user->can("store files")) { echo "Inner store";
// Store avatar
if(isset($data["avatar"])) {
if(!$data["avatar"]->isValid()) {
return reponse(null, 422);
}
// Check if avatar is new
$current_avatar = $user->getAvatarAttribute();
$store_images = get_new_files([$data["avatar"]], [$current_avatar]);
if(isset($store_images[0])) {
// Create asset for avatar
$new_avatar = create_asset([
"file" => $store_images[0],
"user_id" => $user->id,
"type" => "avatar"
]);
$new_avatar->save();
}
}
}
echo "After store<br>";
And here the error which I guess means, that the script failed as soon as if($user->can("...)) got called.
Do you have any idea how to fix that?
Logging errors are fairly common, especially when configured as a daily log.
https://laravel.com/docs/7.x/logging#configuration
Specifically look at the section on "Configuring The Single and Daily Channels" as this allows the permissions of the log file to be set on creation.
Temporarily, you can change the permissions for you logs like so:
sudo chmod 644 storage/log/.

Vagrant & Symfony 3.3: Failed to remove directory

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();
}

Invalid Configuration – yii\base\InvalidConfigException The directory is not writable by the Web process?

Invalid Configuration – yii\base\InvalidConfigException
The directory is not writable by the Web process:
/home/liyunfei/NetBeansProjects/my2/duangplat/publicplat/web/assets
1. in /home/liyunfei/NetBeansProjects/my2/duangplat/vendor/yiisoft/yii2/web/AssetManager.php at line 213
204205206207208209210211212213214215216217218219220221222
* #throws InvalidConfigException if [[basePath]] is invalid
*/
public function init()
{
parent::init();
$this->basePath = Yii::getAlias($this->basePath);
if (!is_dir($this->basePath)) {
throw new InvalidConfigException("The directory does not exist: {$this->basePath}");
} elseif (!is_writable($this->basePath)) {
throw new InvalidConfigException("The directory is not writable by the Web process: {$this->basePath}");
} else {
$this->basePath = realpath($this->basePath);
}
$this->baseUrl = rtrim(Yii::getAlias($this->baseUrl), '/');
}
/**
* Returns the named asset bundle.
I know this is an old post, but in case it helps someone:
SELinux (e.g. on Centos 7) is on by default. For my purposes, I just put SELinux in permissive mode and that fixed the issue for me. That said, there is probably a best practice to allow the apache process without going to permissive mode.
I had this problem when I remove bundled assets folder from web folder.After 1 hour I found it and I created an assets folder in web and it's fixed.

CodeIgniter - Controller Double Inheritence Breaking When Deploying To Server

I really need some guidance here as this issue is pretty confusing and extremely different to understand for a beginner like myself.
I am running a WAMP server with the latest CI version.
In core/MY_Controller.php I have:
public GeneralController extend CI_Controller {
public GeneralController() {
parent::__construct();
// Does some stuff
}
}
public AuthenticatedController extend GeneralController {
public AuthenticatedController() {
parent::__construct();
if(!loggedIn()) redirect("/login");
// Does some stuff
}
}
public UnauthenticatedController extend GeneralController {
public UnauthenticatedController() {
parent::__construct();
if(loggedIn()) redirect("/home");
// Does some stuff
}
}
My login controller is:
class Login extends UnauthenticatedController {
So basically if they are logged in and load "/login" they will be routed to "/home".
This works perfectly on my local environment.
Once I upload it to my server and navigate to "/login" I get an infinite loop. After debugging I figured out that the Login controller loads AuthenticatedController instead of UnauthenticatedController so it keeps redirecting back to "/login" infinitely.
Well, now the inheritance is broken for some reason so I need to check if it calls both Auth and Unauth controllers. Nope. Just calls Auth even though it extends UnauthenticatedController.
I am at a loss here, I've tried everything I can imagine but as a new php programmer I thought I would pick some of your brains on things to try!
Thank you!
Solution:
Check your production server php version vs. local
I also had this problem with extending core classes. My problem was that is was working on my local server, but not on my production server. I was receiving the 404 error in production, and only on my controllers that used the class extensions. After some research I noticed that my local server was running php version 5.3.x, while my production server was running 5.2.x. To fix this I had to upgrade my production server to 5.3.
To find out what version of php your site is using, place this command in your view:
<?php echo phpversion() ?>

Categories