New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error when deploying to production #154

Closed
mvdnbrk opened this Issue Oct 24, 2018 · 31 comments

Comments

Projects
None yet
8 participants
@mvdnbrk

mvdnbrk commented Oct 24, 2018

Install Telescope

composer require laravel/telescope --dev

When deploying your app to production you will probably run:

composer install --no-dev

Which will trigger php artisan package:discover and will result in an error:

PHP Fatal error:  Class 'Laravel\Telescope\TelescopeApplicationServiceProvider' not found 
in ~/app/Providers/TelescopeServiceProvider.php on line 10

App\Providers\TelescopeServiceProvider::class is added to config/app.php when you run php artisan install:telescope.

But the package is not installed since you are running composer install with the --no-dev flag.

@browner12

This comment has been minimized.

Contributor

browner12 commented Oct 24, 2018

I believe the idea is that you run php artisan telescope:install on your dev environment, and then commit the newly created provider to your repo.

@themsaid

This comment has been minimized.

Member

themsaid commented Oct 24, 2018

check @browner12's comment

@themsaid themsaid closed this Oct 24, 2018

@mvdnbrk

This comment has been minimized.

mvdnbrk commented Oct 24, 2018

@themsaid am I missing something?

Running php artisan telescope:install adds App\Providers\TelescopeServiceProvider::class, to the config/app.php file. And creates the TelescopeServiceProvider class in the app/Providers folder:

<?php

namespace App\Providers;

use Laravel\Telescope\Telescope;
use Illuminate\Support\Facades\Gate;
use Laravel\Telescope\IncomingEntry;
use Laravel\Telescope\TelescopeApplicationServiceProvider;

