symfony2 fosuserbundle login from browser? - symfony

I have used symfony up until 1.4 and I'm now picking it up from 2.8. Things seemed to be a lot easier back then. All I want is to create a user from the browser. I seem to have succesfully installed symfony as I get a welcome message in my browser. I seem also succesfully have installed fosuserbundle, as I got a database success message on the command line. Now I want to register a user, but I get 404's when I go to http://localhost/app.php/register or to http://localhost/register. The "register"-route is mentioned at http://symfony.com/doc/current/bundles/FOSUserBundle/index.html
Of course, this is working: http://localhost/app.php/
The tutorials seem to assume you know a lot about symfony, but this should be something all new users want to use?

in Symfony 2:
app.php runs the production environment
app_dev.php runs the development environment
If you don't like this approach you have 2 solutions:
Rename app_dev.php to index.php in development and point your .htaccess to it
RewriteRule ^(.*)$ index.php [QSA,L]
Create an index.php file and rely on environment variables to determine your application environment, something like this:
defined('SYMFONY_ENV') || define('SYMFONY_ENV', (getenv('SYMFONY_ENV') ? getenv('SYMFONY_ENV') : 'prod'));
switch (SYMFONY_ENV) {
case 'prod':
require __DIR__ . '/app.php';
break;
case 'dev':
case 'staging':
case 'test':
require __DIR__ . '/app_dev.php';
break;
default:
header('HTTP/1.0 500 Internal Server Error');
exit('Improper SYMFONY_ENV set. See ' . basename(__FILE__) . ' for more information.');
}
you can set your environment variable in the .htaccess like this
SetEnv SYMFONY_ENV development

Related

How can I integrate wordpress into magento 2 project in valet plus?

I am using Valet+ for my Magento projects.
Currently I’m trying to add WP integration for M2 project. I put wordpress copy into pub/wp/ directory and want to go through the installation process, but I’m receiving 404 error when I’m trying to access url like https://magento2.test/wp/
Could anyone advice for it?
Thank you!
You can use custom valet driver for it.
Copy Magento2ValetDriver.php into magento root directory and rename it to LocalValetDriver.php
Also, change the class name to LocalValetDriver in it.
In the function frontControllerPath, add the following code at the top.
if ($uri === '/wp') {
$_SERVER['DOCUMENT_ROOT'] = $sitePath . '/pub/wp';
return $sitePath . '/pub/wp/index.php';
}

Symfony2 and production environment - allways displays app_dev in links

I have a symfony2 project running with nginx and the problem is that when accessing the prod environment, all the links are still with app_dev.php there.
Here are my config files:
app.php
<?php
require_once __DIR__.'/../app/bootstrap.php.cache';
require_once __DIR__.'/../app/AppKernel.php';
use Symfony\Component\HttpFoundation\Request;
$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();
$kernel->handle(Request::createFromGlobals())->send();
The links in the twig file are called this way:
Route name: user_login, in twig: user_login_path()
Where could the problem come from? Nginx?
You should always use path('route_name') in order to generate links or actions. It seems that the function(s) you are using (kind of twig extension) is bad coded and server dependent. But it does not comes with Symfony itself.
You have multiple options :
The cleanest : replace every href, action, ... with the path function
A (maybe) faster one : find the custom twig extension and make it work (more likely in src/Acme/MyBundle/Twig/MyExtension.php)
A quick and dirty one : rewrite every app_dev.php urls to app.dev with a .htaccess (not really recommended at all but... well...)

Symfony 2.4: An error occurred while loading the web debug toolbar (404: Not Found)

I just downloaded a fresh copy of Symfony 2.4.1 on a Debian 7.3.
The URL /Symfony/web/config.php opens correctly, but when I proceed to Configure, I get:
The requested URL /Symfony/web/app_dev.php/_configurator/ was not found on this server.
If I Bypass configuration and open /Symfony/web/app_dev.php
the page displays, but an error pops up saying:
An error occurred while loading the web debug toolbar (404: Not Found)
Do you want to open the profiler?
If I accept, I get:
The requested URL /Symfony/web/app_dev.php/_profiler/54a8bf was not found on this server.
In other questions (e.g. Symfony 2: 404 Not Found Error when tryes to open /app_dev.php) people suggest to fiddle with the .htaccess file.
I even tried removing it, but it had no effect.
The apache log file shows:
File does not exist: /var/www/Symfony/web/app_dev.php/_wdt/54a8bf, referer: http://wwwtest.di.unipi.it/Symfony/web/app_dev.php
File does not exist: /var/www/Symfony/web/app_dev.php/_profiler/54a8bf
So it looks like routing to any inner URL fails, despite the fact that the correct routing seems to be in place:
> app/console router:debug
[router] Current routes
Name Method Scheme Host Path
_wdt ANY ANY ANY /_wdt/{token}
_profiler_home ANY ANY ANY /_profiler/
_configurator_home ANY ANY ANY /_configurator/
...
I have changed memory_limit in /etc/php5/fpm/php.ini to 512Mb and debug toolbar started to work.
Found solution for me here
The solution for me was to update my app_dev.php file to resemble the one in the Symfony2 repo
Notice the Debug class being used. This wasn't used in older versions of symfony. I updated this file and the javascript alert appears to be gone.
<?php
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Debug\Debug;
// If you don't want to setup permissions the proper way, just uncomment the following PHP line
// read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information
//umask(0000);
// This check prevents access to debug front controllers that are deployed by accident to production servers.
// Feel free to remove this, extend it, or make something more sophisticated.
/*
if (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !in_array(#$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1'))
) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
*/
$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
Debug::enable();
require_once __DIR__.'/../app/AppKernel.php';
$kernel = new AppKernel('dev', true);
$kernel->loadClassCache();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
Is the following present in web/app_dev.php? The line below fixed it for me.
$kernel->terminate($request, $response);
Apache directive DirectoryIndex app.php does the tricks for me.
I put it in apache vhost conf with AllowOverride None to prevent override by .htacces.
Hope this help.

