在Debian系統中設置Laravel路由,你需要遵循以下步驟:
sudo apt-get install composer
composer global require laravel/installer
laravel new project_name
這將創建一個名為project_name
的新目錄,并在其中設置好Laravel環境。
sudo apt-get update
sudo apt-get install nginx
sudo nano /etc/nginx/sites-available/project_name
project_name
為你的實際項目名稱:server {
listen 80;
server_name example.com; # 替換為你的域名或公網IP
root /path/to/your/project_name/public; # 替換為你的項目public目錄的路徑
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # 根據你的PHP版本進行調整
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
保存并退出編輯器。
創建一個符號鏈接,將配置文件鏈接到sites-enabled
目錄:
sudo ln -s /etc/nginx/sites-available/project_name /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
routes/web.php
文件,添加你需要的路由。例如:Route::get('/', function () {
return 'Hello, World!';
});
Route::get('/about', function () {
return 'About page';
});
php artisan serve
現在,你可以在瀏覽器中訪問你的Debian服務器的IP地址或域名,查看路由是否正常工作。