Skip to main content

Install Mixpost Enterprise In an existing Laravel app

If you are using Laravel (v9 or v10), 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.


warning

Before proceeding, please review the server requirements and install all necessary softwares 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 "^3.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
stopwaitsecs=3600

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. 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

9. Done

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