php 如何从另一台 PC 访问我的 Laravel 应用程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28956911/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 00:10:14  来源:igfitidea点击:

How can I access my Laravel app from another PC?

phplaravel

提问by DNM

I'm trying to access my Laravel app from another PC in the same network using IP address but I can't get it to work by accessing 192.168.1.101:8000 in my browser.

我正在尝试使用 IP 地址从同一网络中的另一台 PC 访问我的 Laravel 应用程序,但我无法通过在浏览器中访问 192.168.1.101:8000 来使其工作。

What should I do?

我该怎么办?

回答by Mustafa Ehsan Alokozay

Why don't you use Laravel's artisan for it? Very simple:

你为什么不使用 Laravel 的工匠呢?很简单:

sudo php artisan serve --host 192.168.1.101 --port 80

Now from other computers, you can type: http://192.168.1.101

现在从其他电脑,你可以输入:http: //192.168.1.101

That's it.

就是这样。

回答by Bhavsar1311

Access laravel using your IP address

使用您的 IP 地址访问 laravel

php artisan serve --host 0.0.0.0 

Now you can access laravel server by http://laravel-server-ip-address:8000

现在你可以通过http://laravel-server-ip-address:8000访问 laravel 服务器

If you want to change the port as well then

如果您也想更改端口,那么

php artisan serve --host 0.0.0.0 --port 8101

Now your laravel server is http://laravel-server-ip-address:8101

现在你的 Laravel 服务器是http://laravel-server-ip-address:8101

回答by Robin Curbelo

  1. Go to httpd.confin Apache folder and find the following lines:

    DocumentRoot "c:/wamp/www"
    <Directory "c:/wamp/www">
        # ...Stuffs in here
        Options Indexes FollowSymLinks
        # ...Stuffs in here
        AllowOverride All
        #
        # Controls who can get stuff from this server.
        #
        Require all granted
    </Directory>
    
  2. Then replace the last line within<Directory>tag for:

         Order Deny,Allow
         Deny from all
         Allow from 127.0.0.1
         Allow from ::1
         Allow from localhost
    </Directory>
    
  3. Add a virtual hostfor your laravel application, go to httpd-vhosts.confand add the following lines:

    <VirtualHost *:80>
        DocumentRoot "D:/.../your-laravel-app-path/public"
        ServerName yourservername.dev
        <Directory "D:/.../your-laravel-app-path/public">
            AllowOverride All
            Order deny,allow
            Allow from all
            Require all granted
        </Directory>
    </VirtualHost>
    
  4. Restart all your apache services

  1. 转到httpd.confApache 文件夹并找到以下几行:

    DocumentRoot "c:/wamp/www"
    <Directory "c:/wamp/www">
        # ...Stuffs in here
        Options Indexes FollowSymLinks
        # ...Stuffs in here
        AllowOverride All
        #
        # Controls who can get stuff from this server.
        #
        Require all granted
    </Directory>
    
  2. 然后替换最后一行<Directory>标记为:

         Order Deny,Allow
         Deny from all
         Allow from 127.0.0.1
         Allow from ::1
         Allow from localhost
    </Directory>
    
  3. 为您的 Laravel 应用程序添加一个虚拟主机,转到httpd-vhosts.conf并添加以下几行:

    <VirtualHost *:80>
        DocumentRoot "D:/.../your-laravel-app-path/public"
        ServerName yourservername.dev
        <Directory "D:/.../your-laravel-app-path/public">
            AllowOverride All
            Order deny,allow
            Allow from all
            Require all granted
        </Directory>
    </VirtualHost>
    
  4. 重新启动所有 apache 服务

This should do it, i'm using wamp on Windows and works for me.

这应该可以,我在 Windows 上使用 wamp 并且对我有用。

回答by Raviraj Chauhan

You can do it by using laravel's built in command php artisan serve.

您可以使用 laravel 的内置命令来完成php artisan serve

Follow the steps:

按照步骤:

  1. Go to your project's root directory within command line.
  2. run php artisan serve
  1. 在命令行中转到项目的根目录。
  2. php artisan serve

If you still can't access port 8000 orit is already in use then run:

如果您仍然无法访问端口 8000它已被使用,则运行:

php artisan serve --port 8383

And it should listen on new port you provided. Also you can set other options for this command. Look for the help php artisan help serve.

它应该侦听您提供的新端口。您也可以为此命令设置其他选项。寻求帮助php artisan help serve