Check laravel websocket on server - php

Im trying to implement laravel websockets and trying to access dashboard.
http://127.0.0.1:8000/laravel-websockets Address leads me to the dashboard on my local machine but when i host it and try www.mysite.com/laravel-websockets, it shows that the page doesn't exist.
Im using this package for laravel websockets and AWS EC2 Instance for hosting.
broadcasting.php
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Broadcaster
|--------------------------------------------------------------------------
|
| This option controls the default broadcaster that will be used by the
| framework when an event needs to be broadcast. You may set this to
| any of the connections defined in the "connections" array below.
|
| Supported: "pusher", "ably", "redis", "log", "null"
|
*/
'default' => env('BROADCAST_DRIVER', 'null'),
/*
|--------------------------------------------------------------------------
| Broadcast Connections
|--------------------------------------------------------------------------
|
| Here you may define all of the broadcast connections that will be used
| to broadcast events to other systems or over websockets. Samples of
| each available type of connection are provided inside this array.
|
*/
'connections' => [
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'useTLS' => false,
'host' => '127.0.0.1',
'port' => 6001,
'scheme' => 'http'
],
],
'ably' => [
'driver' => 'ably',
'key' => env('ABLY_KEY'),
],
'redis' => [
'driver' => 'redis',
'connection' => 'default',
],
'log' => [
'driver' => 'log',
],
'null' => [
'driver' => 'null',
],
],
];

By default, access to the WebSocket dashboard is only allowed while your application environment is set to local.
However, you can change this behavior by overriding the Laravel Gate being used. A good place for this is the AuthServiceProvider that ships with Laravel.
public function boot()
{
$this->registerPolicies();
Gate::define('viewWebSocketsDashboard', function ($user = null) {
return in_array($user->email, [
//
]);
});
}
Refer to this doc https://beyondco.de/docs/laravel-websockets/debugging/dashboard#protecting-the-dashboard

Related

Storage path is not part of public path (Laravel8)

I'm using laravel 8 and I'm getting the storage error:
"Storage path
/var/www/type.adoreanime.com/htdocs/Linkati/storage/app is not part
of public path /var/www/type.adoreanime.com/htdocs/Linkati/public
(View:
/var/www/type.adoreanime.com/htdocs/Linkati/resources/views/layouts/master.blade.php)
(View:
/var/www/type.adoreanime.com/htdocs/Linkati/resources/views/layouts/master.blade.php)
(View:
/var/www/type.adoreanime.com/htdocs/Linkati/resources/views/layouts/master.blade.php)
◀"
I run nginx as my webserver so i've set /var/www/type.adoreanime.com/htdocs/Linkati/public as the root directory.
filesystems.php
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Filesystem Disk
|--------------------------------------------------------------------------
|
| Here you may specify the default filesystem disk that should be used
| by the framework. The "local" disk, as well as a variety of cloud
| based disks are available to your application. Just store away!
|
*/
'default' => env('FILESYSTEM_DRIVER', 'local'),
/*
|--------------------------------------------------------------------------
| Default Cloud Filesystem Disk
|--------------------------------------------------------------------------
|
| Many applications store files both locally and in the cloud. For this
| reason, you may specify a default "cloud" driver here. This driver
| will be bound as the Cloud disk implementation in the container.
|
*/
'cloud' => env('FILESYSTEM_CLOUD', 's3'),
/*
|--------------------------------------------------------------------------
| Filesystem Disks
|--------------------------------------------------------------------------
|
| Here you may configure as many filesystem "disks" as you wish, and you
| may even configure multiple disks of the same driver. Defaults have
| been setup for each driver as an example of the required options.
|
| Supported Drivers: "local", "ftp", "sftp", "s3", "rackspace"
|
*/
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL') . '/storage',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
],
's3_public' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
'visibility' => 'public',
],
],
];
Anyone know how to fix this problem?
Your directory structure might not be setup correctly. Your htdocs directory should be laravel's /public directory, which is the same directory as storage/app/public, if you linked it with storage:link. You seem to have the laravel root folder in htdocs.
Whatever is causing the error, its trying to access storage/app, not storage/app/public. the former shouldn't be visible on your server.

Mail Not Sending via Mailgun API Laravel 8

