How can i access a second laravel app from another pc - php

On this link:
how can i access my laravel app from another pc?
It is perfectly described how to access an laravel app from another pc on the same network.
Now, my question is:
How to access another app served on the same pc?
I have a virtual machine serving two apps app.dev and demo.dev
both are accessible inside VM through internet browser
app.dev is accessible on http://localhost and http://app.dev
demo.dev is accessible only on http://demo.dev
Outside VM only app.dev is accessible on IP address 192.168.0.60
i have used this command inside VM
sudo php artisan serve --host 192.168.0.60 --port 80
Should i use again
sudo php artisan serve ????
but how? anybody help?

Laravel's artisan serve command uses the PHP Built-in web server. Because that is not a full featured web server, it has no concept of virtual hosts, so it can only run one instance of the server mapped to an IP and port pair.
Normally to serve two hosts from the same IP address you'd add in your VM's /etc/hosts file the following mappings:
192.168.0.60 app.dev
192.168.0.60 demo.dev
Now you can run app.dev by running:
php artisan serve --host app.dev --port 80
And it will be available on your host machine using http://app.dev. However if you would try to spin up a second server instance for demo.dev using this:
php artisan serve --host demo.dev --port 80
It won't work and will complain that:
Address already in use
You could get around that by using a different port for your demo.dev app by using for example this:
php artisan serve --host demo.dev --port 8080
And now you'd be able to access http://demo.dev:8080 for your second app on your host machine.
That being said, I suggest you install a full featured web server such as Apache or nginx and then setup a virtual host for each application (just make sure to keep the mappings from the /etc/hosts file I showcased above).
Setting up virtual hosts can be really easy for both server solutions. Below are links to two articles from the Laravel Recipes website that showcase how to do that specifically for Laravel:
Creating an Apache VirtualHost
Creating a Nginx VirtualHost

Related

How do I successfully serve a local Laravel app on my phone without the connection refused error?

I'm running a Laravel 9 app on my MacBook using php artisan serve. I would like to see the app on my Android phone, but I'm failing.
Both the computer and the phone are connected to the same WiFi network. I serve the app on my computer and access its public IP:port on my phone, like this:
HTTP://192.168.1.10:8000
However, all I'm getting is an error in Chrome: Err_Connection_Refused. Tried Firefox as well.
What might be wrong or missing here?
The full artisan command for running a Laravel application that you want reached from other devices is
sudo php artisan serve --host 192.168.1.10 --port 8080
This opens up listening to the external port of 8080 for incoming traffic from outside localhost or 127.0.0.1

How to set a domain name with php artisan serve

I am new to PHP and Laravel. While virtualhosting with Wamp, I could specify the documentroot, servername and the port number - hence specifying the domain name. But with the command php artisan serve, I am able to specify the port address but not the domain name.
Is it possible to set the domain name?
also, what is the difference between hosting with this command and with wamp ?
n.b I am new to server side languages, sorry for asking these basics !
EDIT: I've used php artisan serve --host=blog.local --port=8001 but error is showing up
I've cleared the configuration and application cache.
You can explicitly define the host and the port with artisan serve command:
php artisan serve --host=somedomain.com --port=8001
Note: Remember to enable to port with your firewall.
Though it is too late.
Make an entry in the system host file. in case of windows it is at
C:\Windows\System32\Drivers\etc\hosts
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 blog.local
Then run your command:
php artisan serve --host=blog.local --port=8001
It's easy, just pass the --host parameter.
php artisan serve --host=example.com
Try to command like this:
php artisan serve --host=<host IP address> --port=<port to use>
Example:
php artisan serve --host=127.0.0.1 --port=8080
First of all you will need to add your local domain in the host file. The path is C:\Windows\System32\drivers\etc and you will found the host file.
Open with notepad and write this line 127.0.0.1 <your_domain_name> to the last line. For example 127.0.0.1 lala.com
Then the command on your terminal,
php artisan serve --host=<your_domain_name_in_the_host_file>
and system will auto generate a port number for you like
php artisan serve --host=lala.com
Laravel development server started: http://lala.com:8000
Now then, you are able to surf your localhost, which is http://lala.com:8000 with your custom domain name but also with the port number.
If you want a custom port number then just specify the port number at the end of the command,
php artisan serve --host=lala.com --port=8088
and url will be http://lala.com:8088
Try this command.
php artisan serve --host=0.0.0.0 --port=8000
You can try it:
php artisan serve --host 192.168.0.1 --port 80
Change your host and port

