ContextErrorException after generating a bundle in Symfony - php

I have this problem for days now... I just do a fresh install on syfmony but after i create a bundle from symfony console i get this error from the webpage...
ContextErrorException: Warning: is_dir(): open_basedir restriction in effect.
File(/srv/www/backend.tacon.eu/web) is not within the allowed path(s): (/var/www/clients/client1/web5/web:/var/www/clients/client1/web5/private:/var/www/clients/client1/web5/tmp:/var/www/backend.tacon.eu/web:/srv/www/backend.tacon.eu/web:/usr/share/php5:/usr/share/php:/tmp:/usr/share/phpmyadmin:/etc/phpmyadmin:/var/lib/phpmyadmin) in /var/www/clients/client1/web5/web/back/vendor/symfony/symfony/src/Symfony/Component/Process/ExecutableFinder.php line 59
I don't know why is this happening. This is not my first symfony project and this never happens. Also on the same server i have various symfony projects.
Thanks in advance

I had the same problem after refresh install symfony using composer.
I have solved this issue by editing php configuration file (php.ini).
Set the open_basedir option to null.
More about open_basedir

From ISPConfig:
WebSites-> Your Site -> Options -> PHP open_basedir ->
Add :/srv/www/backend.tacon.eu/web at the end of line

if you face this error on live server then you can solve this problem like this-
<?php
require_once __DIR__.'/../app/bootstrap.php.cache';
require_once __DIR__.'/../app/AppKernel.php';
use Symfony\Component\HttpFoundation\Request;
$kernel = new AppKernel('prod', true);
$kernel->loadClassCache();
// wrap the default AppKernel with the AppCache one
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
in line $kernel = new AppKernel('prod', true); you may change it "prod" or "dev" and it's value like true or false;

Related

Symfony throws error but not 404 page

The problem is I see trace error pages in production mode, in Symfony app.
I have this in app.php:
$kernel = new AppKernel('prod', true);
And I have done:
php app/console cache:clear --env=prod
Ok, I was completely wrong! The purpose of the second parameter in $kernel = new AppKernel('prod', true); is to enable/disable the debug mode. You can read the doc here: https://symfony.com/doc/current/configuration/environments.html
The issue was solved by setting to false the debug mode.

Symfony's app_dev.php shows "half" source code

I downloaded it with composer. Tried to run with the PHPStorm's built in server and it does not load the toolbar (404).
Then I tried to run it with Apache, I copied my project to /var/www/html and then I went to http://localhost/symfony_app/web/app_dev.php in the browser.
What is strange is that it partially shows the source code (but without line breaks):
loadClassCache(); $request = Request::createFromGlobals(); $response = $kernel->handle($request); $response->send(); $kernel->terminate($request, $response);
This file (complete) has the following source code:
<?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#checking-symfony-application-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'], ['127.0.0.1', 'fe80::1', '::1']) || php_sapi_name() === 'cli-server')
) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
/**
* #var Composer\Autoload\ClassLoader $loader
*/
$loader = require __DIR__.'/../app/autoload.php';
Debug::enable();
$kernel = new AppKernel('dev', true);
$kernel->loadClassCache();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
In the Apache error logs there is nothing, just restarts.
The app works OK with Symfony's built-in server, in port 8000
The same thing just happened to me on a new vagrant setup I made. Weirdest thing I've seen. It turns out I had installed php5, but not completely. I needed to install specifically the libapache2-mod-php5 package in Ubuntu. Running this installed it for me in Ubuntu:
sudo apt-get install php5
I don't know what system you're running on but it might be a missing php package like this that's the culprit.
if you have apache2 and php installed and got this issue enable
mod_rewrite
you can do that with:
a2enmod rewrite
in your terminal and restard apache

Laravel - Getting errors when using HTTPS and AJAX only on Safari and a few other browsers

