Symfony2 routing no match - php

We have a symfony2 application. Everything was successful until we tried to create a subdomain (for a different application). For our first test with the subdomain we linked the subdomain to a route in the s2 application.
After our test the application always return a 404 code for the route used in the previous test. We return back all configurations within the server and the problem keeps.
The route is "/usuario/iniciar-sesion".
Our original configuration for the routing is:
#/src/AppBundle/Resources/routing.yml
app_user:
resource: routing/user.yml
prefix: /usuario
#/src/AppBundle/Resources/routing.yml
app_login:
path: /iniciar-sesion
defaults: { _controller: AppBundle:User:login }
We execute the next commands in console to check the routing:
php console router:debug
php console router:match /usuario/iniciar-sesion
and everything looks fine.
Everything else works fine. At this moment the hotfix is changing the prefix (we called "usuarios") and the application runs successful. After it we tried return back the original prefix, but the application keeps return the 404 code.
We execute a lot of cache:clear --env=prod and manually delete cache dir. In our local enviroment everything works fine.
What else we can check?

So as you said in the comment I think you are trying to achieve this:
#/src/AppBundle/Resources/routing.yml
app_login:
host: usuario.site.com
path: /iniciar-sesion
defaults: { _controller: AppBundle:User:login }
And in the server host configuration you need to add the subdomain as a ServerAlias and also own that subdomain I think: https://www.godaddy.com/help/add-a-subdomain-that-points-to-a-server-name-19974

We resolved the problem.
We didn't consider the folders created by the server when set up the domain. We deleted them and the application responds on the original path.

Related

Symfony 2 : Web debug tool bar not showing (404 error) and Twig path function's not working

I have built a symfony 2.6 web site and I deploy it in an url like this :
https://www.example.com/abc/
This url points on the "web" directory (as the root directory).
The web site is working fine, but there is two issues :
1) Web debug tool bar is not showing because the widget is pointing on https://www.example.com/ not on
https://www.example.com/abc/ and I don't understand why ?!
2) Same thing for Twig path() function, it is also pointing on https://www.example.com/ not https://www.example.com/abc/
So do you have any idea about that ?
I Finally Got it, "abc" is not a physical folder it's just a "virtual" path defined in the virtual host of www.example.com,
so while https://www.example.com/abc/ is pointing on web folder of my symfony project, which is the root repository by default in Symfony framework, the folder "abc" doesn't exist in reality,
In fact I use to modify in this script "/public_html/vendor/symfony/symfony/src/Symfony/Component/Routing/Generator/UrlGenerator.php" this way by enforcing the "/abc" part in the dynamically
generated url :
$url = $schemeAuthority."/abc".$this->context->getBaseUrl().$url;
I think Symfony doesn't take this case into account by default.
Other thing that can cause this issue too is to verify the scheme (http or https) of your website in the routing configuration (routing.yml) of your project, example :
test:
resource: "#testBundle/Controller/"
type: annotation
prefix: /
schemes: [http]

Laravel: routing not working

I have downloaded clients project from the internet, and it is programmed in Laravel (also seen by directory structure). I have set up homestead.yaml, hosts, filled the DB and modified .env. I also did a vagrant provision and 'composer dump-autoload` once everything was done.
Problem I'm facing is that home route '/' returns index.html in root. But route.php says different:
Route::get('/', 'PagesController#home');
Route::get('about', 'PagesController#about');
I've tried to intentionally modify routes so that they point to controller which doesn't exist, deleting some letters inside Kernel.php...anything that would reasonably produce an error, and nothing happens. I still get back what is inside index.html. Also there is index.php which gets returned after I enter anything after slash inside the url:
/bla
/nlo
/xyz
You get the point...what can be the issue?
I have also tried with artisan cache:clear
It's a webserver misconfiguration error. The webserver is configured to serve index.html with more priority than index.php. Relevant configuration can be found at /etc/apache2/httpd.conf, /etc/apache2/sites-available/your-site, .htaccess, or for nginx /etc/nginx/sites-available/your-site just to mention the two most common web servers.

Testing multi-tenancy Laravel applications using Behat / Mink and Behat Laravel Extension

