22

I have been searching around to see if there is a way I can mock SSL for local development using Laravel's artisan to serve HTTPS with no luck.

Is this possible and if so, how?

I understand this is a very general question, but I am not seeing anything on this in searches.

Jazzy
  • 6,029
  • 11
  • 50
  • 74

3 Answers3

29

You can use ngrok for that

php artisan serve
cd <path-to-ngrok>
./ngrok http localhost:8000

https://ngrok.com/

  • 1
    This does not answer the question. It facilitates connections from outside the local network, via ngrok, to the locally running web server, but only on HTTP, not HTTPS. – Matthew Setter May 20 '21 at 10:00
  • @MatthewSetter this does answer the question. when you call `./ngrok http [PORT]` it will create an https proxy to the http version. You can see in the terminal logs something like: https://d16f-2402-800-631d-928e-dc2b-9136-ad8a-bd9f.ngrok.io -> http://localhost:80 go to the link with https and the secure logic should be applied – Phạm Huy Phát Oct 06 '21 at 08:14
  • 1
    Fair point, @PhạmHuyPhát. Happy to admit I was wrong: https://ngrok.com/docs#tls. That said, the second line's not required if ngrok's installed in the user's path. – Matthew Setter Oct 06 '21 at 11:42
14

Laravel uses the in-built PHP5.4 development server php -S (http://php.net/manual/en/features.commandline.webserver.php) for it's artisan serve command (see Illuminate\Foundation\Console\ServeCommand). This only supports plain HTTP, so no, this isn't possible. Your best bet would be to use a Vagrant box set up to work with SSL/TLS.

kieranajp
  • 474
  • 5
  • 11
-1

If you're using xampp, then you can setup HTTPS locally with xampp (this post is also useful for setting up HTTPS) and then you can:

  1. move your project to htdocs folder and visit it with https://localhost/projectFolder/public/

  2. or just create a special VirtualHost in httpd-vhosts.conf for this project (always point to that public folder, this is from where the project is running) and then visit it with https://localhost/ in this example (you can of course, run it on a subdomain if you want to)

    <VirtualHost *:80>
        ServerName localhost
        DocumentRoot "c:\pathToYourProject\projectFolder\public"
        <Directory "c:\pathToYourProject\projectFolder\public">
            Options All
            AllowOverride All
        </Directory>
    </VirtualHost>
    
    # this should ensure https (this is mentioned in the stackoverflow post, that I linked as useful
    <VirtualHost *:443>
        ServerName localhost
        DocumentRoot "c:\pathToYourProject\projectFolder\public"
        SSLEngine on
        SSLCertificateFile "conf\ssl.crt\server.crt"
        SSLCertificateKeyFile "conf\ssl.key\server.key"
        <Directory "c:\pathToYourProject\projectFolder\public">
            Options All
            AllowOverride All
        </Directory>
    </VirtualHost>
    

Theoretically, when you're using this method, you don't even need php artisan serve (tbh I'm not entirely sure if it has any purpose in this case).

SenTisso
  • 579
  • 7
  • 18