Symfony2 routing not working in production environment - symfony

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

Related

Gatsby / WooCommerce not processing mediaItems

I'm having major problems trying to build a Gatsby / WooCommerce site - whenever wp-graphql-woocommerce is activated it simply will not process any media items, with this error:
--
gatsby-source-wordpress Error category: undefined
Error:
Internal server error
Debug message:
in_array(): Argument #2 ($haystack) must be of type array, string given
Error path: mediaItems
info gatsby-source-wordpress GraphQL vars: {"first":100,"url":"http://178.62.90.26/graphql","in":["13"],"after":null}
--
Steps to reproduce:
I have created a completely fresh install of Wordpress (v6+) on a php8+ environment (Digital Ocean Wordpress 1 click install image)
https://marketplace.digitalocean.com/apps/wordpress
I open the console and finish the wordpress installation process
Next I install wp-graphql (latest master version) and run composer install in the directory, then activate the plugin
Next I install WooCommerce, run through the installation process and create a dummy product
Then I install WP-Gatsby (v2.3.3) and activate.
Next I install the latest version of wp-graphql-woocommerce (v12 master), upload the plugin and activate
I then change the permalink structure and check that the /graphql route is working - everything is fine
At this point I have a single dummy product, a single Hello World post with a featured image attached, and I have only the following plugins installed on the site:
WooCommerce (v7.2.2)
WP Gatsby (v2.3.3)
WP GraphQL (v1.13.7)
WPGraphQL WooCommerce (WooGraphQL) (v0.12.0)
I then clone this simple blog repo:
https://github.com/gatsbyjs/gatsby-starter-wordpress-blog.git
I run yarn install for dependencies.
I change my gatsby-config to point toward my server and add an option in gatsby-source-wordpress to ignore ShippingMethod (or else it takes forever to build), and add some debugging in to help define the issue:
--
resolve: 'gatsby-source-wordpress',
options: {
url: process.env.WPGRAPHQL_URL || 'http://178.62.90.26/graphql',
type: {
ShippingMethod: {
exclude: true
},
},
debug: {
graphql: {
showQueryVarsOnError: true,
showQueryOnError: true,
onlyReportCriticalErrors: false,
},
},
},
--
I then add define( 'GRAPHQL_DEBUG', true ); to my wp-config.php and restart Apache just to be sure
I then run gatsby develop and get the error I mentioned earlier when it gets to MediaItems:
--
gatsby-source-wordpress Error category: undefined
Error:
Internal server error
Debug message:
in_array(): Argument #2 ($haystack) must be of type array, string given
Error path: mediaItems
info gatsby-source-wordpress GraphQL vars: {"first":100,"url":"http://178.62.90.26/graphql","in":["13"],"after":null}
--
And it creates 0 MediaItem nodes:
no MediaItems processed
And in my debug.log it’s just this over and over again:
--
[05-Jan-2023 10:21:40 UTC] PHP Deprecated: Function WPGraphQL\Connection\TermObjects::get_connection_args is <strong>deprecated</strong> since version 1.13.0! Use \WPGraphQL\Type\Connection\TermObjects::get_connection_args instead. in /var/www/html/wp-includes/functions.php on line 5379
[05-Jan-2023 10:21:40 UTC] PHP Deprecated: Function WPGraphQL\Connection\Comments::get_connection_config is <strong>deprecated</strong> since version 1.13.0! Use \WPGraphQL\Type\Connection\Comments::get_connection_config instead. in /var/www/html/wp-includes/functions.php on line 5379
--
If I deactivate wp-graphql-woocommerce the image is processed absolutely fine and creates the one mediaItem node that I have:
MediaItems processed with wp-graphql-woocommerce disabled
I need the woocommerce aspect of things though so this isn’t a solution. It just seems to happen whenever wp-graphql-woocommerce is activated.
Any help with this would be hugely, hugely appreciated as I’ve been banging my head against a brick wall for a while now and I'm really starting to worry that this isn't going to work
I have tried the following versions of wp-graphql / wp-graphql-woocommerce
wp-graphql - v1.12.2, v1.12.3, v1.13.0, v1.13.4, v1.13.7
wp-graphql-woocommerce - v12, v11.2, v10.7
Node Versions - v16.11.1, v18.12.1
I've tried with both Digital Ocean and AWS Lightsail servers - same outcome
And it just never seems to process the mediaItems. The strangest thing is that this did work in September, however lately it just flatly refuses to process the images whilst wp-graphql-woocommerce is activated

login failure in prodcution mode

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 !

Sudden syntax error after deployment

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.

Deploying symfony to Heroku, get swiftmailer parameters via configvars

I have deployed my symfony app to Heroku, but I want to configure the swiftmailer component with config_vars provided by Heroku. I already have two of them:
SYMFONY_ENV: prod
CLEARDB_DATABASE_URL: my-connection-string
Now what I would like to do is to decribe swiftmailer credentials in the config_prod.yml:
#config_prod.yml
swiftmailer:
transport: "%env(mail_transport)%"
host: "%env(mail_host)%"
username: "%env(mail_user)%"
password: "%env(mail_password)%"
spool: { type: memory }
I, then, set up the config_vars on Heroku, however when trying to deploy the app I got the following exception.
[Symfony\Component\DependencyInjection\Exception\EnvParameterException]
Incompatible use of dynamic environment variables "mail_transport" found in parameters.
[Symfony\Component\DependencyInjection\Exception\InvalidArgumentException]
Unable to replace alias "swiftmailer.mailer.default.transport.real" with actual definition "%env(mail_transport)%".
[Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException]
You have requested a non-existent service "%env(mail_transport)%".
Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the symfony-scripts event terminated with an exception
If I hardcode the parameters in the config.yml then deploying to Heroku succeeds.
What am I messing up? Thx in advance.
I do not know much about heroku but i know how to get ENV_VAR inside symfony config ;)
inside app/config where your other configs files reside create a new file called parameters.php
<?php
if(isset($_SERVER['AWS_MAILER_HOST']) ){
$container->setParameter('mailer_transport', #$_SERVER['AWS_MAILER_TRANSPORT']);
$container->setParameter('mailer_host', #$_SERVER['AWS_MAILER_HOST']);
$container->setParameter('mailer_username', #$_SERVER['AWS_MAILER_USERNAME']);
$container->setParameter('mailer_password', #$_SERVER['AWS_MAILER_PASSWORD']);
$container->setParameter('mailer_port', #$_SERVER['AWS_MAILER_PORT']);
$container->setParameter('mailer_encryption', #$_SERVER['AWS_MAILER_ENCRYPTION']);
$container->setParameter('mailer_auth_mode', #$_SERVER['AWS_MAILER_AUTH_MODE']);
}
replace all 'AWS_MAILER_...' with your ENVIRONEMENT_VAR
Inside your app/config/config.yml put
imports:
- { resource: parameters.yml }
- { resource: parameters.php } <------------

Symfony2 Automatically HTTP Cache Clearing

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?

Resources