ajaydhakal/laravel-host
Composer 安装命令:
composer require ajaydhakal/laravel-host
包简介
Serve Laravel apps on the local network using php artisan host.
README 文档
README
Serve your current Laravel application on your local network/LAN by default, making it easily accessible from other devices (like smartphones, tablets, or other development machines) on the same Wi-Fi.
Installation
You can install the package via Composer:
composer require ajaydhakal/laravel-host
The package will automatically register its service provider using Laravel's package auto-discovery.
Usage
To start serving your application on your local network:
php artisan host
This will run the built-in development server and output details similar to:
Laravel Host is running
Local:
http://127.0.0.1:8000
Network:
http://192.168.1.12:8000
Press Ctrl+C to stop the server.
Make sure your firewall allows incoming connections on port 8000.
The terminal must remain open while serving.
Custom Port
You can specify a custom port with the --port option:
php artisan host --port=8080
Custom Host
You can customize the host bind address with the --host option (defaults to 0.0.0.0):
php artisan host --host=0.0.0.0 --port=8080
Production Warning
By default, the command prevents running in a production environment (APP_ENV=production) to safeguard against accidental exposure. If you explicitly want to run it in production, pass the --force option:
php artisan host --force
Configuration
If you want to customize default settings, you can publish the configuration file:
php artisan vendor:publish --tag=laravel-host-config
This will create a config/host.php file:
return [ 'host' => env('LARAVEL_HOST_ADDRESS', '0.0.0.0'), 'port' => env('LARAVEL_HOST_PORT', 8000), 'allow_production' => env('LARAVEL_HOST_ALLOW_PRODUCTION', false), ];
You can define these settings directly in your .env file:
LARAVEL_HOST_ADDRESS=0.0.0.0 LARAVEL_HOST_PORT=8000 LARAVEL_HOST_ALLOW_PRODUCTION=false
Troubleshooting & Important Notes
- Local Development Only: This package uses PHP's built-in web server. It is meant only for local development and testing. Do not use it in place of production web servers like Nginx, Apache, or PHP-FPM.
- Same Wi-Fi/LAN: To access the application on other devices using the Network URL, all devices must be connected to the exact same Wi-Fi network or Local Area Network (LAN).
- Firewall Restrictions: If other devices are unable to connect to the Network URL, verify your machine's firewall settings. Ensure that incoming connections on the selected port (e.g.,
8000) are allowed. - IP Bind (0.0.0.0 vs 127.0.0.1): To listen on all network interfaces, the host must be set to
0.0.0.0. If set to127.0.0.1, the server will only accept requests from the local machine. - Busy Ports: If the selected port is already in use by another service, the command will automatically detect it and suggest trying another port (e.g.,
8081).
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-19