I am trying to send mail via the mailgun API from my controller but the mail is not reaching mailgun and I am not getting any error messages/logs.
This is in my .env:
MAIL_MAILER=mailgun
MAILGUN_DOMAIN=subdomain.domain.ca
MAILGUN_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxx
This is in my services.php:
<?php
return [
/*
|--------------------------------------------------------------------------
| Third Party Services
|--------------------------------------------------------------------------
|
| This file is for storing the credentials for third-party services such
| as Mailgun, Postmark, AWS, and more. This file provides the de facto
| location for this type of information, allowing packages to have
| a conventional file to locate the various service credentials.
|
*/
'mailgun' => [
'domain' => env('subdomain.domain.ca'),
'secret' => env('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'),
],
'postmark' => [
'token' => env('POSTMARK_TOKEN'),
],
'ses' => [
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
],
];
This is in my mail.php:
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Mailer
|--------------------------------------------------------------------------
|
| This option controls the default mailer that is used to send any email
| messages sent by your application. Alternative mailers may be setup
| and used as needed; however, this mailer will be used by default.
|
*/
'default' => env('MAIL_MAILER', 'mailgun'),
/*
|--------------------------------------------------------------------------
| Mailer Configurations
|--------------------------------------------------------------------------
|
| Here you may configure all of the mailers used by your application plus
| their respective settings. Several examples have been configured for
| you and you are free to add your own as your application requires.
|
| Laravel supports a variety of mail "transport" drivers to be used while
| sending an e-mail. You will specify which one you are using for your
| mailers below. You are free to add additional mailers as required.
|
| Supported: "smtp", "sendmail", "mailgun", "ses",
| "postmark", "log", "array"
|
*/
'mailers' => [
'smtp' => [
'transport' => 'smtp',
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'timeout' => null,
'auth_mode' => null,
],
'ses' => [
'transport' => 'ses',
],
'mailgun' => [
'transport' => 'mailgun',
],
'postmark' => [
'transport' => 'postmark',
],
'sendmail' => [
'transport' => 'sendmail',
'path' => '/usr/sbin/sendmail -bs',
],
'log' => [
'transport' => 'log',
'channel' => env('MAIL_LOG_CHANNEL'),
],
'array' => [
'transport' => 'array',
],
],
/*
|--------------------------------------------------------------------------
| Global "From" Address
|--------------------------------------------------------------------------
|
| You may wish for all e-mails sent by your application to be sent from
| the same address. Here, you may specify a name and address that is
| used globally for all e-mails that are sent by your application.
|
*/
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'info#domain.ca'),
'name' => env('MAIL_FROM_NAME', 'From name'),
],
/*
|--------------------------------------------------------------------------
| Markdown Mail Settings
|--------------------------------------------------------------------------
|
| If you are using Markdown-based email rendering, you may configure your
| theme and component paths here, allowing you to customize the design
| of the emails. Or, you may simply stick with the Laravel defaults!
|
*/
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
This is how I am sending the mail in my controller:
Mail::send('emailtemplates.trackeremail', $data, function($message)use($data, $pdf) {
$message->to($data["toaddress"])
->cc($data["ccaddress"])
->subject($data["title"])
->attachData($pdf->output(), "PDFName.pdf");
});
This is working when I send to mailgun via SMTP in my local environment but I am unfortunately limited to shared hosting that does not allow 3rd party SMTP and I need to switch to the API method for production. I have gone through many tutorials and questions on this site (and others) related but nothing has solved my issue.
I always run php artisan config:clear after any kind of .env change.
Is there anything else that I can be doing to even get an error message or further debug this? Any help would be appreciated.
It might possibly be the port, host, encryption, and mail from:
Keep these as is in your .env:
MAIL_MAILER=mailgun
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
Enter these in your .env:
MAIL_FROM_NAME=YourNameHere
MAIL_FROM_ADDRESS=enter#theemail.com
MAIL_FROM=enter#theemail.com
MAILGUN_DOMAIN=subdomain.domain.ca
MAILGUN_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxx
Update services.php with:
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'),
],
Update mail.php with adding:
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'port' => env('MAIL_PORT', 587),
After going over this with A2 Hosting's technical support it turns out that this is just not possible with their shared hosting, I was informed that "Mailgun only supports the standard SMTP ports, so it is not supported on our shared server".

laravel log system with logstash