I am building a multi-tenant SaaS application which I am trying to write tests for with Behat, using Mink and the Behat Laravel Extension
When you register for an account, you get your own subdomain on the site {account}.tenancy.dev
my behat.yml file looks like so:
default:
extensions:
Laracasts\Behat:
# env_path: .env.behat
Behat\MinkExtension:
default_session: laravel
base_url: http://tenancy.dev
laravel: ~
I am having problems straight off the bat as when I try to test my registration flow, I am getting a 404 error testing that the new subdomain is accessible, all of the data has been saved correctly, manually testing the process works and the subdomain routing works.
I was wondering if there was any way to do this using Behat and how I would go about setting Behat / Mink to use wildcard subdomains to test SaaS applications?
I am running the test inside the Homestead VM.
The base_url: http://tenancy.dev configuration is used to generate a fully qualified domain URL when you utilize relative path URL's in your mink steps (IE "/home").
When you want to hit a domain different from the domain specified in base_url, all you have to do is use the fully qualified domain URL in your step like "http://test.tenancy.dev/fully/qualified".
So use the base_url configuration to set what you will be using for the majority of your steps as relative url's and then explicitly specify the full domain for the exceptions.
When I create an account named foo
And GET "http://foo.tenancy.dev/ping"
Then I get a 200 response code
When I GET "/home"
Then the response contains "Sign Up"
If the majority of your testing will be against the sub domain, set that as your base_url and explicitly specify your top level domain when necessary.
You may resolve subdomains using xip.io, which is especially useful if you cannot access the /etc/hosts file on a CI server, for example.
To route {account}.tenancy.dev to your local webserver, you can use account.tenancy.dev.127.0.0.1.xip.io which resolves to 127.0.0.1.
After a short while I revisited this problem and found a rather simple solution to be used in my FeatureContext.php:
$this->setMinkParameter('base_url', $url);
This changes the base url for any scenario it is used in:
/**
* #Given I visit the url :url
*/
public function visitDomain($url)
{
$this->setMinkParameter('base_url', $url);
$this->visit('/');
}
Which is used in the following way:
Scenario: Test Multi Tenancy
Given I have a business "mttest"
When I visit the url "http://mttest.example.com"
Then I should see "mttest"
Obviously this is slightly contrived but does show that what I was intending to do is possible.

From development (app_dev.php) to production (app.php) in Symfony2

I'm working in a Symfony2 project, under development enviroment app_dev.php all works fine but when I go to production app.php I get this error at Firebug console:
"NetworkError: 404 Not Found - http://applicationtest.com/css/fmain.css"
And of course CSS and JS isn't working, what I miss?
It seems that you have not dumped assetic resources:
php app/console assetic:dump --env=prod
And then try again...
for example:
//routing.yml
test_root:
path: /css/fmain.css
defaults: { _controller: AcmeBlogBundle:Blog:index }
..
is valid.
That means that the request of that root will call the indexAction of the Blog Controller in my exemple.
thought, are you trying just to include some css file?
is so check the doc: http://symfony.com/fr/doc/current/book/templating.html#liens-vers-des-fichiers

Cache issue with dynamic parameter in config.yml

I have a multisite aplication with a log system depends on each site and I want that each of them has its own log file so I did that :
1) I use a dynamic variable in config.yml with depends on $_SERVER['HTTP_HOST'].
config.yml:
imports:
- { resource: param.php }
...
monolog:
handlers:
user:
type: stream
path: %kernel.logs_dir%/%domain_name%.%log_filename%
channels: [user]
=> %domain_name% is my dynamic variable
2) I set it in app/config/param.php:
<?php
$url = $_SERVER['HTTP_HOST'];
$domain = preg_replace('/^www./', '', $url);
$container->setParameter('domain_name', $domain); // this set my variable `%domain_name%` with the current domain (ex: site1.com)
Problem :
This code works fine but when I switch to an other site, the value of %domain_name% remains equal to its initial value.
Exemple :
I am in www.site1.com => %domain_name% value is "site1.com" so it works
fine
I switch to www.site2.com => %domain_name% value is always "site1.com" and
not "site2.com"
Why ?
Cache issue. Indeed, Symfony load in cache config.yml so it keeps the first value of %domain_name%
To delete this value I have to execute this command: rm -rf app/cache/* but it is not a solution.
So nobody has a solution for this problem ? Thanks
We had the same problem in our multi-site CMS environment. Symfony is primarily designed to run a single site, so the config.yml gets run once, and then cached. That means if you inject dynamic parameters into the config.yml (by any means: Globals, Constants, Apache Environment, etc), after the first run they are cached for each subsequent request :( So the next unique domain site request, will be using the cached values from the first site. In most cases, this creates problems.
Some people have suggested creating different environments for each site. But that's not practical when you host hundreds, thousands or millions of sites.
Alternative Cache Location
At the moment, the best solution we can conceive is to specify a different cache folder for each site. So you extend the app/appKernel.php and customize the getCacheDir function.
//app/appKernel.php
class AppKernel extends Kernel
{
public function getCacheDir()
{
return $this->rootDir.'/cache/'.$this->environment.'/'.$_SERVER['HTTP_HOST'];
}
}
See API Reference for Kernel.
I am not quite sure, if you are using the parameter file/configuration as intended.
For me there is information missing, to answer your question directly, so here are the two possible scenarios:
1) Site www.site1.com and www.site2.com is pointing at the SAME source (same server):
In this case I wouldn't define the domain_name as an configuration value, course it is not an distinct configuration parameter it is more like a variable. Build a service or think about defining an additional environment.
2) www.site1.com and www.site2.com are two distinct projects:
In that case you shouldn't deploy the contents of the cache directory (which you should do anyway; but in this case it would be the issue ;)).
EDIT
You could implement different configuration files to solve:
config_site1.yml # Configuration for www.site1.com
config_site2.yml # Configuration for www.site2.com
Controller in your /web directory:
app_site1.php
app_site2.php
initialize the AppKernel with the requested environment, and point to the controller in your vhost config or your htaccess file.
I think you could change the app.php controller even to something like:
[...]
require_once __DIR__.'/../app/AppKernel.php';
$request = Request::createFromGlobals();
$kernel = new AppKernel($request->giveMeMyHostEnvironmentMappingShizzle(), false);
$kernel->loadClassCache();
[...]
kind regards

Categories