When I'm doing a post request using AJAX, I'm getting this error:
PHP Parse error: syntax error, unexpected '/*' (T_STRING), expecting ')' in /home/laravel/public_html/public/index.php on line 47
PHP Fatal error: require(): Failed opening required '/home/user/public_html/vendor/ClassLoader.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/user/public_html/vendor/autoload.php on line 6
The index.php it's referring to is as following:
<?php
require __DIR__.'/../../laravel/bootstrap/autoload.php';
$app = require_once __DIR__.'/../../laravel/bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
$response->send();
$kernel->terminate($request, $response);
I have no idea why this is happening.
This only happens in safari and a few other browsers. Doesn't happen on chrome.
The inspect element looks like this:
Please help guys. Thanks
Edit: Folder structure:
home/user/laravel -> All my laravel files
home/user/laravel/public_html/public -> my public folder
When I do composer install
, it gives me this error:
Warning: Composer should be invoked via the CLI version of PHP, not the cgi-fcgi SAPI
Composer could not find a composer.json file in /usr/bin
For some reason, it's looking for composer.json file in /usr/bin. The composer.json file is in the current directory in which I am cd'd to.
Edit: index.php should look like this:
<?php
require __DIR__.'/../../bootstrap/autoload.php';
$app = require_once __DIR__.'/../../bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
$response->send();
$kernel->terminate($request, $response);
That will hopefully do the trick.
The first line of any PHP file should be
<?php
Somehow that's missing in your copy of the index file. I'm not sure how that happened, but that would be the error you're seeing.
I had the same issue. Exact same. It was happening only on HTTPS.
Here's what I did:
First thing's first. Run these commands:
php artisan cache:clear
chmod -R 777 app/storage
composer dump-autoload
php artisan optimize
Then run
npm install
Make sure that in your public_html folder, there is no index.html
or index.php
file. It should only be in the public_html/public
folder.
After that, ensure that you Htaccess is set up properly.
Htaccess in public_html
directory should be something like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
After doing the following, let me know how it goes. Also, be sure to look at the log file in storage/logs/laravel.log and your Apache logs.
Cheers!