Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mastermarco's avatar

Api over virtual host and port?

I installed laravel passport and access my api over http://127.0.0.1:8000/api, that works. But I also have my valet virutalhost like https://myapp.test, I would wish to access now the api over https://myapp.test/api, is that possible? Will I have also api directly online on my domain?

0 likes
2 replies
Kishore032's avatar

If you are using valet, then 'valet share' will open an ngrok tunnel to your server (basically giving you a publicly addressible URL).

Now the API should work over the new ngrok url the same way as accessing it over 127.0.0.1.

If you are not using valet, you can still go to https://ngrok.com, create an account and follow instructions on how to create an ngrok tunnel to your local server.

First test with http.

To use https, you have to use 'valet secure' to create an encrypted connection. If not using valet, there are ways of creating a secure channel with MAMP & WAMP as well.

There are a couple of issues that took me a while to resolve which had to do with reinitializing the server and clearing the DNS cache. To avoid these, do the following:

  1. After you create a secure channel, restart your server. (restart valet or MAMP or better still, reboot your computer).

  2. Clear your DNS cache. On a mac, dscacheutil -flushcache && sudo killall -HUP mDNSResponder will do it.

Now your API should work over a secure virtual server.

Please or to participate in this conversation.