SSL Certificate on Laravel Development - laravel

I have an application which i am using 'php artisan serve' command to run it on my mobile. I want to test it on my mobile but i have an API which requires HTTPS. So how can i configure this? I want to test this before I put this live.
Here is how my artisan command looks like:
php artisan serve --host=192.168.1.18 --port=80
The IP is my local machines IP Address which i am accessing from my mobile.
I have tried looking up google but i couldn't find the answer i was looking for.
Thanks

You can use self-signed SSL for own server.
1 - Download the certificate.
2 - Add or edit this line in php.ini config:
curl.cainfo = "[path_to_cerfificate]\cacert.pem"
3 - Then restart your server
Done.

Related

If I run it on laravel localhost, it shows me only file, how to fix it

If I run laravel on localhost, it shows me only file, how to fix this
The main index.php file is in Laravel's public/ directory. If you visit http://localhost/Employee/public, you'll likely see your Laravel site.
If you point your webserver's DocumentRoot at that directory, you'll be able to visit the app at http://localhost/. If you want to run multiple apps locally, you'll want to start playing with virtualhosts.
Alternatively, consider using Laravel's Valet, Sail, or Homestead options for local development; each will handle this sort of thing for you. Sail is Laravel's current recommendation.
You can use a web server such as Apache or Nginx to serve your laravel applications. If you have PHP 5.4+ and would like to use PHP's built in development server you may use the serve artisan command:
cd /project_directory
php artisan serve
By Default it will run application on port 8000
If you want to change to other port specify port number like
php artisan serve --port=8080
It will run your application on the PHP development server on localhost:8080
Docs: https://laravel.com/docs/4.2/quick#local-development-environment

How to run laravel websockets in laragon?

How to run laravel websockets in laragon?
when run command to start websockets
php artisan websockets:serve
it's not working because
https://imgur.com/ODkZC8d
and its still suck there
https://imgur.com/6lzEOGX
this is error on browser
WebSocket connection to 'wss://nextlevelbot.test:6001/app/mykey?protocol=7&client=js&version=6.0.2&flash=false' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
It was my problem in SSL certifacates
I solve this problem by create SSL certificates for nextlevelbot.test and add them in folder in this path
C:\laragon\etc\ssl\nextlevelbot.test
and add path SSL certificates in .env file
LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT =C:\laragon\etc\ssl\nextlevelbot.test\server.crt
LARAVEL_WEBSOCKETS_SSL_LOCAL_PK =C:\laragon\etc\ssl\nextlevelbot.test\server.key
and edit path SSL certificates in config file for my project in this path
C:\laragon\etc\nginx\sites-enabled\auto.nextlevelbot.test.conf
ssl_certificate "C:/laragon/etc/ssl/nextlevelbot.test/server.crt";
ssl_certificate_key "C:/laragon/etc/ssl/nextlevelbot.test/server.key";
and restart nginx server in laragon
and run command composer dumpautoload
after that run command php artisan websockets:serve
after that work good :)
Generate certificates for domain
I generate certificates by this scripts
https://gist.github.com/mindscms/721cf0968ddbbff5bad0c0b359d918e6
https://gist.github.com/mindscms/a7f3e7db0b6c7bfaaab56522ebed9042
1 - Download two files make-cert.bat and cert-template.conf from link above
2 - Create folder cert in C:\laragon\bin\apache\YOUR_VIRSION_APACHE
in my case C:\laragon\bin\apache\httpd-2.4.35-win64-VC15\cert
3 - Put two file make-cert.bat and cert-template.conf in folder cert
4 - Run file make-cert.bat and answer the questions to generate certificates
5 - After finished script creates a folder with the name domain likenextlevelbot.test
C:\laragon\bin\apache\httpd-2.4.35-win64-VC15\cert\nextlevelbot.test
6 - Inside this folder two files server.crt and server.key
That was helpful but not the exact reason
as this is a local cert, it needs permission
The easiest way ( oh its quirky )
Copy the failing wss link
i.e. wss://example.test:3031/app/?protocol=7&client=js&version=4.3.1&flash=false
and replace the wss:// with https://
i.e.
https://example.test:3031/app/?protocol=7&client=js&version=4.3.1&flash=false
Open the link on another tab of same browser and accept the certification on ssl prompt
try the websockets dashboard now, refresh and voila!
By the way, if you make any change to your nginx config for domain in laragon, you should remove the auto. prefix to avoid future auto overwrite by laragon

Laravel - how to serve laravel project with https on local development

I googled a lot about solution to serve with https. Even I tried ngrok, but it doesn't work properly.
Below is the code of ngork.
php artisan serve
cd <path-to-ngrok>
./ngrok http localhost:8000
I am sure Laravel has artisan to serve HTTPS.
One solution is to use Symfony's 'serve' command instead of artisan serve.
https://symfony.com/download
Install the Symfony CLI locally (I used the homebrew install instructions) and then ran symfony serve in my Laravel root dir. This serves the site under https by default.
it's a standard protocol that HTTPS is listening on port 443, you can simply run the command to listen on that port
php artisan serve --port=443
by the way, php artisan serve is for development use only and ssl certificate is for production environment and both of them have no work relation at all as both serve their purpose differently...
although you can customize your web server to install the SSL certificate and and listening on custom port but you are breaking the standard and the public may doubt and not able to accept it...

How to access laravel valet project from local network?

I built a laravel project in my desktop folder and running it using valet on project-name.dev . How can I access it from local network ? My IP address is 192.168.1.5 ,I'm using a mac and I tried below code but It gives me a error in my project. Is there any different solution ?
php artisan serve --host 192.168.1.5 --port 80
Any help will be appreciated!!
You forgot the equals sign in your command. It should work like this:
php artisan serve --port=80 --host=192.168.1.5
To connect any of your local network devices to your mac you can type into their browser's address bar:
192.168.1.5:80
You can follow the step below
Make valet site unsecure 1st using valet unsecure sitename
Run valet share
A publicly accessible URL will be inserted into your clipboard and is ready to paste directly into your browser. That's it.
Please note
valet share does not currently support sharing sites that have been
secured using the valet secure command.
https://laravel.com/docs/5.6/valet#sharing-sites
You can do that by using --host=0.0.0.0. By using 0.0.0.0, you don't need to hardcode your IP address. It will automatically point to your IP address, even if it changed at some point, maybe when you connect to a different network.
So you type
php artisan serve --host=0.0.0.0 --port=80
You can now access your app using your browser or on another computer in the same network.
http://192.168.1.5:80

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