在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地址或域名,查看路由是否正常工作。