How Avalanche Imagine Bundle can work on production environment?

I try to use AvalancheImagineBundle and I don't understand how it can works in production environment.
The default cache_prefix is media/cache. All cached images will be in the myProject/web/media/cache directory and it's also a Symfony2 route :
Name Method Scheme Host Path
_imagine_thumbnail GET ANY ANY /uploads/cache/{filter}/{path}
If I do a test on this url "http://my-project.fr/app.php/", the bundle works fine:
The first time, I try to show the /app.php/media/cache/thumbnail/profile.jpg picture. The Symfony2 route is caught. The bundle return the cropped picture and cache it.
The second time, the route is caught again and the bundle redirects me to the cached picture /media/cache/
In short, the first time /app.php/media/cache -> bundle, and second time /media/cache -> assets
But in production environment, app.php is missing so how the bundle can do the difference ?
I'm not familiar with lighttpd, so I can only point you to a direction where to look.
The "switch" is done via .htaccess, here are two relevant lines and explanation:
# If request is an existing file, then it's simply returned
RewriteCond %{REQUEST_FILENAME} !-f
# Else the request is pushed to the app.php front controller
RewriteRule ^(.*)$ app.php/$1 [QSA,L]
I think you're missing first part of this config.
P.S. Note that app.php isn't actually missing, it's just "hidden".
The -f option does not exist in lighttpd so I switch to apache2 and everything work well.

Nginx (as front end to Apache) to serve WP Super Cache static files

I am currently working on my Wordpress blog, which is hosted on a VPS.NET VPS with Nginx as front end to Apache to serve static files, while Apache takes care of the PHP in FastCGI. This seems to be working great, however I haven't yet managed to have Nginx serve WP-SuperCache files as well, which I would like for maximum performance (I am not planning to completely replace Apache with Nginx right now because I've got a Virtualmin license and it does not support Nginx).
I have tried a lot of rules found here and there but in the end none worked for me or I am missing something.
If Apache is stopped, in fact, I can still get images, stylesheets and javascript delivered to the browser by Nginx directly.
But if I try to surf the blog (with pages cached for sure by WP-SuperCache) with Apache stopped, all I get from Nginx is a "502 bad gateway".
Any ideas would be greatly appreciated.
Many thanks in advance.
Nginx can handle your fastCGI. Bundled with Nginx, generally, all Apache does is cost you resources.
Regarding WP Super Cache, if you create a new file and paste this, it'll give you both that and, while we're about it, FURLs...
# if the requested file exists, return it immediately
if (-f $request_filename) {
break;
}
set $supercache_file '';
set $supercache_uri $request_uri;
if ($request_method = POST) {
set $supercache_uri '';
}
# Using pretty permalinks, so bypass the cache for any query string
if ($query_string) {
set $supercache_uri '';
}
if ($http_cookie ~* "comment_author_|wordpress|wp-postpass_" ) {
set $supercache_uri '';
}
# if we haven't bypassed the cache, specify our supercache file
if ($supercache_uri ~ ^(.+)$) {
set $supercache_file /wp-content/cache/supercache/$http_host/$1index.html;
}
# only rewrite to the supercache file if it actually exists
if (-f $document_root$supercache_file) {
rewrite ^(.*)$ $supercache_file break;
}
# all other requests go to Wordpress
if (!-e $request_filename) {
rewrite . /index.php last;
}
Now, goto your virtual host file, or nginx.conf if you bundle your sites, and add a line like ..
# Wordpress WP Super Cache plugin and permalinks.
include /usr/local/nginx/conf/wordpress_params.super_cache;
.. where wordpress_params.super_cache is what you called the file we created, and given a path relative to that I've shown.
Then restart Nginx and turn on WP Super Cache plugin and, for the pretty links, add a permalink structure.
Fact is, there's a lot to know about to get the Nginx install right, especially with WordPress and to configure fastCGI. If you like, this would be a good start for you...
.. Setup WordPress on NGINX (FURLs & Cache) - VPS Bible Pt 13
Re. Virtualmin .. I understand you want a CP, but truth is, the resource cost is greater than the cost of the software .. plus it takes way longer to do stuff with a CP.
I'm currently publishing a 21 part VPS Admin series which addresses the lack of an Nginx CP .. that'll be all you need, frankly.
Given a week or two, I challenge you to tell me it's quicker or otherwise better to use a CP :)
It seems silly to run Nginx through Apache.
Set up Nginx to serve up the php and dynamic pages itself and you'll have a much faster service and won't have the problem where apache dies and leaves your webserver(Nginx) hanging.
If your admin panel doesn't support this, you probably should only be using apache in the first place. Either do one or the other, both is just asking for problems.
You may use FREE WordOps - WordPress site and server administration which already offers nginx configuration option (--wpsc) for WP Super Cache and other cache plugins.

Resources