I have a laravel application that I want to store my logs into my logstash and see them in kibana i searched a lot over the net to find a solution for it but I didnt find any good source for it, is there any package to use laravel logs into logstash ???
by the way I have my logstash and kibana running without any problem I just need a source of data now .
and here is my elstic search running :
{
name: "5351ced3b7a4",
cluster_name: "elasticsearch",
cluster_uuid: "Ej5TRN8CQyGvemZlT3gAFA",
version: {
number: "7.1.1",
build_flavor: "oss",
build_type: "tar",
build_hash: "7a013de",
build_date: "2019-05-23T14:04:00.380842Z",
build_snapshot: false,
lucene_version: "8.0.0",
minimum_wire_compatibility_version: "6.8.0",
minimum_index_compatibility_version: "6.0.0-beta1"
},
tagline: "You Know, for Search"
}
EDIT
as the answer explains the way I did and now I get this error in my logs in laravel :
[2019-08-05 14:16:17] laravel.INFO: Hello logstash!
EDIT :
The Logging Config file :
<?php
use Monolog\Handler\StreamHandler;
use Monolog\Handler\SyslogUdpHandler;
return [
/*
|--------------------------------------------------------------------------
| Default Log Channel
|--------------------------------------------------------------------------
|
| This option defines the default log channel that gets used when writing
| messages to the logs. The name specified in this option should match
| one of the channels defined in the "channels" configuration array.
|
*/
'default' => env('LOG_CHANNEL', 'stack'),
/*
|--------------------------------------------------------------------------
| Log Channels
|--------------------------------------------------------------------------
|
| Here you may configure the log channels for your application. Out of
| the box, Laravel uses the Monolog PHP logging library. This gives
| you a variety of powerful log handlers / formatters to utilize.
|
| Available Drivers: "single", "daily", "slack", "syslog",
| "errorlog", "monolog",
| "custom", "stack"
|
*/
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['daily'],
'ignore_exceptions' => false,
],
'single' => [
'driver' => 'single',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
],
'daily' => [
'driver' => 'daily',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
'days' => 14,
],
'slack' => [
'driver' => 'slack',
'url' => env('LOG_SLACK_WEBHOOK_URL'),
'username' => 'Laravel Log',
'emoji' => ':boom:',
'level' => 'critical',
],
'papertrail' => [
'driver' => 'monolog',
'level' => 'debug',
'handler' => SyslogUdpHandler::class,
'handler_with' => [
'host' => env('PAPERTRAIL_URL'),
'port' => env('PAPERTRAIL_PORT'),
],
],
'stderr' => [
'driver' => 'monolog',
'handler' => StreamHandler::class,
'formatter' => env('LOG_STDERR_FORMATTER'),
'with' => [
'stream' => 'php://stderr',
],
],
'syslog' => [
'driver' => 'syslog',
'level' => 'debug',
],
'errorlog' => [
'driver' => 'errorlog',
'level' => 'debug',
],
'logstash' => [
'driver' => 'custom',
'via' => \App\LogstashLogger::class,
'host' => env('LOGSTASH_HOST', '127.0.0.1'),
'port' => env('LOGSTASH_PORT', 9200),
],
],
];
As explained in this post it's quite easy to do.
Configure a logging channel in config/logging.php (docs)
'channels' => [
// ... other channels like stack or single
'logstash' => [
'driver' => 'custom',
'via' => \App\LogstashLogger::class,
'host' => env('LOGSTASH_HOST', '127.0.0.1'),
'port' => env('LOGSTASH_PORT', 4718),
],
],
Create a custom Logger factory (docs)
namespace App;
use Monolog\Formatter\LogstashFormatter;
use Monolog\Handler\SocketHandler;
use Monolog\Logger;
use Psr\Log\LoggerInterface;
class LogstashLogger {
/**
* #param array $config
* #return LoggerInterface
*/
public function __invoke(array $config): LoggerInterface
{
$handler = new SocketHandler("udp://{$config['host']}:{$config['port']}");
$handler->setFormatter(new LogstashFormatter(config('app.name')));
return new Logger('logstash.main', [$handler]);
}
}
This will write logs via udp to the specified host and port using the monolog logstash formatter
To now write log entries to logstash specify the logging channel you just created (docs)
Log::channel('logstash')->info('Hello logstash!');
This wasn't working for me because of the UCP socket connection, rather than debugging it I just changed it to TCP and it worked.
I first tested it on the command line:
echo "hello world!" | nc 127.0.0.1 5000
If that doesn't work, then you need to update your elastic configuration, otherwise s/udp/tcp.
$handler = new SocketHandler("tcp://127.0.0.1:5000");
$formatter = new LogstashFormatter('EXAMPLE');
$handler->setFormatter($formatter);
$logger = new Logger('logstash.main', [$handler]);

Laravel Lumen Logging not working on production

