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


How can I access my Laravel app from another PC?

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

我该怎么办?

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

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

现在,您可以从其他计算机上键入:http://192.168.1.101

不要忘记将IP替换为您自己的本地IP。就是这样。

注意:仅当您要在端口 80 上提供服务时,才需要sudo

使用您的 IP 地址访问 laravel(英语:Laravel

php artisan serve --host 0.0.0.0 

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

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

php artisan serve --host 0.0.0.0 --port 8101

现在您的 laravel 服务器已 http://laravel-server-ip-address:8101

  1. 转到 Apache 文件夹中的httpd.conf并找到以下行:

    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 服务

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

使用此命令,其中 IP 地址为 ip-v4。从您的 wifi 连接属性检查 ip-v4。

php artisan serve --host 192.168.10.15 --port 5000
  1. 查找计算机本地 IP:

ifconfig

  1. 转到项目文件夹并键入以下命令:

sudo php artisan serve --host your_ip --port your_port

例:

sudo php 工匠服务 --host 192.168.1.70 --port 8080

  1. 从其他计算机浏览:

192.168.1.70:8080

您可以使用

laravel 的内置命令php artisan serve来完成。

请按照以下步骤操作:

  1. 在命令行中转到项目的根目录。
  2. 运行php artisan serve

如果仍然无法访问端口 8000 该端口已在使用中,请运行:

php artisan serve --port 8383

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