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?
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?
Share Improve this question asked Oct 15, 2020 at 12:23 nn3112337nn3112337 1112 bronze badges 3 |1 Answer
Reset to default 0Okey 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.)
HTAccess
ffiles determine how Apache transfers the request to WP, they're not really the integral part of WP that people think they are ( but rather to tell Apache that if you have example/stuff/here, to loadindex.php
to generate the response and not try to find a file atstuff/here
. People who use Nginx don't even have HTAccess files. In this case you need to make sure that WP knows that all those routes are for that page, and then be able to either give Laravel the URL or have Laravel be able to figure it out – Tom J Nowell ♦ Commented Oct 15, 2020 at 15:22