Cannot use NGINX subdomain inside the Docker container

This question is kinda stupid, it's about using the Docker's service names as hostnames, so here's the context:
I am running the following NGINX containers: base, php-fpm and nginx. I also have a Laravel project who is located in the root project, in the /api folder. I also run haproxy on port 5000 for load balancing the requests over php-fpm containers.
The base container contains the linux environment from which i can run commands to phpunit, npm and literally have access to other containers' files that are sent using the volume from docker-compose.
The php-fpm contains the environment for PHP to run.
The nginx contains the NGINX server which is configured to hold two websites: the root website (localhost) and the api subdomain (api.localhost). The api. subdomain points to the /api folder within the root project, and the root website (localhost) points to the /frontend folder within the root project.
The problem is that within the base service container, i cannot run curl command to access the api.localhost website. I tried to use curl to access the nginx using the service name within the docker-compose (which is nginx):
$ curl http://nginx
and it works perfectly, but the frontend folder answers with code from the frontend folder. I have no idea how to use the service name to access the api.localhost wihin the container.
I have tried
$ curl http://api.nginx
$ curl http://api.localhost
Not even the localhost answers to the curl command:
$ curl http://localhost
Is there any way i can access the subdomain from a NGINX container using the service name as hostname?
I have found out that subdomains are not working well using NGINX and Docker Service name as hostname.
Instead, i had to change the structure of my project so that i don't use subdomains while trying to access URLs using service names as hostnames.

How to set up access to Symfony2 application via web browser?

I have a Linux virtual box, built using Vagrant. I am working on an application built using Symfony2 and wish to use PHP's built in server to host the application. I have got the PHP server running successfully using the command: php bin/console server:start. This tells me:
[OK] Web server listening on http://127.0.0.1:8000
I've specified the following in the Vagrantfile:
config.vm.network "private_network", ip: "192.168.56.109
I want to access the application via the browser on my host machine which is running on Windows 7.
How can I achieve this?
The default IP for the built-in web server is 127.0.0.1. In order for it to be visible outside your vagrant machine, you need to bind it to 0.0.0.0:
php bin/console server:start 0.0.0.0
Then you access http://192.168.56.109:8000 and it should work correctly.

Access Laravel Project on Network Machine

i am new to laravel and basically i am a nodejs developer, i basically develop application in sailsjs and i access my sailjs application on another machine within same network by using my machine ip on which the project is running.
like i lift main salsjs application on A machine using sails lift --port 1334 and then goto another machine B within same network and access is with my A machine ip , like 192.168.10.2:1334
now i want to do the same thing with laravel, i've lifted my server using laravel command
ahsan#ahsan-Inspiron-N5110:~/Desktop/Development/laravell/laravel$ sudo php artisan serve --port 1334
Laravel development server started on http://localhost:1334
and now the application is running on 1334 port and when i try to access it from machine B within same network it just says unble to connect.
Please let me knowo what do i need to do to access it over network with my machine A ip address.
Thanks.
Note: i am using UBUNTU on Machine A and have access to sailsjs application on Machine B which is windows based but not the laravel application access
php artisan serve --host 0.0.0.0 --port 1334
or
php artisan serve --host 192.168.10.2 --port 1334
in most cases you will need permissions (sudo) to start this. If its not working, check your firewall (iptables)

Categories