NGrok and Laravel - laravel

I want to deploy my local larvel website online with NGROK.
I'm using Laragon with Apache server, I use this command :
ngrok http -host-header=rewrite site.dev:80
It almost work, but the asset file (like CSS/Image) are still link to my local server (site.dev). And it's the same for my link, the laravel routing command :
{{ route('ngo') }} return site.dev/ngo instead of my online tunnel (http://number.ngrok.io/ngo)
I've try to :
Edit the http.conf (https://forum.laragon.org/topic/88/allow-outside-other-devices-phones-tablets-to-access-your-local-server-using-ngrok)
Change my Laravel App url in config/app.php
Change my url in .env file
Nothings work

I ran into this problem myself just now, but also found a way to fix it:
Run the ngrok command without the -host-header=rewrite part, resulting in
ngrok http site.dev:80
After this, edit your http.conf file and add the ngrok domain as a server alias. For example:
ServerAlias nd3428do.ngrok.io
The problem is that Laravel's route helper uses the HOST header, which is rewritten to site.dev. Without the -host-header part, the header isn't rewritten and now it works.

Related

How can I use Valet to serve 2 directories on a subdomain like api.domain.test and spa.domain.test?

I have tried valet link api.domain but it shows 502 Bad Gateway. My folder structure is basically very simple. I am using valet park on ~/Sites and there is a backend and frontend folder in that ~/Sites directory. I basically want to access api.domain.test and spa.domain.test instead of backend.test and frontend.test.
The reason is using Laravel Sanctum with XSRF cookie protection. The domain + TLD must be same for the cookies to work. I have also tried valet proxy but that only worked properly for frontend.test being mapped to localhost:3000 where I serve my Next.js. Any help would be appreciated. Thanks.
Have you tried the following
cd ~/Sites/backend
valet link api.domain
cd ~/Sites/frontend
valet link spa.domain
valet proxy spa.domain http://127.0.0.1:3000

How to remove "public/index.php" on server?

I m newly working on laravel.
I created laravel project named as "blog" on localhost and for removing public/index.php, I followed following process :
cut and pasted .htaccess from public/ folder to root i.e. blog
Renamed the server.php to index.php
Then I created a test api in api.php route and echoed "Hello World".
Now when I go to project path from my localhost server like:
localhost/Blog/api/test then its work properly.
But when I run same on a server like 192.101.111.555,like :
192.101.111.555/Blog/api/test then it showing NOT FOUND.
I am not getting how can I resolve this. And why its working fine on localhost but not working on server ?
You rename server.php but not recommend. This file copy then rename
Yes, if you have done those settings you will not be able to properly access on the localhost by running php artisan serve. So for this, you can install xampp and do the virtual host settings. Check more info at
How to enable Virtual Host on Xampp for Laravel?.
On the benefit of this is that you don't have to run the php artisan serve command again and again.

Programmatic ngrok tunnel url

I'm trying to get ngrok's dynamically generated IP address programmatically by using bash to set globals and env variables.
Below is what I have so far.
Run ngrok http {server url}
Inside your host root directory run:
curl http://localhost:4040/api/tunnels > ~/ngrok_tunnels.json;
Install jq
Brew install [jq](https://stedolan.github.io/jq/) (let's you access json through bash)
Afterwards you just need to access this json following jq's docs.
Inside the project root that is calling the dev URL. [0]=(http) [1]=(https)
echo “NGROK_TUNNEL=$(jq .tunnels[1].public_url ~/ngrok_tunnels.json
)" >> .env
Set all of your dev urls to process.env.NGROK_TUNNEL
So this works, but is it the "best way" to do this?
For people who want to get a url through ngrok using python there is the pyngrok library
from pyngrok import ngrok
#Open a HTTP tunnel on the default port 80
#<NgrokTunnel: "http://<public_sub>.ngrok.io" -> "http://localhost:80">
http_tunnel = ngrok.connect()
#Open a SSH tunnel
#<NgrokTunnel: "tcp://0.tcp.ngrok.io:12345" -> "localhost:22">
ssh_tunnel = ngrok.connect(22, "tcp")
it is also possible to do some things directly via the ngrok API. I didn't find the option to create a tunnel, but having a tunnel created you can restart it or update it
https://ngrok.com/docs/api#api-tunnel-sessions-list
The short answer is yes.
You can upgrade to a paid plan and use the --subdomain argument to get the same ngrok url every time. The next price level from that includes white labeling where you can use your own custom domain as well.

Xampp localhost not working

I am running laravel on xampp and I have problem with accessing pages,
http://localhost/laravel/public/ I get a login page which is good
however when I go for example http://localhost/laravel/public/smokeyard
I get 404 error with The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.
Route:
Route::get('smokeyard', 'GuzzleController#smokeyard');
Controller:
function smokeyard(){
return view('smokeyard');
}
All my views are located in resources folder.
if you want to access laravel project without running artisan serve, you need to change few settings,
copy the .htaccess file from the public folder and paste it in the root folder of your application
rename the server.php in the root directory to index.php
now go to localhost/your_project_name/smokeyard for the url you want to check
hope this helps
Run php artisan serve and access your server at http://localhost:8000. Your routes should work fine then.
You can't access your laravel application routes straight away through the folder structure with xampp. You need to setup the web root to point to the public folder and access localhost or run the laravel server and use it. This is because the url rewriting would fail when you access the routes in laravel the way you do.
I tried this in MX Linux 21.xx. My xampp got messed up after installing larvel on it.
check MySQL status with command
mysql service status
stop the service using the command
service mysql stop
you will be prompted to provide your password, Enter password.
start xampp using command
sudo /opt/lampp/lampp start
All should be back to normal

Lumen not working out of the box

Just installed Lumen framework.
hit the link http://localhost/lumen/public/ in my browser and got this following error, anyone got any idea about it?
Traced it back to the app.php file in bootstrap folder.
if You want to access lumen project without "php artisan serve"
$app->run(); replace with
$request = Illuminate\Http\Request::capture();
$app->run($request);
from this path yourlumenproject/public/index.php
Open your terminal in the root folder run the following command php artisan serve.
Lumen development server started on http://localhost:8000/
if you want to serve your app in local development you can do this :
php -S localhost:8000 -t public/
and it will serve in localhost in port 8000. hope this help.
Note : I'm using Laravel Framework version Lumen (5.2.4) (Laravel Components 5.2.*)
At the moment Lumen only runs in the domain root.
(I've submitted a PR that fixes this but it has yet to be merged)
You have to create a Virtual Host on your local webserver and point the document root of that to the public directory. After that you can access your app with something like: http://lumen.dev.
Guide for Virtual Hosts with nginx
Guide for Virtual Hosts with Apache
A simple alternative to setting this up manually is Laravel Homestead. It is an official Vagrant box made for Laravel, that allows you to easily get your development environment up and running.

Resources