skip to Main Content

I have a laravel project contains an RestFull API. I want to access to this API from android studio. I use retrofit library.When I run server through artisan, can’t access localhost laravel app routes to android studio.According to this question accessing-localhost-laravel-app-routes-to-android-studio-failed, I change base url to http://192.168.1.103:8000/halamooz/public/api/ and run the laravel app with apache server.For this work, I follow this guideline Laravel practical guide for using XAMPP.Of course I don’t use XAMPP and install apache server individually. I access web route from browser but when I try to access API route from postman or android studio I receive 404 page not founded error.What is my mistake?
I put this lines in httpd-vhosts file:

 <VirtualHost *:80>
DocumentRoot "C:/apache/htdocs/halamooz/public"
ServerName exampledomain.com
ServerAlias exampledomain.com
<Directory "C:/apache/htdocs/halamooz/public">
AllowOverride All
Require all Granted
</Directory>
</VirtualHost>

2

Answers


  1. Chosen as BEST ANSWER

    I finally did these steps and My problem solved.

    • Step 1: Put your laravel project into C:apachehtdocs.
    • Step 2: Run as administrator notepad app and open hosts file from C:WindowsSystem32driversetc path and add this line to end of file.

    127.0.0.1 exampledomain.com www.exampledomain.com

    • Step 3: Open httpd-vhosts file from C:apacheconfextra path and add these lines to end of file:

      <VirtualHost *:80>
      DocumentRoot "C:/apache/htdocs/NameOfProject/public"
      ServerName exampledomain.com 
      ServerAlias exampledomain.com 
      <Directory "C:/apache/htdocs/NameOfProject/public">
      AllowOverride All
      Require all Granted
      

    • Step 4:Uncomment this line from C:apacheconfhttpd.conf file.

    Include conf/extra/httpd-vhosts.conf

    • Step 5:Use this Url to access API in postman or android studio project.

    http://{IPv4 of your computer}:8000/{ProjectName}/public/api/{desired method} For example: http://192.168.1.3:8000/halamooz/public/api/login

    • Notice: Your Android device and computer must be on a same network Internet.

  2. In httpd.conf file find

    Listen 80 
    

    and below that write

    Listen 8060
    

    Then goto httpd-vhosts.conf

    <VirtualHost *:8060>
        ServerAdmin [email protected]
        DocumentRoot "C:/apache/htdocs/halamooz/public"
        ServerName dummy-host2.example.com
        ErrorLog "logs/dummy-host2.example.com-error.log"
       CustomLog "logs/dummy-host2.example.com-access.log" common
    </VirtualHost>
    

    Replace DocumentRoot with your path of project. Hope this help you

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search