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

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

Related

500 Error after symfony update from 4.4.10 to 5.1

I made a symfony update from 4.4.10 to 5.1.
Therefore i called "composer update" more times with making changes like ..
Update TranslatorInterface to Symfony\Contracts\Translation\TranslatorInterface;
Update errors.xml path to resource: '#FrameworkBundle/Resources/config/routing/errors.xml' in twig.yaml
Commented config setting templating -> engines: ['twig', 'php']
Afterwards the "composer update" call is now working successfully without any errors.
But now i get a 500 error when i'm loading the page in my browser. And i don't get any error descriptions in Ubuntu 18.04 neither in var/log/dev.log nor in /var/log/apache2/error.log. And i can't find out until now why it isn't working.
Can you help me? Thanks in advance.
Now i know the problem. After update from from 4.4.20 to 5.1 you have also to update public/index.php because e.g. use path from Symfony\Component\Debug\Debug changed.
That's why I'm using this code in public/index.php now:
<?php
use App\Kernel;
use Symfony\Component\ErrorHandler\Debug;
use Symfony\Component\HttpFoundation\Request;
require dirname(__DIR__).'/config/bootstrap.php';
if ($_SERVER['APP_DEBUG']) {
umask(0000);
Debug::enable();
}
if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? false) {
Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
}
if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? false) {
Request::setTrustedHosts([$trustedHosts]);
}
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
Taken from:
https://raw.githubusercontent.com/symfony/recipes/master/symfony/framework-bundle/4.4/public/index.php
Thanks all for your help.

Laravel deployment HTTP ERROR 500

I have my project in /var/www/html/project on the server,
When ever i hit example.com shows default server page, Then i tried
example.com/project i got list of my project files/folders, Then i tried example.com/project/public it gave me HTTP ERROR 500 error.
Here is my public/index.php file :
<?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);
My project/storage permissions are drwxr-xrwx. 5 root root 4096 Apr 20 12:56 storage
What am i missing ?
Your permissions at /storage and /bootstrap/cache have to be 775 and try to change owner group to www-data if you're using apache
Had the same exact issue and in my case the problem was the default php version (which was 5.5+) of the shared hosting service that I use.
After I changed the php version to 7+ (laravel 5.5 needs php version >= 7) everything started to work. Hope that helps someone!
check php version
Laravel 5.5 requires PHP >= 7.0.0
Laravel 5.6 requires PHP >= 7.1.3

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.

ContextErrorException after generating a bundle in Symfony

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;

Categories