class TelescopeServiceProvider extends TelescopeApplicationServiceProvider
{
    ...

The service provider requires Laravel\Telescope\TelescopeApplicationServiceProvider which will not be installed with composer install --no-dev.

@browner12

This comment has been minimized.

Contributor

browner12 commented Oct 24, 2018

ahh, i see what you're saying. yah, that's a thinker

@mvdnbrk

This comment has been minimized.

mvdnbrk commented Oct 24, 2018

composer require laravel/telescope --dev

😉

@browner12

This comment has been minimized.

Contributor

browner12 commented Oct 24, 2018

that's the question, though. I'm still confused if this package is intended to be used in Production or not.

@mvdnbrk

This comment has been minimized.

mvdnbrk commented Oct 24, 2018

I believe this package is mainly for dev purposes but could be used in production as well according to the post by Matt Stauffer.

@johanvanhelden

This comment has been minimized.

johanvanhelden commented Oct 24, 2018

I often compare Telescope to the Debugbar, both are packages that, IMHO, should not be installed on production. If for some reason there is something wrong with the Gate, and you expose Telescope or Debugbar to the outside world, you expose details of your application that should not be public.

So I'd rather see a solution that does not involve installing it as a regular dependency. Maybe this issue could be opened again?

@matthewhall-ca

This comment has been minimized.

matthewhall-ca commented Oct 24, 2018

Agreed with @johanvanhelden this seems like it should be handled like Debugbar or Clockwork, where you can install it as a dev dependency and just have it not active in Production

@mvdnbrk

This comment has been minimized.

mvdnbrk commented Oct 24, 2018

Agree. Most of the times you will not push Telescope to production.
However, if you would like to have it available in production, you can.

By default you will only have access to the dashboard in a local environment, unless you explicitly give access to to a user with the gate method:

protected function gate()
{
    Gate::define('viewTelescope', function ($user) {
        return in_array($user->email, [
            'taylor@laravel.com',
        ]);
    });
}
@johanvanhelden

This comment has been minimized.

johanvanhelden commented Oct 24, 2018

@mvdnbrk Sure, but to prevent security issues I'd rather not have it installed on production at all. If a bug slips through and a part of Telescope exposes things that it shouldn't, we've got a problem. And sure, the Gate should prevent it, but what if something is bugged or misconfigured.

If I can just not install Telescope on production, I've got nothing to worry about.

@browner12

This comment has been minimized.

Contributor

browner12 commented Oct 24, 2018

yah, I was thinking originally that this would just use the package auto-discovery so on dev it would just be ignored.

@mvdnbrk

This comment has been minimized.

mvdnbrk commented Oct 24, 2018

Like @matthewhall-ca mentioned this should be handled like Debugbar.
Just install Telescope with composer require laravel/telescope --dev and there should nothing to be worried about when deploying to production.

App\Providers\TelescopeServiceProvider::class should not be added to config/app.php.

Like @browner12 mentioned package auto-discovery should handle this?

What about the public/vendor/telescope folder?
Shouldn't be there either I guess.

@browner12

This comment has been minimized.

Contributor

browner12 commented Oct 24, 2018

I feel like we're running into some chicken/egg problems 🤕

we do need the vendor assets published and committed, because otherwise your re-deploying them on new clones?

idk anymore.

@johanvanhelden

This comment has been minimized.

johanvanhelden commented Oct 25, 2018

I'd say Telescope does not need to publish its assets. The (and I am going to use this example again) Debugbar also works fine without having any assets published and committed.

URL: /_debugbar/assets/stylesheets?v=1534935979
screenshot from 2018-10-25 08-51-14

Source: https://github.com/barryvdh/laravel-debugbar/blob/master/src/Controllers/AssetController.php

I'm going to ask again, but could someone open up this issue again?

@themsaid

This comment has been minimized.

Member

themsaid commented Oct 25, 2018

Hey everyone, Telescope is meant to be used for dev purposes AND production as well, however using it in production needs to be controlled and secured.

If you don't want to use it in production, just add the package to extra.laravel.dont-discover in your composer.json and only register the ServiceProvider if the environment isn't production.

if ($this->app->environment('local')) {
    $this->app->register(\Laravel\Telescope\TelescopeServiceProvider::class);
    $this->app->register(\App\Providers\TelescopeServiceProvider::class);
}

@themsaid themsaid reopened this Oct 25, 2018

@johanvanhelden

This comment has been minimized.

johanvanhelden commented Oct 25, 2018

Alright thanks for clarifying @themsaid , so besides adding this information to the documentation, the only issue left would be the asset handling, right?

@emielmolenaar

This comment has been minimized.

emielmolenaar commented Oct 25, 2018

Just symlink vendor/laravel/telescope/public to public/vendor/telescope and add the symlink to git. Same thing I did with Horizon. Solves assets troubles 😃

@johanvanhelden

This comment has been minimized.

johanvanhelden commented Oct 25, 2018

Symlinking feels a bit dirty, because those symlinks will exist on production as well, but will be dead. And I am not sure all OS's support symlinks in the same way. Let's say I commit a symlink on Linux, will it also work for my Windows colleague?

@emielmolenaar

This comment has been minimized.

emielmolenaar commented Oct 25, 2018

We don't care about Windows, so symlinks are fine here. Guess they won't work on Windows.

What harm could a dead symlink in public/vendor do? In this case I rather prefer a dead symlink over pushing these (ultimately unused) assets to production.

@mvdnbrk

This comment has been minimized.

mvdnbrk commented Oct 25, 2018

A route to telescope/assets/stylesheets or similar seems more elegant to me.
That route can take of serving all the necessary assets.
Keeps the public folder clean as well.

@themsaid

This comment has been minimized.

Member

themsaid commented Oct 25, 2018

What's the problem with having the public/vendor/telescope file? I don't understand.

@matthewhall-ca

This comment has been minimized.

matthewhall-ca commented Oct 25, 2018

Yeah personally i see no issue with having a public/vendor/telescope file, the issue is that if you have something in your require-dev dependencies it shouldn't be breaking a dev-less composer install.

Like having symfony/css-selector and symfony/dom-crawler in your require-dev. Application will run fine without them when you do a dev-less install.

@themsaid

This comment has been minimized.

Member

themsaid commented Oct 25, 2018

If you load the service provider manually as in #154 (comment), it should work in production without issues.

@dindong

This comment has been minimized.

dindong commented Oct 26, 2018

I required provide in app service provider and added package to dont-auotload as descriped.
If I run php artisan package:discover after composer install --no-dev I get the following Error:

In TelescopeServiceProvider.php line 10:

  Class 'Laravel\Telescope\TelescopeApplicationServiceProvider' not found

Am I doing anything wrong?

@lesterchan

This comment has been minimized.

lesterchan commented Oct 27, 2018

@dindong Did you run composer require laravel/telescope --dev instead of composer require laravel/telescope?

@dindong

This comment has been minimized.

dindong commented Oct 29, 2018

@lesterchan Yes I installed it as ah dev dependency, because I dont want it on production.

@lesterchan

This comment has been minimized.

lesterchan commented Oct 29, 2018

@dindong did you put don't discover in composer.json?

    "extra": {
        "laravel": {
            "dont-discover": [
                "laravel/telescope"
            ]
        }
    },

Then in AppServiceProvider register() do something like

        if ($this->app->environment() === 'local') {
            $this->app->register(\Laravel\Telescope\TelescopeServiceProvider::class);
            $this->app->register(TelescopeServiceProvider::class);
        }
@dindong

This comment has been minimized.

dindong commented Oct 29, 2018

@lesterchan I only register this->app->register(TelescopeServiceProvider::class); at the moment.

@lesterchan

This comment has been minimized.

lesterchan commented Oct 29, 2018

@dindong \Laravel\Telescope\TelescopeServiceProvider::class is the one that loads all the telescope routes. You need to register that if you are not using auto discover (like me).

@themsaid

This comment has been minimized.

Member

themsaid commented Nov 13, 2018

Hope this is clear to everyone by now.

@themsaid themsaid closed this Nov 13, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment