Change the folder Structure It helps most of the time
api routes not working on live server
the api routes in my laravel project works fine in localhost, when it is served by php server from localhost. But it doesn't work on the live server when it is served by apache in the live server.
When i try to do this, it throws me a 404 error (Page not found).
Please how do you advice i solve this?
@vibe what folder structure to change?
Can you show one of the methods that fails? And the route
If you have a firstOrFail without exception handling it could give you issues
I think it is a configuration issue, if you have deployed laravel on apache before, please advice on how api routes can be directed to routes/api.php instead of web.php becasue that's what i think is the cause
Which laravel version are you using? You can just check your RouterServiceProvider. It should have the api route handler
it is deployed on a vps server, an ubuntu 18.04 server running apache and php, how do I change the folder structure???
Sir @sinnbeck the thing i that it works properly as intended on localhost, when I run php artisan serve and open localhost:8000/api/route but it shows page not found error handler when I open www.projectx.com/api/route using postman
it's running Laravel 5.8
I assume that means that web routes work on the server? Can you run php artisan route:list on the server? Does it list the api routes?
yes web routes runs on server. but api routes doesn't work
but on localhost when I serve using php artisan serve, both works properly
Did you run php artisan route:list to check if they are listen?
If they are, can you post one of those that does not work?
the route:list command doesn't work on my project including route:cache because a lot of the project codebase doesn't follow some standard laravel conventions
That could make it quite hard for us to debug here sadly.
Can you try posting your api.php file? Or at least some of it. Is there auth of some kind on all routes? If not can you open the page in a regular browser?
but the web routes runs properly on the server, on the api routes doesn't work, both of them works on the localhost. do you think it has got to do with .htaccess??? or apache configuration probably???
In my mind I'm thinking what's the correct way to configure apache rewrite base??? do you think this might be the cause??? what exactly could be wrong???
on some routes in the api the is auth:api middleware but the routes I'm visiting has no auth.
Sadly I use nginx, but I have never run into issues where only a special url path didn't work. I don't see any way you could make that happen. Also I suppose your .htaccess is the default one? https://laravel.com/docs/6.x/installation#web-server-configuration
Just another thought. You don't by any chance have a folder called api in the /public directory?
<?php
use Illuminate\Http\Request;
use Twilio\Rest\Client;
use Carbon\Carbon;
use \App\Jobs\SendCashCodeSMS;
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
/* Route::middleware('auth:api')
->get('/user', function(Request $request) {
return $request->user();
}); */
Route::group(['prefix' => 'ussd'], function(){
Route::post('cashurban', 'USSDController@cashurban');
Route::get('transferpay', 'USSDController@transferpay');
Route::get('cashout', 'USSDController@cashout');
Route::get('ussdtransaction', 'USSDController@ussdtransaction');
Route::get('validatecharge', 'USSDController@validateCharge');
Route::post('/rave/callback', 'flutterwaveController@callback')->name('callback');
});
Route::group(['prefix' => 'pos'], function(){
Route::post('register-agent', 'POSController@MerchantOnboarding')->name('merchant_onboarding');
Route::post('agent-terminal', 'POSController@POSterminal')->name('pos_terminal');
Route::post('transaction/callback', 'POSController@CgateCallback')->name('pos_callback');
});
yes, my .htaccess is the default htaccess, and I don't have any folder api in the public/ directory
You have a lot of unused use statements in the file. Try removing them. (all of them)
Did you remember to run composer install on the server?
yeah I have all of those things in place.
those unused statements are actually commented out.
Did you solve the issue?
if you facing similar problem. please create a new thread.
zaghadon Did you find a solution?
I'm inn a similar situation although, I can see the route:list, just can't post/get my api endpints at https://www.stayinghome.uk/be/api/auth/login
I'm using laravel ^9.2, 2022 :p
The solution that worked for me in cent os usign httpd is from laravel 6 remove space: laravel. com/docs/6.x/installation#web-server-configuration
using the .htaccess in public folder works fine :) (without the .htacces all works, however the api routes no)
Please or to participate in this conversation.