I have a small project on Laravel/Lumen where I use logging messages like this
Log::info('User failed to login.',
['Env token' => $this->envToken, 'Request token' =>$request->header('Authorization')]);
I can check my log in storage/logs/lumen.log just fine. The problem is when I push it to my vps where the log stops working. In there I ran composer install --no-dev to install the production dependencies only.
Is there a required dev dependency for logging or it can be something else??
More info:
Vendor/laravel/lumen-framework/config/logging.php (I haven't change it, so it's by default)
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Log Channel
|--------------------------------------------------------------------------
|
| This option defines the default log channel that gets used when writing
| messages to the logs. The name specified in this option should match
| one of the channels defined in the "channels" configuration array.
|
*/
'default' => env('LOG_CHANNEL', 'stack'),
/*
|--------------------------------------------------------------------------
| Log Channels
|--------------------------------------------------------------------------
|
| Here you may configure the log channels for your application. Out of
| the box, Laravel uses the Monolog PHP logging library. This gives
| you a variety of powerful log handlers / formatters to utilize.
|
| Available Drivers: "single", "daily", "slack", "syslog",
| "errorlog", "custom", "stack"
|
*/
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['single'],
],
'single' => [
'driver' => 'single',
'path' => storage_path('logs/lumen.log'),
'level' => 'debug',
],
'daily' => [
'driver' => 'daily',
'path' => storage_path('logs/lumen.log'),
'level' => 'debug',
'days' => 7,
],
'slack' => [
'driver' => 'slack',
'url' => env('LOG_SLACK_WEBHOOK_URL'),
'username' => 'Lumen Log',
'emoji' => ':boom:',
'level' => 'critical',
],
'syslog' => [
'driver' => 'syslog',
'level' => 'debug',
],
'errorlog' => [
'driver' => 'errorlog',
'level' => 'debug',
],
],
];
.env file
APP_ENV=local
APP_DEBUG=true
APP_KEY=stuffkey
APP_TIMEZONE=UTC
LOG_CHANNEL=stack
LOG_SLACK_WEBHOOK_URL=
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=stuffdb
DB_USERNAME=stuffuser
DB_PASSWORD=stuffkey
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
RESTTOKEN=blablablabla

Laravel Iron Queue::push doesn't seem asynchronous

I have a form which allows the user to input some text and upload an image (the image is then resized and sent to TinyPNG.com for optimisation).
Upon clicking on the submit button the form sends data via JQuery AJAX. I'd like to show the user some message via On Success in the AJAX function, after the data posting is complete but without waiting for the image manipulation processes. To do this, I created a Laravel Queue with Iron, with the code below:
\Queue::push('RenameClassImage',[$_POST['temp_img_id'], $class_id,$final_path,$_POST['crop_w'],$_POST['crop_h'],$_POST['crop_x'],$_POST['crop_y']]);
Overall everything works fine, except the AJAX success function only triggers AFTER the entire image manipulation process is complete (which takes a really long time).
Below is my queue config file. If you'd like me to include any other code please let me know. Thanks in advance
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Queue Driver
|--------------------------------------------------------------------------
|
| The Laravel queue API supports a variety of back-ends via an unified
| API, giving you convenient access to each back-end using the same
| syntax for each one. Here you may set the default queue driver.
|
| Supported: "null", "sync", "database", "beanstalkd",
| "sqs", "iron", "redis"
|
*/
'connections' => [
'sync' => [
'driver' => 'sync',
],
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'expire' => 60,
],
'beanstalkd' => [
'driver' => 'beanstalkd',
'host' => 'localhost',
'queue' => 'default',
'ttr' => 60,
],
'sqs' => [
'driver' => 'sqs',
'key' => 'your-public-key',
'secret' => 'your-secret-key',
'queue' => 'your-queue-url',
'region' => 'us-east-1',
],
'iron' => [
'driver' => env('QUEUE_DRIVER'),
'host' => env('QUEUE_HOST'),
'token' => env('QUEUE_TOKEN'),
'project' => env('QUEUE_PROJECT'),
'queue' => env('QUEUE_NAME'),
'encrypt' => true,
],
'redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => 'default',
'expire' => 60,
],
],
/*
|--------------------------------------------------------------------------
| Failed Queue Jobs
|--------------------------------------------------------------------------
|
| These options configure the behavior of failed queue job logging so you
| can control which database and table are used to store the jobs that
| have failed. You may change them to any database / table you wish.
|
*/
'failed' => [
'database' => 'mysql', 'table' => 'failed_jobs',
],
];
In your .env file you have to set the queue:
QUEUE_DRIVER=iron

Categories