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

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...

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

Laravel-Php artisan serve url (127.0.0.1:8000) vs localhost/laravelproject/public

I want to access my laravel project.I run php artisan serve and access the 127.0.0.1:8000 in browser.
But i learned that I can also check my project using the localhost/laravelproject/public url whithout running php artisan serve.
Question: What is the point of using php artisan serve?
No point in two different methods like you mentioned run laravel by "php artisan serve" and by "project url" followed by localhost. But advantage of "php artisan serve" is you can run you laravel project without putting in htdocs/www directory i.e servers root directory. You can put laravel project anywhere where you want and run through the artisan command.
I found some information you may find interesting:
https://www.quora.com/How-can-I-use-php-artisan-serve
But in simple words, php artisan serve is an easy way to create a php server and that is what laravel needs to run.
You could do the same with "php -S 8080 (which would start a php web server (single threaded) in the current directory on port 8080)"
Also if you have already a php server running with apache or nginx it would not be necessary any of the commands.
Hope you find this helpful.
The `Serve command is just a shortcut for the PHP Builtin Webserver, something PHP has out of the box, so the point of using it is to start testing your application as fast as you could, you just need to install PHP, Composer and your application is up (if you don't need anything else, of course). But if you already have Nginx installed, there is no point at all, just use it.
It's not wise to use the Builtin Webserver in production.

SSL Certificate on Laravel Development

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.

How to run multiple Laravel projects at same time?

To run one laravel project we only need to type "php artisan serve". and it will be available on port 8000.
But sometimes we need to run multiple projects at the same time. How can we do this?
tl;dr one cannot have more than one listener per TCP port at the same time. If you need more web server instances: try another port:
php artisan serve --port=8001
then go to http://localhost:8001
References:
Can two applications listen to the same port?
https://laravel.com/docs/8.x
You can also run web server on multiple port in PHP application by the following command.
php -S localhost:8000
php -S localhost:8080
First run your first laravel project blog as follows:
Open your command prompt and go to your drive where your laravel project exist.
And type php artisan serve
C:\xampp\htdocs\blog>php artisan serve
Now type http://localhost:8000 in browser and your blog project will run.
Again open another command prompt and again go to your another laravel project bloganother
C:\xampp\htdocs\bloganother>php artisan serve --port=8080
Now go to your browser and type http://localhost:8080 in your browser your another project will also run.
1- First thing you need to mention port number in .env file.
APP_URL=http://127.0.0.1:8001
2- Run php artisan serve --port=8001
Run first laravel project (with url: http://localhost:8000)
php artisan serve
Run another laravel project (with port specific url: http://localhost:8001)
php artisan serve --port=8001
Run one more laravel project (with port specific url: http://localhost:8002)
php artisan serve --port=8002

Artisan Error: Failed to listen on localhost:8000 (reason: An attempt was made to access a socket in a way forbidden by its access permissions. )

I'm having problem starting my laravel installation. Whenever I type in the terminal php artisan serve, it throws me an error like below:
c:\wamp\www\blog>php artisan serve Laravel development server started
on http://localhost:8000/
[Sat Nov 05 21:18:39 2016] Failed to listen
on localhost:8000 (reason: An attempt was made to access a socket in a
way forbidden by its access permissions.)
1) First firewall restore to default
2) change artisan serve port using this command php artisan serve --port=3232
Trust me its works :)
I faced the same problem today. I just restarted the my machine, after that tried with the same port and it works!
Change artisan serve port using this command
php artisan serve --port=####
instead #### you can enter your own port number.
This will work sure.!
You need command prompt to run as administrator, that solves the problem most of the time.
First make sure your installed Laravel properly in your local machine.
When you execute php artisan serve , you better to run it with administrative priviledges.
In linux, I use
sudo php artisan localhost:8888 -t public
Make sure other requirements such as php version are upto date.
PHP >= 5.5.9
OpenSSL PHP Extension
PDO PHP Extension
Mbstring PHP Extension
Tokenizer PHP Extension
For more information refer this document.

Resources