0

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>
maryam
  • 1,437
  • 2
  • 18
  • 40

2 Answers2

0

In httpd.conf file find

Listen 80 

and below that write

Listen 8060

Then goto httpd-vhosts.conf

<VirtualHost *:8060>
    ServerAdmin webmaster@dummy-host2.example.com
    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

Amol Rokade
  • 145
  • 1
  • 11
  • whats the error when you hit localhost:8060? first check your apache and localhost server working properly – Amol Rokade Oct 27 '18 at 09:32
  • I put your code In the httpd-vhosts.conf file and when I test localhost:8060 in the browser, It show a list of some folder but when I try in postman I receive 404 error – maryam Oct 27 '18 at 09:39
  • pass the below headers in postman and try again Content-type: application/json; – Amol Rokade Oct 27 '18 at 09:46
  • I did , but even didn't work. I give this url in postman: `http://localhost:8060/halamooz/public/api/login` – maryam Oct 27 '18 at 09:48
  • give it: `The requested URL /api/login was not found on this server.` – maryam Oct 27 '18 at 09:53
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/182627/discussion-between-amol-rokade-and-sarina). – Amol Rokade Oct 27 '18 at 09:57
0

I finally did these steps and My problem solved.

  • Step 1: Put your laravel project into C:\apache\htdocs.
  • Step 2: Run as administrator notepad app and open hosts file from C:\Windows\System32\drivers\etc 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:\apache\conf\extra 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:\apache\conf\httpd.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.
maryam
  • 1,437
  • 2
  • 18
  • 40