在Debian上设置Laravel路由,你需要遵循以下步骤:
composer global require laravel/installer
确保将Composer的全局二进制文件目录添加到系统的$PATH变量中。
laravel new project-name
这将在当前目录下创建一个名为project-name的新Laravel项目。
sudo apt update
sudo apt install nginx
sudo nano /etc/nginx/sites-available/project-name
将以下内容粘贴到配置文件中,确保将root指令指向你的Laravel项目的public目录:
server {
listen 80;
server_name example.com; # 替换为你的域名或公网IP地址
root /path/to/your/project-name/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
如果一切正常,你将看到以下输出:
nginx: configuration file /etc/nginx/nginx.conf test is successful
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地址或域名,查看设置的路由是否正常工作。