Skip to main content

Install Mixpost Enterprise In an existing Laravel app

If you are using Laravel (v10 or v11), it's recommended to install Mixpost Enterprise as a package within your application. This approach is ideal for those already familiar with Laravel.

Getting a license

In order to install Mixpost Enterprise, you’ll need to get a license first.


Server requirements

Before proceeding, please review the server requirements to ensure that Mixpost functions properly.

1. Installing via Composer

First, add the packages.inovector.com repository to your composer.json.

"repositories": [
{
"type": "composer",
"url": "https://packages.inovector.com"
}
],

Next, you need to create a file called auth.json and place it either next to the composer.json file in your project or the composer home directory. Using this command, you can determine the composer home directory on Unix machines.

composer config --list --global | grep home

This is the content you should put in auth.json:

{
"http-basic": {
"packages.inovector.com": {
"username": "<YOUR-MIXPOST.APP-ACCOUNT-EMAIL-ADDRESS-HERE>",
"password": "<YOUR-LICENSE-KEY-HERE>"
}
}
}

To validate if Composer can read your auth.json you can run this command:

composer config --list --global | grep packages.inovector.com

If you did everything correctly, the above command should display your credentials. If that command doesn't display anything, verify that you created an auth.json as mentioned above.

With this configuration in place, you'll be able to install the package into your Laravel project using this command:

composer require inovector/mixpost-enterprise "^4.0"

After installing the Mixpost package, you may execute these 2 commands:

php artisan mixpost:install
php artisan mixpost-enterprise:install

To ensure that the assets get republished each time Mixpost Enterprise is updated, we strongly advise you to add the following command to the post-update-cmd of the scripts section of your composer.json.

"scripts": {
"post-update-cmd": [
"@php artisan mixpost:publish-assets --force=true",
"@php artisan mixpost-enterprise:publish-assets --force=true"
]
}

2. Job Batching

Mixpost uses Job Batching and you should create a database migration to build a table to contain meta information about your job batches.

If your application does not yet have this table, it may be generated using the:

php artisan queue:batches-table

Run the migrations with:

php artisan migrate

3. Publish the config file

Optionally, you can publish the config file with this command:

php artisan vendor:publish --tag=mixpost-config

4. CSRF Protection

Exclude payment webhook handler route From CSRF protection by adding the URI */payment-webhook to the $except property of the VerifyCsrfToken middleware:

<?php

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;

class VerifyCsrfToken extends Middleware
{
/**
* The URIs that should be excluded from CSRF verification.
*
* @var array<int, string>
*/
protected $except = [
'*/payment-webhook'
];
}

5. Error Reporting

Mixpost utilizes its unique internal exception handler rather than the default App\Exceptions\ExceptionHandler. To integrate external error reporting tools with your Mixpost setup, you should use the Mixpost::report method. Generally, this method is called from the register method of your app's App\Providers\AppServiceProvider class:

use Inovector\Mixpost\Mixpost;
use Sentry\Laravel\Integration;

Mixpost::report(function($exception) {
Integration::captureUnhandledException($exception);
});

6. Install Horizon

Mixpost handles various tasks in a queued way via Laravel Horizon. If your application doesn't have Horizon installed yet, follow their installation instructions.

After Horizon is installed, don't forget to set QUEUE_CONNECTION in your .env file to redis.

config/horizon.php should have been created in your project. In this config file, you must add a block named mixpost-heavy to both the production and local environment.

'environments' => [
'production' => [
'supervisor-1' => [
'maxProcesses' => 10,
'balanceMaxShift' => 1,
'balanceCooldown' => 3,
],
'mixpost-heavy' => [
'connection' => 'mixpost-redis',
'queue' => ['publish-post'],
'balance' => 'auto',
'processes' => 8,
'tries' => 1,
'timeout' => 60 * 60,
],
],

'local' => [
'supervisor-1' => [
'maxProcesses' => 3,
],
'mixpost-heavy' => [
'connection' => 'mixpost-redis',
'queue' => ['publish-post'],
'balance' => 'auto',
'processes' => 3,
'tries' => 1,
'timeout' => 60 * 60,
],
],
],