When I'm doing a post request using AJAX, I'm getting this error:
PHP Parse error: syntax error, unexpected '/*' (T_STRING), expecting
')' in /home/laravel/public_html/public/index.php on line 47
PHP Fatal error: require(): Failed opening required
'/home/user/public_html/vendor/ClassLoader.php'
(include_path='.:/usr/lib/php:/usr/local/lib/php') in
/home/user/public_html/vendor/autoload.php on line 6
The index.php it's referring to is as following:
<?php
require __DIR__.'/../../laravel/bootstrap/autoload.php';
$app = require_once __DIR__.'/../../laravel/bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
$response->send();
$kernel->terminate($request, $response);
I have no idea why this is happening.
This only happens in safari and a few other browsers. Doesn't happen on chrome.
The inspect element looks like this:
Please help guys. Thanks
Edit: Folder structure:
home/user/laravel -> All my laravel files
home/user/laravel/public_html/public -> my public folder
When I do composer install, it gives me this error:
Warning: Composer should be invoked via the CLI version of PHP, not the cgi-fcgi SAPI
Composer could not find a composer.json file in /usr/bin
For some reason, it's looking for composer.json file in /usr/bin. The composer.json file is in the current directory in which I am cd'd to.
Edit: index.php should look like this:
<?php
require __DIR__.'/../../bootstrap/autoload.php';
$app = require_once __DIR__.'/../../bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
$response->send();
$kernel->terminate($request, $response);
That will hopefully do the trick.
The first line of any PHP file should be
<?php
Somehow that's missing in your copy of the index file. I'm not sure how that happened, but that would be the error you're seeing.
I had the same issue. Exact same. It was happening only on HTTPS.
Here's what I did:
First thing's first. Run these commands:
php artisan cache:clear
chmod -R 777 app/storage
composer dump-autoload
php artisan optimize
Then run
npm install
Make sure that in your public_html folder, there is no index.html or index.php file. It should only be in the public_html/public folder.
After that, ensure that you Htaccess is set up properly.
Htaccess in public_html directory should be something like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
After doing the following, let me know how it goes. Also, be sure to look at the log file in storage/logs/laravel.log and your Apache logs.
Cheers!

Symfony2.3 production page blank 500

after working with my project on dev mod, i found some problems with prod on OVH.
it shows me a blank page ! i try to follow the issue on app.php and i found that the problem persist with the execution of $response = $kernel->handle($request); and it don't logging on prod.
so when i change the row on app.php : $kernel = new AppKernel('prod', false); with $kernel = new AppKernel('dev', false); it works well !!!
here's my app.php
<?php
/*
* This file is part of the Sonata package.
*
* (c) Thomas Rabaix <thomas.rabaix#sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
umask(0000);
require_once __DIR__ . '/../app/bootstrap.php.cache';
require_once __DIR__ . '/../app/AppKernel.php';
//use Symfony\Component\HttpFoundation\Request;
// if you want to use the SonataPageBundle with multisite
// using different relative paths, you must change the request
// object to use the SiteRequest
use Sonata\PageBundle\Request\SiteRequest as Request;
$request = Request::createFromGlobals();
$kernel = new AppKernel('prod', false);
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
EDIT :
in dev and prod local mode test it works well with
php app/console cache:clear --env=prod --no-debug
php app/console assets:install web_directory
php app/console assetic:dump web_directory
should i add or install php5 on my project ?
EDIT :
my project contains : sonata-project, fosUserBundle,etc...
EDIT
the problem was on config_prod.xml
doctrine:
orm:
entity_managers:
default:
metadata_cache_driver: apc
query_cache_driver: apc
result_cache_driver: apc
intil now after it return an error 500 ! why ? because of apc was not enabled !
so my question how to enable apc on OVH pro !
Go to web/config.php and comment ot the following lines:
if (!in_array(#$_SERVER['REMOTE_ADDR'], array(
'127.0.0.1',
'::1',
))) {
header('HTTP/1.0 403 Forbidden');
exit('This script is only accessible from localhost.');
}
That will enable the config.php to be called from "extern". Don't forget to remove the comments after you've checked everything.
If you have console access on the production server, enter the root directory of your project and call php app/check.php to run the checks on the console.

Symfony2: class included in AppKernel can not be found on webserver

I added to my project FOSUserBundle, on localhost it's works fine. But on web server I get
Fatal error: Class 'FOS\UserBundle\FOSUserBundle' not found in
/home/zone24/domains/zone24.linuxpl.info/public_html/worldclock/app/AppKernel.php on line 22
I can't cache:clear because I get this same message.
My autoload.php
<?php
use Doctrine\Common\Annotations\AnnotationRegistry;
$loader = require __DIR__.'/../vendor/autoload.php';
// intl
if (!function_exists('intl_get_error_code')) {
require_once __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';
$loader->add('', __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs');
}
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
return $loader;
The line from AppKernel.php who make mistake
new FOS\UserBundle\FOSUserBundle(),
Folderfriendsofsymfony in /vendor has 775 permisions
Are you using APC ? If yes, restart apache to clear its cache.
If that does not help, you can always force the autoloader to register a specific namespace with $loader->add(), but you should not have to do that. FOS works fine for me without adding that.

Categories