Hi All
Recently we migrated to symfony2 application. Now I am having a problem with storage on the systems. The system is running on the docker container. It looks like application is not deleting the http_cache automatically. After searching in the internet found few following solutions. But not sure about the actual problem.
Solution 1
// app/AppCache.php
use Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache;
class AppCache extends HttpCache
{
protected function getOptions()
{
return array(
'default_ttl' => 500,
// ...
);
}
}
This looks like a solution, but not really able to test it on local system.
Solution 2
Periodically run following command via cron job or similar to clear the cache.
php app/console cache:clear --env=prod
Hints
I am getting following error on the server, but it is not too often. I am not sure if it is the real issue that is causing system to crash.
[xx-xxx-xxxx xx:xx:xx] WARNING: [pool www] child 2452 said into stderr: "NOTICE: PHP message: PHP Notice: SessionHandler::gc(): ps_files_cleanup_dir: opendir(/var/lib/php/sessions) failed: Permission denied (13) in /var/www/vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/Session/Storage/Proxy/SessionHandlerProxy.php on line 93"
Server Setup
The application is running on docker container.
Any help or hint would be great,am I missing anything?
Related
I am using symfony 5.4.4.
I encounter a problem when I try to connect a user without launching the php server (I want to work in production mode).
I used make:user commands to create the User entity. Then I used the make:auth and make:registration-form commands to generate the login and registration forms.
everything works perfectly when I run the symfony server with the symfony serve command. On localhost:8000 I am able to register and login users with no problem.
I then followed the symfony documentation on deployment as I want my application to run in a server accessible from a private network. I then ran the commands:
composer require symfony/requirements-checker to check
composer install --no-dev --optimize-autoloader
Then I updated the .env file
APP_ENV=prod
APP_DEBUG=0
before clearing the cache with: php bin/console cache:clear
And finally I added rewrite rules with the command: composer require symfony/apache-pack.
now I access my application from any computer (example: http://localhost/myproject/public/user/4) in the network and I navigate without problems on the links.
However, when I try to login a user, it doesn't work.
And when I try to enter one, it works.
In summary, the login works on localhost:8000 but does not work on localhost/myproject/public while all other forms work.
Can you help me ? thank you in advance.
It's OK !
I added the method below into my App/src/Authenticator.php class
Notice : it does not work without the return type "bool" of the function
public function supports(Request $request): bool
{
return self::LOGIN_ROUTE === $request->attributes->get('_route')
&& $request->isMethod('POST');
}
I hope it will be useful to someone!
Thanks to all and especially to Cerad for the link !
I have an incomprehensible problem.
I have used this bundle many times, and I understand the main logic to generate a pdf from a twig view.
But on my two last project i have this kind of error:
Error: Failed to load https://mydomain/bundles/bundle/css/bootstrap.css, with network status code 1 and http status code 0 - Connection refused
Exit with code 1 due to network error: ConnectionRefusedError
I have tried:
HTTP and HTTPS url
chmod 777 on var/cache folder - try acl
disable all parameters of wkhtml
update wkhtml
Disable extends twig view - ihave made a new file with full HTML
Clean controller use assets
filter / absolute_url filter / or web_url variable to prefix assets
On my development environment (Windows), i didn't have any problem.
This problem appeared when I work on production environment, based on Debian 9 with nginx, php 5.6, mariadb 10.0* and letsencrypt certificate.
I can't load any assets for now.
Does anyone have an idea??
Ok i have found a workaround. I use this trick :
create a global variable with this path :
pdf_url: '%kernel.root_dir%/../web'
then i call my assets like this :
<link href="{{ pdf_url}}/bundles/css/bootstrap.css" rel="stylesheet">
Its a not the ebst solution, but its works.
I have a working symfony project. I have it on a private bitbucked repository and locally the website works without an issue.
Today I tried to deploy the project onto an external server linuxpl.com.
Steps taken include:
Istalling composer
Adding the mysql database
Running git clone to get the data into a proper location
Running composer install on the folder to install everything and connect to the db
Cleared the cache
Set the project root as ....domain/project_name/web
However after completing all these steps, when running the website with regular server:run I'm getting this odd error:
Parse error: syntax error, unexpected '.' in /home/spirifer/domains/surowcewobiektywie.pl/konkurs/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1571
Not sure if this is of any importance but the mentioned code partion looks like this in my local files:
// Some objects throw exceptions when they have __call, and the method we try
// to call is not supported. If ignoreStrictCheck is true, we should return null.
try {
$ret = $object->$method(...$arguments);
} catch (BadMethodCallException $e) {
if ($call && ($ignoreStrictCheck || !$env->isStrictVariables())) {
return;
}
throw $e;
}
The local version does not differ from the one on the server.
My local machine has PHP 7.0.9 and the remove server has PHP 7.0.14
How could I fix this issue?
PHP 5.6 adds Variadic functions, with "...". However, Twig v1.x only required the use of PHP 5.2.7 or above.
If you didn't explicitly update to Twig 2.0, it's very possible you have used the 'death star' version constraint in the composer file - '*'. which allows uncontrolled version updates to the latest version. If this is the case, you will need to either update your version of PHP, or at least require just a previous version of Twig/twig, "^1.32" would be the latest in the version 1 series of Twig.
I am trying to access a POST route which is currently working locally but doesn’t work once deployed to the production server. I've removed the name of the app and replaced with XXX in the following. I've run out of ideas and I think I've tried everything posted here.
We have a very similar POST only route which is working fine, but from a previous deployment.
I'm trying to access the route www.XXX.com/api/convert_mov
my routing.yml
XXX_api_convert:
path: /api/convert_mov
defaults: { _controller: XXXPartnerBundle:API:convert }
methods: [POST]
php app/console router:debug | grep api returns
XXX_api_convert POST ANY ANY /api/convert_mov
I have run
php app/console cache:clear --env=prod
app/logs/prod.log shows
request.ERROR: Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "No route found for "POST /api/convert_mov"" at /var/www/XXX/ppp/releases/20150903102317/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/EventListener/RouterListener.php line 144 {"exception":"[object] (Symfony\Component\HttpKernel\Exception\NotFoundHttpException(code: 0): No route found for \"POST /api/convert_mov\" at /var/www/XXX/ppp/releases/20150903102317/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/EventListener/RouterListener.php:144, Symfony\Component\Routing\Exception\ResourceNotFoundException(code: 0): at /var/www/XXX/ppp/releases/20150903102317/app/cache/prod/appProdUrlMatcher.php:738)"} []
Even after warming up the cache I can see this in appProdUrlMatcher.php
// XXX_api_convert
if ($pathinfo === '/api/convert_mov') {
if ($this->context->getMethod() != 'POST') {
$allow[] = 'POST';
goto not_XXX_api_convert;
}
return array ( '_controller' => 'XXX\\PartnerBundle\\Controller\\APIController::convertAction', '_route' => 'XXX_api_convert',);
}
not_XXX_api_convert:
}
I managed to resolve this problem with a different deploy script. The new script performed some extra tasks on the server including restarting PHP which may have been the answer.
Clearing the cache for the prod environment with debug false
Stopping php-fpm-5.5: [ OK ]
Starting php-fpm-5.5: [ OK ]
Nothing to update - your database is already in sync with the current entity metadata.
Installing assets as hard copies.
Installing assets for Symfony\Bundle\FrameworkBundle into web/bundles/framework
Installing assets for XXX\PartnerBundle into web/bundles/XXXpartner
Installing assets for Sonata\CoreBundle into web/bundles/sonatacore
Installing assets for Sonata\AdminBundle into web/bundles/sonataadmin
Installing assets for FOS\JsRoutingBundle into web/bundles/fosjsrouting
Installing assets for Sensio\Bundle\DistributionBundle into web/bundles/sensiodistribution
Running XXX:migrate
XXX:migrate - done
I'm trying to move a Symfony 2 based project to production mode on my rented CentOS VPS, however I seem to encounter an issue when visiting a certain route address which shows the following error every time.
Method "MyNamespace\MyProjectBundle\Controller\MyController::indexAction" does not exist.
500 Internal Server Error - InvalidArgumentException
If I run rm -rf app/cache/* it will load fine, then show the same error when I refresh again. It appears to work fine in development mode. From what I can see all of the permissions are fine and have verified all of the routes are working using php app/console router:debug.
Can anyone else suggest what could be causing this issue?
Check your /app/AppKernel.php
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new Acme\ProjectBundle\ProjectDemoBundle();