Symfony 4 deployment not working - production-environment

I'm trying to deploy a symfony 4 project in my server, but I'm having problems to acomplish it production (in local it works perfect).
Previously I have deployed a lot of symfony 3 projects in my server, so I decided to test a Symfony 4.
This is the error that I'm getting in my log:
[Wed Dec 06 10:26:33.141952 2017] [:error] [pid 13485] [client 84.120.210.249:50394] PHP Fatal error: Uncaught TypeError: Return value of Symfony\Component\Dotenv\Dotenv::populate() must be an instance of Symfony\Component\Dotenv\void, none returned in /var/www/my_project/vendor/symfony/dotenv/Dotenv.php:95\nStack trace:\n#0 /var/www/my_project/vendor/symfony/dotenv/Dotenv.php(57): Symfony\Component\Dotenv\Dotenv->populate(Array)\n#1 /var/www/my_project/public/index.php(15): Symfony\Component\Dotenv\Dotenv->load('/var/www/rodage...')\n#2 {main}\n thrown in /var/www/my_project/vendor/symfony/dotenv/Dotenv.php on line 95
This is my index.php (default index.php that you get when you create a project):
<?php
use App\Kernel;
use Symfony\Component\Debug\Debug;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\HttpFoundation\Request;
require __DIR__.'/../vendor/autoload.php';
// The check is to ensure we don't use .env in production
if (!isset($_SERVER['APP_ENV'])) {
if (!class_exists(Dotenv::class)) {
throw new \RuntimeException('APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.');
}
(new Dotenv())->load(__DIR__.'/../.env');
}
if ($_SERVER['APP_DEBUG'] ?? ('prod' !== ($_SERVER['APP_ENV'] ?? 'dev'))) {
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(explode(',', $trustedHosts));
}
$kernel = new Kernel($_SERVER['APP_ENV'] ?? 'dev', $_SERVER['APP_DEBUG'] ?? ('prod' !== ($_SERVER['APP_ENV'] ?? 'dev')));
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
This is what I have in my composer.json:
"require": {
"php": "^7.1.3",
"symfony/asset": "^4.0",
"symfony/console": "^4.0",
"symfony/dotenv": "^4.0",
"symfony/flex": "^1.0",
"symfony/framework-bundle": "^4.0",
"symfony/lts": "^4#dev",
"symfony/twig-bundle": "^4.0",
"symfony/web-server-bundle": "^4.0",
"symfony/yaml": "^4.0"
},
These are the things that I tried:
-cache:clear
-composer update
-apache restart
I think that it something about environment variables, but not really sure...
Any suggestions?
Thank you all for your time!

Void returns are only available from PHP 7.1. My guess is that you are using an earlier version of PHP.
Look at this answer

Related

Hybridauth on Codeigniter Could not load the Hybrid_Auth class

I have installed hybridauth via composer and then followed the steps given here, but always get the following error:
Could not load the Hybrid_Auth class
Any solution to this?
Use:
$this->load->library('hybridauth');
in your controller to load the library.
application/composer.json
{
"require" : {
"hybridauth/hybridauth" : "~3.0"
},
"config": {
"platform": {
"php": "X.X.XX" //SET your php version
}
}
}
and change config file application/config/config.php
$config['composer_autoload'] = TRUE;

Laravel Dingo API returns 404 error on Apache VHosts

I've build a Laravel Rest API with Dingo\API following a tutorial. I've set this up as virtual host at http://site.test
Vhosts are set up in httpd.conf and /etc/hosts files.
But, when I go to http://site.test, it shows the full project directory. So I have to click into the /routes/api.php, but I get the following error:-
Uncaught Error: Call to undefined function app() in /Users/param/Desktop/api/routes/api.php
undefined function app() in /Users/param/Desktop/api/routes/api.php
I ran this during set up:
php artisan vendor:publish --provider="Dingo\Api\Provider\LaravelServiceProvider"
My composer.json file
"require": {
"php": ">=7.1.3",
"dingo/api": "^2.1",
"fideloper/proxy": "^4.0",
"laravel/framework": "5.8.*",
"laravel/tinker": "^1.0"
}
RouteServiceProvider.php file
protected function mapApiRoutes()
{
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
}
routes/api.php file
$api = app('Dingo\Api\Routing\Router');
$api->version('v1', function ($api) {
$api->get('/', function () {
return ['fruits'=> 'Delicious'];
});
});
.env file
API_PREFIX=api
API_DEBUG=true
Would love any help in the right direction -- I can't figure out why http://site.test/api return that error?
For anybody looking for a solution to this assuming your Virtual host is http://site.test
On your.env file put http://site.test as your API_URL environment variable and put site.test as your API_DOMAIN environment variable

Laravel 5.6 Passport FatalThrowableError on php artisan passport:install --force

