Import not working
When I use import in a PHP script to import another PHP script it doesn't work locally (it works after building though).
I have index.php:
<?php
include '/config.php';
echo $test
?>
and config.php:
<?php
define("test", "testing");
?>
vite.config.ts:
import usePHP from 'vite-plugin-php';
export default defineConfig({
plugins: [usePHP({ binary: '/opt/homebrew/bin/php', entry: ['index.php', 'config.php', 'get-access/index.php'],})],
});
When opening the page I get this error:
Warning: include(/config.php): Failed to open stream: No such file or directory in /Users/martinhell/Documents/quantumcode/slaice-website/node_modules/vite-plugin-php/dist/router.php(14) : eval()'d code on line 17
Warning: include(): Failed opening '/config.php' for inclusion (include_path='.:/opt/homebrew/Cellar/php/8.2.12_1/share/php/pear') in /Users/martinhell/Documents/quantumcode/slaice-website/node_modules/vite-plugin-php/dist/router.php(14) : eval()'d code on line 17
This is how PHP works. It is trying to include config.php from the ROOT of your server.
/ is the root directory on a Linux system.
You should be able to include the file without the slash, or you can always use relative imports.
Ok thanks.
This doesn't seem to work even if it works on production:
<form class="flex center wrap" id="registrationForm" method="post" action="./register.php'?>">
The server is never returning a value it seems.
The most recent version of the plugin has a error catcher build in. Now you should be able to see the error causing the page to be blank.