How to make artisan serve work in virtual host? - php

I'm on Windows 8 and I'm using WAMP to run my laravel project. I have configured apache and I created a virtual host, to access my app through http://myapp.dev.
I would like to know if it's possible to use the built-in php server (to run the laravel aplication through artisan serve) to point to my virtualhost instead of http://localhost:8000.
I tried to change the app url in app.php but it didn't work.

Point myapp.dev to 127.0.0.1 in your hosts file, and do php artisan serve --host 0.0.0.0 --port 80.
In Linux/OSX, this requires sudo privilege, I'm not sure what Windows will require. You'd want to stop Apache too, as it uses port 80 and will cause a conflict if both are trying to run on that port.

You need change the hosts file (ubuntu => /etc/hosts, windows => $WINDIR/System32/drivers/etc/hosts).
127.0.0.1 myapp.dev
.env file also needs changing:
APP_URL=tttp://myapp.dev:8000
$ php artisan serve --host=myapp.dev

Related

Cannot access laravel app on port 8000 when SSL is configured

I have apache and php setup on linux server and created a laravel app in /home/username/laravelapp
Then I run php artisan serve --host=0.0.0.0
I am able to access the laravel app through http://<ipaddress>:8000
Then I setup a domain and point to my address and setup SSL from letsencrypt. I restarted apache2 and run the laravel app again and access https://<mydomain>:8000, cannot reach the site. But http://<ipaddress>:8000 is still reachable.
I didn't make any change in the /etc/apache2/sites-available. Do I need to make any changes on the 000-default.conf or 000-default-le-ssl.conf file?

Serve multiple laravel apps on localhost with php artisan serve

I'd like to be able to serve more than one laravel app at the same time on different tabs/ports, this is so I can showcase various designs, sadly when I run php artisan serve I can get only one app running at a time on port 8000.
Even after updating to laravel 5.8, form the docs:
Artisan Serve Improvements
In previous releases of Laravel, Artisan's serve command would serve your application on port 8000. If another serve command process was already listening on this port, an attempt to serve a second application via serve would fail. Beginning in Laravel 5.8, serve will now scan for available ports up to port 8009, allowing you to serve multiple applications at once.
Is there anything I'm missing?
Use php artisan serve --port='YOUR-PORT' command.
or
you can create a variable SERVER_PORT in your .env file
Example:
SERVER_PORT=80
you can add --port #### when you run php artisan serve like this:
php artisan serve --port 8001, this will run your project on port 8001
You can use Laravel Valet for this, you essentially have local domains for each site, I use it daily on MacOS if you're on windows this should help:
https://github.com/cretueusebiu/valet-windows
Run php artisan serve --port port_number this will run your project on your defined port.

Symfony fresh installation is not working on my localhost

I installed a fresh copy of Symfony on my localhost at htdocs\symfony-fresh and the file structure is:
Now I run the following in git bash:
$ php bin/console server:run
then I was suggested to browse at 127.0.0.1:8000 to see the fresh installation of symfony. It works like a charm. But one day later I browse at 127.0.0.1:8000 and I can see the following error message:
This site can’t be reached
127.0.0.1 refused to connect.
It seems server is offline. I checked my apache & Mysql is running.
Then I tried to run the command again:
$ php bin/console server:run
But same problem is going on. I am new in Symfony and enjoying to learn, but this problem stuck me. What should I do to run this app browsing at 127.0.0.1/symfony-fresh or localhost/symfony-fresh?
You should check status follow:
php bin/console server:status
By default, the web server listens on port 8000 on the loopback device. You can change the socket passing an IP address and a port as a command-line argument:
# passing a specific IP and port
php bin/console server:start 192.168.0.1:8080
# or like this
php bin/console server:start *:8080
Apache has nothing to do with this, the built in Symfony server is based on php built in server (php -S ...)
The built in server is intended for development use only, you must run the command every time the server has stopped or the machine has rebooted.
If you want to use Symfony with apache you can setup a virtualhost: https://symfony.com/doc/current/setup/web_server_configuration.html

How to access a Laravel site from another machine on the same network?

I have a Laravel site on my computer which I can access by typing the php artisan serve command. However I cannot access the site from another machine on the same network.
Is there a way to access the site from another machine?
Yes there is! There are two ways to go about it.
Method 1: Passing a Host Parameter to Artisan
First figure out your computer IP address. If you are on Linux or Mac, type ifconfig at the terminal. If you are on Windows, type ipconfig at the command prompt.
Then, go to your Laravel root directory and just type:
php artisan serve --host=XX.XX.XX.XX
If you'd also like to pass the port parameter, just add --port=XX to the artisan serve command.
Method 2: Serving via a Webserver (like Apache)
Setup Laravel inside your Apache webserver directory through composer. Navigate to your laravel directory and set permissions of the storage folder to 777 by typing this command at the terminal: sudo chmod -R 777 storage/
Access your Laravel site by navigating to
http://IPADDR/laravelproject/public
And voila!

How to run laravel 5 on port 80 of localhost?

For previous versions of Laravel, you can simply download laravel with composer in the root folder of your apache server and type in http://localhost/public/ to see the "You've arrived" homepage.
I know I can use php artisan serve to view the Laravel5 default home page, but it is run on localhost:8000 and I heard that php artisan serve command should not be used in production due to the limit of connection and the bad performance. Is there a way I can see the default home page without using the php artisan serve command?
And it is really frustrating that Laravel is not including such simple thing in their installation documentation....
To run the service on another port you need to pass the port parameter with port numberusing this code on the cmd:
php artisan serve --port=80
To run on port 80, you might need administrator permission.
You may have to use sudo command for admin rights.
sudo php artisan serve --port=80

Categories