I seem to be having a problem installing Laravel Passport, when running the command php artisan passport:install --force, I get the following error.
Symfony\Component\Debug\Exception\FatalThrowableError : Access to undeclared static property: Laravel\Passport\Passport::$client
at /Applications/MAMP/htdocs/xxxxxxxxx/alpha.platform.vuex/vendor/laravel/passport/src/Passport.php:413
409| * #return \Laravel\Passport\Client
410| */
411| public static function client()
412| {
> 413| return new static::$client;
414| }
415|
416| /**
417| * Set the personal access client model class name.
Not sure what has happened since running this command last night when it was working fine.
So i have found the problem.
Old composer
"require": {
"php": "^7.1.3",
"fideloper/proxy": "^4.0",
"laravel/framework": "5.6.*",
"laravel/passport": "^6.0",
"laravel/tinker": "^1.0"
},
New composer
"require": {
"php": "^7.1.3",
"fideloper/proxy": "^4.0",
"laravel/framework": "5.6.*",
"laravel/passport": "^4.0.3",
"laravel/tinker": "^1.0"
},
Rolled back the passport version and all seems to work as planned.
** Edit
After checking out the repo, updates where made 3 days back causing the break, now rolled back to 6.0.0 , this issue has been flagged on github.

Silex traits for swiftmailer. Fatal error: Call to undefined method Silex\Application::mail()

I am trying to use traits in Silex for Swift mailer.
I have included:
use Silex\Application\SwiftmailerTrait;
I also checked that traits file were in the right Silex vendor directory.
Test traits:
$app->mail(\Swift_Message::newInstance()
->setSubject("title")
->setFrom(["www.domain.com"]])
->setTo(["something#domain.com"])
->setReplyTo(["user.email#some.com"])
->setBody("TEST MESSAGE")
);
Then, I get this error message:
Fatal error: Call to undefined method Silex\Application::mail() in
...\app.php on line 88
Just to make it clear. I can, without any issue, use standard way of using swift in Silex and it works just fine.
This is the working bit without traits:
// $message = \Swift_Message::newInstance()
// ->setSubject('[YourSite] Feedback')
// ->setFrom(array('noreply#yoursite.com'))
// ->setTo(array('feedback#yoursite.com'))
// ->setBody($request->get('message'));
// $app['mailer']->send($message);
However I was wondering what was actually stopping Silex from running swift with traits. Any idea ?
I am using PHP Version 5.6.11
My composer file:
{
"require": {
"components/jquery": "^2.2",
"components/css-reset": "^2.5",
"silex/silex": "~1.2",
"symfony/browser-kit": "~2.3",
"symfony/console": "~2.3",
"symfony/config": "~2.3",
"symfony/css-selector": "~2.3",
"symfony/dom-crawler": "~2.3",
"symfony/filesystem": "~2.3",
"symfony/finder": "~2.3",
"symfony/form": "~2.3",
"symfony/locale": "~2.3",
"symfony/process": "~2.3",
"symfony/security": "~2.3",
"symfony/serializer": "~2.3",
"symfony/translation": "~2.3",
"symfony/validator": "~2.3",
"symfony/monolog-bridge": "~2.3",
"symfony/twig-bridge": "~2.3",
"doctrine/dbal": ">=2.2.0,<2.4.0-dev",
"swiftmailer/swiftmailer": "5.*",
"twig/twig": "^1.24",
"symfony/security-csrf": "~2.3",
"symfony/yaml": "~2.3"
},
"autoload": {
"psr-4": {
"WL\\Form\\": "WL/Form/",
"WL\\Email\\": "WL/Email/"
},
"classmap":[],
"files":[]
}
}
You need to create a custom Application class which extends \Silex\Application and uses that trait.
Assuming a base project tree as:
project/
|
|_app/
|
|_src/
|
|_vendor/
|
|_web/
You need a class definition:
// src/WL/App.php
namespace WL;
class App extends \Silex\Application
{
use \Silex\Application\SwiftmailerTrait;
// add some other trait
// even custom methods or traits
}
A bootstrap :
// app/bootstrap.php
$app = new \WL\App();
// configure it, register controllers and services, ...
// or import them
foreach (glob(__DIR__ . "/../src/WL/Controller/*.php") as $controllers_provider) {
include_once $controllers_provider;
}
return $app;
So you can import a controller collection like :
// src/Wl/Controller/blog.php
use Symfony\Component\HttpFoundation\Request;
/** #var \Silex\ControllerCollection $blog */
$blog = $app['controllers_factory'];
// define some routes
$blog->post('/send-mail', function (Request $request, \WL\App $app)
{
// Now this application passed to your controller is an
// instance of custom \App which has the trait you want
// in contrary with the default \Silex\Application
$app->mail(...
}
$app->mount('/blog', $blog);
And a front controller :
// web/index.php
// define autoloading
// customize debug and server parameters
$app = require_once '../app/bootstrap.php';
$app->run();

Laravel 5 and Socialite

I have installed laravel/socialite in my project but I can't understand how to make it work...
I have this in my composer.json:
"require": {
"laravel/framework": "5.0.*",
"laravelcollective/html": "~5.0",
"laravel/socialite": "~2.0"
},
I have added in my config/app.php:
'Socialize' => 'Laravel\Socialite\SocialiteServiceProvider'
and:
'Laravel\Socialite\SocialiteServiceProvider',
Then:
composer dump-autoload
Added a new route:
Route::get('auth/facebook', 'Auth\AuthController#getFacebookLogin');
Add the new method:
/**
* #return mixed
*/
public function getFacebookLogin()
{
return \Socialize::with('facebook')->redirect();
}
But all I get is:
FatalErrorException in AuthController.php line 43: Call to undefined method Laravel\Socialite\SocialiteServiceProvider::with()
Where is the error?
You should add
'Socialize' => 'Laravel\Socialite\Facades\Socialite'
as an alias in your app.php.
It seems the Facade alias doesn't really work anymore for Socialite. I think the docs could use some love, in general, too (especially since I don't think it's supposed to be aliased as "socialize").
What I found to work was to alter your use statement to
use Laravel\Socialite\Contracts\Factory as Socialite;
and drop the alias entry altogether.

Resources