I am creating a mobile application(flutter) that works with api on Laravel. The api should work but there are problems. I’m trying to figure it out, although I don’t have previous experience with Laravel (I have experience with PHP). so on server Cpanel. when i try to call the api i get an error
404 Not Found
body:
The requested URL was not found on this server.
Additionally, a 404 Not Found
error was encountered while trying to use an ErrorDocument to handle the request
This is a fairly common problem, the points I checked are the following points.
-
the api is in the public_html folder, some folders inside:
app routes bootstrap
-
checked file public_html/.htaccess
# php -- BEGIN cPanel-generated handler, do not edit # Set the “ea-php74” package as the default “PHP” programming language. <IfModule mime_module> AddHandler application/x-httpd-ea-php74 .php .php7 .phtml </IfModule> # php -- END cPanel-generated handler, do not edit
I changed it to:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
-
executed the following commands
php artisan route:clear php artisan route:cache
after that i execute the command
php artisan route:list
result:
I try the following options for the url:
https://appdomain.com/api/v1/login
https://appdomain.com/api/v1/Check-login
https://appdomain.com/api/v1/user-login
https://appdomain.com/api/login
https://appdomain.com/api/Check-login
https://appdomain.com/api/user-login
https://appdomain.com/login
https://appdomain.com/Check-login
https://appdomain.com/user-login
but each of these urls return a 404 error.
-
Laravel – version 5.5.50
-
part of api.php
Route::group(['prefix' => 'v1'], function () { Route::post('/user-login',['as' => 'login','uses' => 'apiv1UserController@user_login']); });
7. when I added file public_htm/index.php – any request to api returns that file
Which url is correct?
What else can I check?
How can this be fixed?
Any advice – I will be very grateful.
3
Answers
Place .htaccess file into root directory of your project . public_html/.htaccess
The first thing you should do is to verify if your request actually hits your Laravel Application. There are number of ways you can do this, like adding additional testing routes in
web.php
orapi.php
Addtionally, you may install clockwork and capture all the request, so you can also easily see if your request actually hits the laravel app.
If it hits your Laravel application, turn on the debug mode in your
env
file and put the application in development mode, then try checking the laravel logs for any error.If your request is not hitting the laravel application, then its something related to your server configuration or laravel installation configuration.
Normally, the root folder for laravel application is in
laravel-root-directory/public/
which should be the root folder when configuring the domain, but I’ve seen people where they move the root folder to actual laravel app root and not insidepublic
folderMethod 1:
Change Document Root to
public_html/public
and upload the source code topublic_html
.Method 2:
Upload the source code except
public
folder to the parent folder ofpublic_html
folder. And upload the files inpublic
folder topublic_html
folder.Add the following code to
public_html/index.php
: