login failure in prodcution mode - symfony

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 !

Related

Hosting Symfony 4 app with EasyDeployBundle on server without /usr/local/bin/composer

For a Symfony 4 app I have chosen a Web Cloud plan from the hosting provider OVH.
For the deployment I have decided to use the EasyDeployBundle which looks very promising. This is my config file:
<?php
use EasyCorp\Bundle\EasyDeployBundle\Deployer\DefaultDeployer;
return new class extends DefaultDeployer
{
public function configure()
{
return $this->getConfigBuilder()
->server('ovh')
->deployDir('directory/path/at/server')
->repositoryUrl('git#github.com:foo/bar.git')
->repositoryBranch('master')
;
}
}
I have .ssh/config file with the following entry:
Host ovh
Hostname sshcloud.foobar.hosting.ovh.net
Port 12345
User foobar
Note: all values are dummies, just for illustrational purposes.
When I run:
php bin/console deploy --dry-run -v
everything goes fine, but when I actually try to deploy I get the following error:
The command "ssh ovh 'which /usr/local/bin/composer'" failed.
The problem is that I have no write-access to the directory /usr/local/bin/ on the server. The composer.phar is in my home directory and I can't move it to the provisioned destination.
Is there any possibility to tell EasyDeployBundle to look for composer in another directory?
I should really read the manuals, in particular when I'm linking them in my question.
There is a method remoteComposerBinaryPath that accepts custom path to composer. I have amended the method configure like this:
public function configure()
{
return $this->getConfigBuilder()
->server('ovh')
->deployDir('directory/path/at/server')
->repositoryUrl('git#github.com:foo/bar.git')
->repositoryBranch('master')
->remoteComposerBinaryPath('composer.phar')
;
}
On the server I created .bashrc in my home folder and added the line:
export PATH=$PATH:/home/foobar
and now the deployment is passing this hurdle.
I have now another problem, but at least this one is solved and maybe the answer can help other people too.

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.

berks-api will not run on ubuntu in azure - get Permission denied # rb_sysopen - /etc/chef/client.pem

As part of our chef infrastructure I'm trying to set up and configure a berks-api server. I have created an Ubuntu server in azure and i have bootstrapped it and it appears as a node in my chef-server.
I have followed the instructions at github - bekshelf-api installation to install the berks-api via a cookbook. I have run
sudo chef-client
on my node and the cookbook appears to have been run successfully.
The problem is that the berks-api doesn't appear to run. My Linux terminology isn't great so sorry if I'm making mistakes in what I say but it appears as if the berks-api service isn't able to run. If I navigate to /etc/service/berks-api and run this command
sudo berks-api
I get this error
I, [2015-07-23T11:56:37.490075 #16643] INFO -- : Cache manager starting...
I, [2015-07-23T11:56:37.491006 #16643] INFO -- : Cache Builder starting...
E, [2015-07-23T11:56:37.493137 #16643] ERROR -- : Actor crashed!
Errno::EACCES: Permission denied # rb_sysopen - /etc/chef/client.pem
/opt/berkshelf-api/v2.1.1/vendor/bundle/ruby/2.1.0/gems/ridley-4.1.2/lib/ridley/client.rb:144:in `read'
/opt/berkshelf-api/v2.1.1/vendor/bundle/ruby/2.1.0/gems/ridley-4.1.2/lib/ridley/client.rb:144:in `initialize'
If anyone could help me figure out what is going on, I'd really appreciate it. If you need to explain the setup any more let me know.
It turns out I misunderstood the configuration of the berks-api. I needed to get a new private key for my client (berkshelf) from manage.chef.io for our organization. I then needed to upload the new key (berkshelf.pem) to /etc/berkshelf/api-server and reconfigure the berks-api to use the new key. so my config for the berks-api now looks like below:
{
"home_path":"/etc/berkshelf/api-server",
"endpoints":[
{
"type":"chef_server",
"options":
{
"url":"https://api.opscode.com/organizations/my-organization",
"client_key":"/etc/berkshelf/api-server/berkshelf.pem",
"client_name":"berkshelf"
}
}
],
"build_interval":5.0
}
I couldn't upload berkshelf.pem directly to the target location, i had to upload it to my home location, then copy it from within linux.
Having done this, the service starts and works perfectly.

Method does not exist when moving Symfony 2 project to production

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

How to install mmoreramerino/GearmanBundle with Symfony 2.1.x?

I am pretty new to Symfony 2 and brand new to Gearman.
I am looking for a bundle to integrate Symfony 2 with Gearman.
mmoreramerino's bundle seems to be the most popular bundle according to packagist. Unfortunately something seems to be broken, the autoloader does not find the bundle.
Fatal error: Class 'Mmoreramerino\GearmanBundle\MmoreramerinoGearmanBundle' not found in ...
I tried switching to "dev-development" as I got from the issues that it was fixed in this branch, but it did not work for me as well.
Question: How can I install this bundle using Symfony 2.1.x?
Question 2: Are there any working & documented alternatives?
Edit In case someone else comes across this question: Here is how I got it up and running!
Install gearman, libgearman, the PECL extension for PHP (use recent versions!)
check that gearman shows up in phpinfo() (both cli and webserver version)
start gearmand in terminal 1 using "gearmand --verbose INFO" (you will see workers & clients connect to gearman - or not ;-))
start in terminal 2 reverse_worker.php from the gearman php extension example directory
start in terminal 3 reverse_client.php from the gearman php extension example directory
If this is working, you are ready for Symfony: install mmoreramerino/GearmanBundle using "dev-development"
copy dev.base.yml from the bundle to app/config/gearman/dev.yml
Now add TestWorker.php to your bundle as outlined in the documentation
enable the testWorker by using the console script "php app/console gearman:job:execute MmoreramerinoGearmanBundleWorkerstestWorker~test"
now you are able to send jobs to the listening testWorker in a Symfony controller (or somewhere else in Symfony). I had to specify the server though I am using the default host/port.
$gearman = $this->get('gearman');
$gearman->setServer('127.0.0.1',4730);
$gearman->doNormalJob('MmoreramerinoGearmanBundleWorkerstestWorker~test');
To install the bundle, you need to add the following line to composer.json
"Mmoreramerino/GearmanBundle": "dev-development"
and run composer update;
Then register it in app/AppKernel.php (it seems you have already done this)
new Mmoreramerino\GearmanBundle\MmoreramerinoGearmanBundle(),

Resources