1

I have a laravel project and its user has a virtual domain how do I publish it in the local network only

This is my configuration in httd.vhosts.conf file

<VirtualHost *:80> ServerName smarts.local DocumentRoot "C:/xampp/htdocs/smarts/public" SetEnv APPLICATION_ENV "development" <Directory "C:/xampp/htdocs/smarts/public"> DirectoryIndex index.php AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost> 

This is in my hosts file

127.0.0.1 smarts.local 

Currently it works on my pc only but does not work on other devices in the network.

1
  • Which editor do you use to develop your code? because some IDEs have instant servers to share across the local network without messing with lots of codes. Commented Jan 19, 2019 at 16:51

8 Answers 8

7

you can use the artisan command, first run the cmd on your computer, then go to the folder of your project like this: cd c:\wamp64\your_project_folder,

then type this code: php artisan serve --host=YOUR IP --port=ONE FREE PORT you can find your computer port with the running this command in cmd: ipconfig /all

your command should be like this: php artisan serve --host=192.168.1.106 --port=8080

and the others can run your project from your computer with writing this code in the addressBar of their own browser : 192.168.1.106:8080

Sign up to request clarification or add additional context in comments.

Comments

2

Its so much easy to do.
1.In windows go to cmd and type ipconfig.
2.get you local IPv4 Address (e.g:192.168.1.5).
3.Go to visual studio code and open Terminal
4.Type like this (php artisan serve --host=IPv4 Address)

Hopefully this will help you to share your project inside your same network.

Command Line image

Comments

1

If you prefer using xampp to host your laravel over your network without using

"php artisan serve --host " command then this might what you're looking for.

in the xampp control panel we can see this port: 443, you can use this as a port in your virtual hosts

enter image description here

Add entry to your httpd-vhosts.conf

<VirtualHost *:443> DocumentRoot "C:/xampp/htdocs/yoursite_folder/public" ServerName yoursite.io <Directory "C:/xampp/htdocs/yoursite_folder/public"> AllowOverride All Require all granted </Directory> </VirtualHost> 

edit your computer hosts file usually located in: C:\Windows\System32\drivers\etc add your vhost entry

127.0.0.1 yoursite.io 

for other devices, make sure THEY use your IP address on their hosts file not the 127.0.0.1 ex. IP: 192.168.300.5 they need this to access your project with your ServerName.

192.168.300.5 yoursite.io 

Restart apache server and open your browser, visit: http://yoursite.io:443 you can host as many projects as you want just put a unique ServerName on it so you won't have any conflicts. Just repeat the process if you have multiple virtualHost

Note: In Mobile devices you also need to edit the hosts file to be able to access your projects by domain like yoursite.io:443 or else, they can only access your project using your ip address: http://192.168.300.5:443

Comments

0

If you want others to access smarts.local.

  • make sure your system ip address is static.

  • then every one who wants to access smarts.local should add the following to their hosts file

  • 127.0.0.1 smarts.local (Replace 127.0.0.1 with ur public static ip)

  • or you should use DNS server in your network.

You can also write a startup command which will execute php artisan serve.(But you have to make sure ur public ip is static)

Comments

0

If you're using windows.

  1. Go to network status and click on properties
  2. Copy IPV4 address
  3. Open terminal and go to your project root folder.
  4. php artisan serve --host=youripv4address --port=8000

Comments

0

i tested this and it worked:

php -S YOUR_LOCAL_IP:PORT -t public 

Comments

0

This is For Laravel 10 & above;

if you want to serve you application on any other machine with tailwind ; & you are having problem like not able to get css files; then this is for you :)

step (1) :- add server to vite.config.js

after adding code to Vite.config.js it will look like this

server: { host: "192.168.1.15", // Your local ip address }, plugins: [ laravel({ input: ["resources/css/app.css", "resources/js/app.js"], refresh: true, }), ], 

step (2) :- serve you app

php artisan serve --host YOUR_LOCAL_IP --port 8000 

that's all, now you can access your website in local machine with YOUR_LOCAL_IP:8000.

Comments

-1

To check your IP address on Windows, use the ipconfig command in the Command Prompt and locate your IPv4 address. Then, you can use this address to run the Artisan server with the following command:

php artisan serve --host=YourIPv4Address --port=8000 

This method worked for me to share my local API within the LAN. I hope it works for you as well!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.