In the config/queue.php file you must add the mixpost-redis connection:

'connections' => [

// ...

'mixpost-redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => env('REDIS_QUEUE', 'default'),
'retry_after' => 11 * 60,
'block_for' => null,
],

Don't forget to run php artisan horizon. In production, you need a way to keep your horizon processes running. For this reason, you need to configure a process monitor like Supervisor that can detect when your horizon processes exit and automatically restart them.

Before configuring a Supervisor process monitor, make sure you have installed Redis and Supervisor on your server.

Create mixpost_horizon.conf file inside of /etc/supervisor/conf.d folder and put this content:

[program:mixpost_horizon]
process_name=%(program_name)s
command=php /path-to-your-project/artisan horizon
autostart=true
autorestart=true
user=your_user_name
numprocs=1
startsecs=1
redirect_stderr=true
stdout_logfile=/var/log/supervisor/horizon.log
stdout_logfile_maxbytes=5MB
stdout_logfile_backups=3
stopwaitsecs=5
stopsignal=SIGTERM
stopasgroup=true
killasgroup=true

Once the configuration file has been created, you may update the Supervisor configuration and start the processes using the following commands:

sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start mixpost_horizon:*

7. Schedule the commands

In the console kernel app/Console/Kernel.php, you should schedule these command:

protected function schedule(Schedule $schedule)
{
// ...
\Inovector\MixpostEnterprise\Schedule::register($schedule);

$schedule->command('horizon:snapshot')->everyFiveMinutes();
$schedule->command('queue:prune-batches')->daily();
}

8. WebSocket (Optional)

This configuration enables real-time message updates in the post chat discussion. This step is optional.

Mixpost supports 2 WebSocket drivers:

DriverTypeConfiguration Difficulties
PusherSaaSLow
Laravel ReverbSelf-hostedHigh

Pusher

To get started with Pusher, register on their platform, create a new channel, and retrieve your app keys.

  1. Update .env file:

BROADCAST_DRIVER=pusher

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
  1. Optimize application:

php artisan optimize
  1. Terminate the Horizon process:

php artisan horizon:terminate

Laravel Reverb

  1. Update .env file:

BROADCAST_DRIVER=reverb

REVERB_APP_ID=insert_unique_id
REVERB_APP_KEY=insert_random_key
REVERB_APP_SECRET=insert_random_key
REVERB_HOST="example.com" # use "localhost" for testing on your localhost
REVERB_PORT=80 # use 8080 for testing on your localhost
REVERB_SCHEME=https
  1. Optimize application:

php artisan optimize
  1. Add to Supervisor

Create mixpost_reverb.conf file inside of /etc/supervisor/conf.d folder and put this content:

[program:mixpost_reverb]
process_name=%(program_name)s
command=php /path-to-your-project/artisan reverb:start --no-interaction
autostart=true
autorestart=true
user=your_user_name
numprocs=1
startsecs=1
redirect_stderr=true
stdout_logfile=/var/log/supervisor/reverb.log
stdout_logfile_maxbytes=5MB
stdout_logfile_backups=3
stopwaitsecs=5
stopsignal=SIGTERM
stopasgroup=true
killasgroup=true

Once the configuration file has been created, you may update the Supervisor configuration and start the processes using the following commands:

sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start mixpost_reverb:*
  1. Terminate the Horizon process:

php artisan horizon:terminate

Due to the long-running nature of WebSocket servers, you may need to make some optimizations to your server and hosting environment to ensure your Reverb server can effectively handle the optimal number of connections for the resources available on your server. Read here about running Reverb in production.

9. Create an admin

info

If your users table is empty, skip to step 9.

To access the Mixpost Dashboard, you must create an admin. Please execute the following command:

php artisan mixpost:create-admin

10. Done

After performing all these steps, you should be able to visit the Mixpost Dashboard at /mixpost.