How to set a domain name with php artisan serve - php

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

Related

How to use custom domain on Laravel in Windows Server

Am looking for an approach to dealing with the following issue. Any assistance is greatly appreciated.
I have 3 Laravel applications running on a windows server with the server name "php_apps".
Each laravel application is served to a port. e.g;
php artisan serve --port 8001 --host 0.0.0.0
php artisan serve --port 8002 --host 0.0.0.0
php artisan serve --port 8003 --host 0.0.0.0
And the URLs are http://php_apps:8001, http://php_apps:8002, and http://php_apps:8003
How do I replace the port numbers with names, to read something like; http://php_apps/first_app, http://php_apps/second_app, and http://php_apps/third_app
My aim is to replace the port numbers with something more descriptive and readable.
How best would you suggest I go about it?
Just use Valet for windows :) Enjoy

PHP artisan use domain without port number

When I serve my laravel project with php artisan serve --host=yum-yums.local, I can access the site via http://yum-yums.local:8000
My host file has 127.0.0.1 yum-yums.local
How can I access the site with just yum-yums.local please, with no port number appended?
80 port is the default port number of http so you have to use this command to omit the port number:
sudo php artisan serve --host=localhost --port=80

PHP artisan serve error - failed to listen on 127.0.0

I was writing in terminal to install Laravel on my PC but this is what I’m getting. Is that has to do something with my IP address? I’ve downloaded Xampserver to fix this but still nope.
Try changing artisan serve port using this command:
php artisan serve --port=4546
You can do two things
change a port
Stop applications which runs on port 80(Skype probably )
Changing port
php artisan serve --port=8085
Stop Skype
Skype>Tools>Options>Advanced>Connection.
Untick/Uncheck Use port 80 and 443 as an alternatives for incoming connections
click Save

Run laravel 5 app without php artisan serve

I have created small blog application in laravel 5.2 .the app works whenever i run it using php artisan serve.
But without running artisan serve , when i access it from public folder for e.g. localhost/blog/public/addBlog it gives error page not found.
My routes.php has following lines
Route::get('addBlog','BlogsController');
It works fine with php artisan serve with visiting http://localhost:8000/addBlog
The solution is pretty simple. Laravel expects your public folder to be the root of the webserver / url / domain.
Using the serve command works since localhost:8000 is the root then.
Using the longer url doesn't work since your root is localhost/blog not localhost.
A fairly simple solution is to create a virtualhost, to explain how you can do this we would need to know what is running on your localhost (xampp? wamp?)
Nevertheless, the solution would be a virtualhost pointing to localhost/blog/public
Update
example for wamp virtual hosts
C:\Windows\System32\drivers\etc\hosts => open as admin and add
127.0.0.1 blog.dev
C:\wamp\bin\apache\apache2.4.9\conf\extra\httpd-vhosts.conf
<VirtualHost *:80>
ServerName blog.dev
DocumentRoot "C:\wamp\www\blog\public"
ServerAlias blog.dev
</VirtualHost>
It's basically the same for xampp, but the path to the vhosts conf is different
Don't forget to restart wamp/xampp after doing the changes. Then simply open http://blog.dev via browser and enjoy
Laravel expects the folder to be in the root of the application so set-up a virtual host and update your hosts file to match.
Use following command
sudo a2enmod rewrite
I had tried in to the ubuntu but i am not sure that will run in another os or not

How can i access a second laravel app from another pc

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

Categories