Super Sale Limited Time 50% OFF for All-Access Plans
Save 50% Now

The Laravel project cannot access /api after deployment


After deploying the Laravel project on CentOS, try to access the link and find that the 404 page is automatically redirected, but the link access is normal, you can also log in to the default account normally.


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (6)


Hi,

Sorry, we do not have an example for the login API. You can consider checking this guide for the authentication login using the API.



Thanks



Hi,

In the /routes/api.php file, please try to add this route.


Route::get("/user", function (Request $request) {
return $request->user();
});


Then in the browser, go to page /api/user. I did try this, the page should display. Please check if your API route has auth required.

Thanks



It can be accessed normally, thank you. Another thing is whether you can share the /api/login sample code



Hi,

Have you set the routes for API? Please check this file. /routes/api.php

Thanks



I've determined that this file exists, it can be edited normally, it just can't be opened in the link



It should be the latest version, downloaded and deployed in the last week.

PHP:8.1.13(If PHP-8.0.26 is used, an error is reported with an old version)
Node:v18.12.1(If you use v-14.16.1, you will get an error that the version is low)
npm:9.2.0
pm2:5.2.2
yarn:1.22.19


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(