Include Lumen/Laravel app in custom WordPress template

I’ve built a small app with Lumen and now I want to include it on my wordpress site. However I have difficulty getting it to work. My approach was making a custom template and using it on a post with the URL I want. This is how it looks:

<?php /* Template Name: TestApp */ ?>

<?php
    /*
    |--------------------------------------------------------------------------
    | Create The Application
    |--------------------------------------------------------------------------
    |
    | First we need to get an application instance. This creates an instance
    | of the application / container and bootstraps the application so it
    | is ready to receive HTTP / Console requests from the environment.
    |
    */

    $app = require __DIR__.'/../../../../../my-app/bootstrap/app.php';

    /*
    |--------------------------------------------------------------------------
    | Run The Application
    |--------------------------------------------------------------------------
    |
    | Once we have the application, we can handle the incoming request
    | through the kernel, and send the associated response back to
    | the client's browser allowing them to enjoy the creative
    | and wonderful application we have prepared for them.
    |
    */

    $app->run();
?>

The $app path corresponds to a root level directory with the Lumen content inside. The idea was to use the /public/index.php as the template. It works so far, but when I query the site I get an NotFoundHttpException Error on the $app->run(); line, by RoutesRequests.php -> dispatch (line 108). I assume this is because the .htaccess isn’t there, however adding that doesn’t help.

How do I include standalone apps on a wordpress page?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Okey so what I did was not using a WordPress theme template and instead deploying the app how I normally would without WP (e.g. create the folder /my-apps/my-app and put the index and htaccess file in there). After that I wrapped the index.php manually with require '../../wp-load.php'; in the template functions (get_header() etc.)


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x