Not sure what your question is? Do you want to run php artisan on a remote server?
how to run a php artisan command for https host
Hi guys !! I was struggling to run php artisan serve command on certificated protocal . please tell me how to run a php artisan command for https host
I cant run the command php artisan serve in HTTPS Mode, while it is running in http mode, pls guide me . In brief the php artisan serve commnd is executing in NON ssl Mode , it is not getting executed in SSL mode?
Using Commond :
php artisan serve --host=somedomain.com --port=8001
laravel development server is running in http://somedomain.com:8001[HTTP]
but i want to run a laravel development server in https://somedomain.com:8001 [ HTTPS ]
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...
@siangboon It is giving error: Failed to listen on 127.0.0.1:443 (reason: An attempt was made to access a socket in a way forbidden by its access permissions.
@msyadav check any process (probably another web server is running) using that port.... only 1 port number can be used at a time.
@msyadav artisan serve just uses the built in webserver in php, and I dont believe that it supports https/ssl
https://www.php.net/manual/en/features.commandline.webserver.php
So either use a proper webserver (nginx, apache or xampp). Or use a service like ngrok to tunnel the server through https
As has been said. artisan serve is a development tool for a single user. Why would you need to ever run it over https ?
@Snapey because Jeffrey is teaching things that only work over https ;-b
I'm not sure why running ssl in local would seem so strange to some devs... in my opinion it is the best practice. Recently my team were able to fix a bug early on, thanks to the fact that we have our local environments set with SSL and self-signed certificates.
@marco-plastiq because protocol and port number should be transparent to your application
@snapey I have an app that is used as an Iframe on another site. As such, and with Chrome's new 3rd party cookie policy in effect, I had to add the Secure flag to cookies delivered by the app. With the secure flag in place, the app simply cannot run over http. I can get around it by manually removing the Secure flag when I'm working in dev or by adjusting settings in at Chrome://flags. However, these manual fixes are not ideal when working with our automated testing suite and the rest of the team. I can't tell everyone else to temporarily make code changes every time they need to run tests. So mimicking the production environment (with ssl) in local development seems like the best solution to me. Does anyone know of any other workaround I should consider here?
@davidspooner your local .env file can specify different cookie settings to production .env file ?
@snapey Thanks for the reply. I had actually investigated this avenue but was having trouble getting it to work. We have multiple .env files and I was just working in the wrong one. It just took a little more fiddling with it and I did get this to work. Thanks for the tip.
Just a quick question. How did you manage to run https locally ?
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:
-
move your project to
htdocsfolder and visit it withhttps://localhost/projectFolder/public/ -
or just create a special
VirtualHostinhttpd-vhosts.conffor this project (always point to thatpublicfolder, this is from where the project is running) and then visit it withhttps://localhost/in this example (you can of course, run in 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).
I have not used Xampp. Using Laravel how can we configure HTTPS in localhost site.
@jamols09 Sorry for missing this until now. For me, I didn't end up running https locally. I have an env.dev file where I set cookie setting so that they play well with my local http environment. Then in config/session.php I set some default cookie settings for production using the env() helper.
Because "artisan serve" at the moment doesn't support the HTTPS protocol directly, you can use Vite. With Laravel 9 you have Vite. So, in this case, you can start Vite for serving HTTPS and forwarding the requests to your php artisan serve. If you are using Vite (for example, for building your front-end) you can use this approach. The approach is explained here: https://dev.to/robertobutti/laravel-artisan-serve-and-https-cb0
brew install ngrok
php artisan serve
ngrok http 8000
Use the generated HTTPS url upon running last command as your HTTPs testing URL
Please or to participate in this conversation.